diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-animation.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-animation.h new file mode 100644 index 0000000000000000000000000000000000000000..cae551eddc5e9868cce3cafdf1530693f080c9b4 --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-animation.h @@ -0,0 +1,221 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* GdkPixbuf library - Animation support + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Havoc Pennington + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_ANIMATION_H +#define GDK_PIXBUF_ANIMATION_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + +G_BEGIN_DECLS + +/* Animation support */ + +typedef struct _GdkPixbufAnimation GdkPixbufAnimation; + + +typedef struct _GdkPixbufAnimationIter GdkPixbufAnimationIter; + +#define GDK_TYPE_PIXBUF_ANIMATION (gdk_pixbuf_animation_get_type ()) +#define GDK_PIXBUF_ANIMATION(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimation)) +#define GDK_IS_PIXBUF_ANIMATION(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION)) + +#define GDK_TYPE_PIXBUF_ANIMATION_ITER (gdk_pixbuf_animation_iter_get_type ()) +#define GDK_PIXBUF_ANIMATION_ITER(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIter)) +#define GDK_IS_PIXBUF_ANIMATION_ITER(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_ANIMATION_ITER)) + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_animation_get_type (void) G_GNUC_CONST; + +#ifdef G_OS_WIN32 +/* API/ABI compat, see gdk-pixbuf-core.h for details */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file_utf8 (const char *filename, + GError **error); +#endif + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufAnimation *gdk_pixbuf_animation_new_from_file (const char *filename, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_28 +GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream (GInputStream *stream, + GCancellable *cancellable, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_28 +void gdk_pixbuf_animation_new_from_stream_async (GInputStream *stream, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GDK_PIXBUF_AVAILABLE_IN_2_28 +GdkPixbufAnimation *gdk_pixbuf_animation_new_from_stream_finish (GAsyncResult*async_result, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_28 +GdkPixbufAnimation *gdk_pixbuf_animation_new_from_resource(const char *resource_path, + GError **error); + +#ifndef GDK_PIXBUF_DISABLE_DEPRECATED + +GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(g_object_ref) +GdkPixbufAnimation *gdk_pixbuf_animation_ref (GdkPixbufAnimation *animation); +GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(g_object_unref) +void gdk_pixbuf_animation_unref (GdkPixbufAnimation *animation); +#endif + +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_animation_get_width (GdkPixbufAnimation *animation); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_animation_get_height (GdkPixbufAnimation *animation); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_animation_is_static_image (GdkPixbufAnimation *animation); +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_animation_get_static_image (GdkPixbufAnimation *animation); + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufAnimationIter *gdk_pixbuf_animation_get_iter (GdkPixbufAnimation *animation, + const GTimeVal *start_time); +G_GNUC_END_IGNORE_DEPRECATIONS + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_animation_iter_get_type (void) G_GNUC_CONST; +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_animation_iter_get_delay_time (GdkPixbufAnimationIter *iter); +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_animation_iter_get_pixbuf (GdkPixbufAnimationIter *iter); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_animation_iter_on_currently_loading_frame (GdkPixbufAnimationIter *iter); +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_animation_iter_advance (GdkPixbufAnimationIter *iter, + const GTimeVal *current_time); +G_GNUC_END_IGNORE_DEPRECATIONS + + +#ifdef GDK_PIXBUF_ENABLE_BACKEND + + + +/** + * GdkPixbufAnimationClass: + * @parent_class: the parent class + * @is_static_image: returns whether the given animation is just a static image. + * @get_static_image: returns a static image representing the given animation. + * @get_size: fills @width and @height with the frame size of the animation. + * @get_iter: returns an iterator for the given animation. + * + * Modules supporting animations must derive a type from + * #GdkPixbufAnimation, providing suitable implementations of the + * virtual functions. + */ +typedef struct _GdkPixbufAnimationClass GdkPixbufAnimationClass; + +#define GDK_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) +#define GDK_IS_PIXBUF_ANIMATION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION)) +#define GDK_PIXBUF_ANIMATION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION, GdkPixbufAnimationClass)) + +/* Private part of the GdkPixbufAnimation structure */ +struct _GdkPixbufAnimation { + GObject parent_instance; + +}; + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +struct _GdkPixbufAnimationClass { + GObjectClass parent_class; + + /*< public >*/ + + gboolean (*is_static_image) (GdkPixbufAnimation *animation); + + GdkPixbuf* (*get_static_image) (GdkPixbufAnimation *animation); + + void (*get_size) (GdkPixbufAnimation *animation, + int *width, + int *height); + + GdkPixbufAnimationIter* (*get_iter) (GdkPixbufAnimation *animation, + const GTimeVal *start_time); +}; +G_GNUC_END_IGNORE_DEPRECATIONS + + + +/** + * GdkPixbufAnimationIterClass: + * @parent_class: the parent class + * @get_delay_time: returns the time in milliseconds that the current frame + * should be shown. + * @get_pixbuf: returns the current frame. + * @on_currently_loading_frame: returns whether the current frame of @iter is + * being loaded. + * @advance: advances the iterator to @current_time, possibly changing the + * current frame. + * + * Modules supporting animations must derive a type from + * #GdkPixbufAnimationIter, providing suitable implementations of the + * virtual functions. + */ +typedef struct _GdkPixbufAnimationIterClass GdkPixbufAnimationIterClass; + +#define GDK_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) +#define GDK_IS_PIXBUF_ANIMATION_ITER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_ANIMATION_ITER)) +#define GDK_PIXBUF_ANIMATION_ITER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_ANIMATION_ITER, GdkPixbufAnimationIterClass)) + +struct _GdkPixbufAnimationIter { + GObject parent_instance; + +}; + +G_GNUC_BEGIN_IGNORE_DEPRECATIONS +struct _GdkPixbufAnimationIterClass { + GObjectClass parent_class; + + /*< public >*/ + + int (*get_delay_time) (GdkPixbufAnimationIter *iter); + + GdkPixbuf* (*get_pixbuf) (GdkPixbufAnimationIter *iter); + + gboolean (*on_currently_loading_frame) (GdkPixbufAnimationIter *iter); + + gboolean (*advance) (GdkPixbufAnimationIter *iter, + const GTimeVal *current_time); +}; +G_GNUC_END_IGNORE_DEPRECATIONS + + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_non_anim_get_type (void) G_GNUC_CONST; +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufAnimation* gdk_pixbuf_non_anim_new (GdkPixbuf *pixbuf); + +#endif /* GDK_PIXBUF_ENABLE_BACKEND */ + +G_END_DECLS + +#endif /* GDK_PIXBUF_ANIMATION_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-autocleanups.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-autocleanups.h new file mode 100644 index 0000000000000000000000000000000000000000..9b6f58b17a7e5e593ae97654c23725af542e1624 --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-autocleanups.h @@ -0,0 +1,37 @@ +/* GdkPixbuf library - Autocleanup definitions + * + * Copyright (C) 2015 Kalev Lember + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_AUTOCLEANUPS_H +#define GDK_PIXBUF_AUTOCLEANUPS_H + +/* We need all the types, so don't try to include this directly */ +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#ifdef G_DEFINE_AUTOPTR_CLEANUP_FUNC + +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkPixbuf, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkPixbufAnimation, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkPixbufAnimationIter, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkPixbufLoader, g_object_unref) +G_DEFINE_AUTOPTR_CLEANUP_FUNC(GdkPixbufSimpleAnim, g_object_unref) + +#endif + +#endif /* GDK_PIXBUF_AUTOCLEANUPS_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h new file mode 100644 index 0000000000000000000000000000000000000000..4b8c9b9b2ab1e234b6d569ba7f3b314b64a07feb --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-core.h @@ -0,0 +1,525 @@ +/* GdkPixbuf library - GdkPixbuf data structure + * + * Copyright (C) 2003 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Havoc Pennington + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_CORE_H +#define GDK_PIXBUF_CORE_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include +#include + +#include + +G_BEGIN_DECLS + +/** + * GdkPixbufAlphaMode: + * @GDK_PIXBUF_ALPHA_BILEVEL: A bilevel clipping mask (black and white) + * will be created and used to draw the image. Pixels below 0.5 opacity + * will be considered fully transparent, and all others will be + * considered fully opaque. + * @GDK_PIXBUF_ALPHA_FULL: For now falls back to #GDK_PIXBUF_ALPHA_BILEVEL. + * In the future it will do full alpha compositing. + * + * Control the alpha channel for drawables. + * + * These values can be passed to gdk_pixbuf_xlib_render_to_drawable_alpha() + * in gdk-pixbuf-xlib to control how the alpha channel of an image should + * be handled. + * + * This function can create a bilevel clipping mask (black and white) and use + * it while painting the image. + * + * In the future, when the X Window System gets an alpha channel extension, + * it will be possible to do full alpha compositing onto arbitrary drawables. + * For now both cases fall back to a bilevel clipping mask. + * + * Deprecated: 2.42: There is no user of GdkPixbufAlphaMode in GdkPixbuf, + * and the Xlib utility functions have been split out to their own + * library, gdk-pixbuf-xlib + */ +typedef enum +{ + GDK_PIXBUF_ALPHA_BILEVEL, + GDK_PIXBUF_ALPHA_FULL +} GdkPixbufAlphaMode; + +/** + * GdkColorspace: + * @GDK_COLORSPACE_RGB: Indicates a red/green/blue additive color space. + * + * This enumeration defines the color spaces that are supported by + * the gdk-pixbuf library. + * + * Currently only RGB is supported. + */ +/* Note that these values are encoded in inline pixbufs + * as ints, so don't reorder them + */ +typedef enum { + GDK_COLORSPACE_RGB +} GdkColorspace; + +/* All of these are opaque structures */ + +typedef struct _GdkPixbuf GdkPixbuf; + +#define GDK_TYPE_PIXBUF (gdk_pixbuf_get_type ()) +#define GDK_PIXBUF(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF, GdkPixbuf)) +#define GDK_IS_PIXBUF(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF)) + + +/** + * GdkPixbufDestroyNotify: + * @pixels: (array) (element-type guint8): The pixel array of the pixbuf + * that is being finalized. + * @data: (closure): User closure data. + * + * A function of this type is responsible for freeing the pixel array + * of a pixbuf. + * + * The gdk_pixbuf_new_from_data() function lets you pass in a pre-allocated + * pixel array so that a pixbuf can be created from it; in this case you + * will need to pass in a function of type `GdkPixbufDestroyNotify` so that + * the pixel data can be freed when the pixbuf is finalized. + */ +typedef void (* GdkPixbufDestroyNotify) (guchar *pixels, gpointer data); + +/** + * GDK_PIXBUF_ERROR: + * + * Error domain used for pixbuf operations. + * + * Indicates that the error code will be in the `GdkPixbufError` enumeration. + * + * See the `GError` for information on error domains and error codes. + */ +#define GDK_PIXBUF_ERROR gdk_pixbuf_error_quark () + +/** + * GdkPixbufError: + * @GDK_PIXBUF_ERROR_CORRUPT_IMAGE: An image file was broken somehow. + * @GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY: Not enough memory. + * @GDK_PIXBUF_ERROR_BAD_OPTION: A bad option was passed to a pixbuf save module. + * @GDK_PIXBUF_ERROR_UNKNOWN_TYPE: Unknown image type. + * @GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION: Don't know how to perform the + * given operation on the type of image at hand. + * @GDK_PIXBUF_ERROR_FAILED: Generic failure code, something went wrong. + * @GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION: Only part of the animation was loaded. + * + * An error code in the `GDK_PIXBUF_ERROR` domain. + * + * Many gdk-pixbuf operations can cause errors in this domain, or in + * the `G_FILE_ERROR` domain. + */ +typedef enum { + /* image data hosed */ + GDK_PIXBUF_ERROR_CORRUPT_IMAGE, + /* no mem to load image */ + GDK_PIXBUF_ERROR_INSUFFICIENT_MEMORY, + /* bad option passed to save routine */ + GDK_PIXBUF_ERROR_BAD_OPTION, + /* unsupported image type (sort of an ENOSYS) */ + GDK_PIXBUF_ERROR_UNKNOWN_TYPE, + /* unsupported operation (load, save) for image type */ + GDK_PIXBUF_ERROR_UNSUPPORTED_OPERATION, + GDK_PIXBUF_ERROR_FAILED, + GDK_PIXBUF_ERROR_INCOMPLETE_ANIMATION +} GdkPixbufError; + +GDK_PIXBUF_AVAILABLE_IN_ALL +GQuark gdk_pixbuf_error_quark (void); + + + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_get_type (void) G_GNUC_CONST; + +/* Reference counting */ + +#ifndef GDK_PIXBUF_DISABLE_DEPRECATED +GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(g_object_ref) +GdkPixbuf *gdk_pixbuf_ref (GdkPixbuf *pixbuf); +GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(g_object_unref) +void gdk_pixbuf_unref (GdkPixbuf *pixbuf); +#endif + +/* GdkPixbuf accessors */ + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkColorspace gdk_pixbuf_get_colorspace (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_get_n_channels (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_get_has_alpha (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_get_bits_per_sample (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +guchar *gdk_pixbuf_get_pixels (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_get_width (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_get_height (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +int gdk_pixbuf_get_rowstride (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_2_26 +gsize gdk_pixbuf_get_byte_length (const GdkPixbuf *pixbuf); + +GDK_PIXBUF_AVAILABLE_IN_2_26 +guchar *gdk_pixbuf_get_pixels_with_length (const GdkPixbuf *pixbuf, + guint *length); + +GDK_PIXBUF_AVAILABLE_IN_2_32 +const guint8* gdk_pixbuf_read_pixels (const GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_2_32 +GBytes * gdk_pixbuf_read_pixel_bytes (const GdkPixbuf *pixbuf); + + + +/* Create a blank pixbuf with an optimal rowstride and a new buffer */ + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new (GdkColorspace colorspace, gboolean has_alpha, int bits_per_sample, + int width, int height); + +GDK_PIXBUF_AVAILABLE_IN_2_36 +gint gdk_pixbuf_calculate_rowstride (GdkColorspace colorspace, + gboolean has_alpha, + int bits_per_sample, + int width, + int height); + +/* Copy a pixbuf */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_copy (const GdkPixbuf *pixbuf); + +/* Create a pixbuf which points to the pixels of another pixbuf */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_subpixbuf (GdkPixbuf *src_pixbuf, + int src_x, + int src_y, + int width, + int height); + +/* Simple loading */ + +#ifdef G_OS_WIN32 +/* In previous versions these _utf8 variants where exported and linked to + * by default. Export them here for ABI (and gi API) compat. + */ + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_from_file_utf8 (const char *filename, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_4 +GdkPixbuf *gdk_pixbuf_new_from_file_at_size_utf8 (const char *filename, + int width, + int height, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_6 +GdkPixbuf *gdk_pixbuf_new_from_file_at_scale_utf8 (const char *filename, + int width, + int height, + gboolean preserve_aspect_ratio, + GError **error); +#endif + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_from_file (const char *filename, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_4 +GdkPixbuf *gdk_pixbuf_new_from_file_at_size (const char *filename, + int width, + int height, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_6 +GdkPixbuf *gdk_pixbuf_new_from_file_at_scale (const char *filename, + int width, + int height, + gboolean preserve_aspect_ratio, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_26 +GdkPixbuf *gdk_pixbuf_new_from_resource (const char *resource_path, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_26 +GdkPixbuf *gdk_pixbuf_new_from_resource_at_scale (const char *resource_path, + int width, + int height, + gboolean preserve_aspect_ratio, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_from_data (const guchar *data, + GdkColorspace colorspace, + gboolean has_alpha, + int bits_per_sample, + int width, int height, + int rowstride, + GdkPixbufDestroyNotify destroy_fn, + gpointer destroy_fn_data); + +GDK_PIXBUF_AVAILABLE_IN_2_32 +GdkPixbuf *gdk_pixbuf_new_from_bytes (GBytes *data, + GdkColorspace colorspace, + gboolean has_alpha, + int bits_per_sample, + int width, int height, + int rowstride); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_from_xpm_data (const char **data); + +#ifndef GDK_PIXBUF_DISABLE_DEPRECATED +GDK_PIXBUF_DEPRECATED_IN_2_32 +GdkPixbuf* gdk_pixbuf_new_from_inline (gint data_length, + const guint8 *data, + gboolean copy_pixels, + GError **error); +#endif + +/* Mutations */ +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_fill (GdkPixbuf *pixbuf, + guint32 pixel); + +/* Saving */ + +#ifndef __GTK_DOC_IGNORE__ +#ifdef G_OS_WIN32 +/* DLL ABI stability hack. */ +#define gdk_pixbuf_save gdk_pixbuf_save_utf8 +#endif +#endif + +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_save (GdkPixbuf *pixbuf, + const char *filename, + const char *type, + GError **error, + ...) G_GNUC_NULL_TERMINATED; + +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_savev (GdkPixbuf *pixbuf, + const char *filename, + const char *type, + char **option_keys, + char **option_values, + GError **error); + +#ifdef G_OS_WIN32 +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_savev_utf8 (GdkPixbuf *pixbuf, + const char *filename, + const char *type, + char **option_keys, + char **option_values, + GError **error); +#endif + +/* Saving to a callback function */ + + +/** + * GdkPixbufSaveFunc: + * @buf: (array length=count) (element-type guint8): bytes to be written. + * @count: number of bytes in @buf. + * @error: (out): A location to return an error. + * @data: (closure): user data passed to gdk_pixbuf_save_to_callback(). + * + * Save functions used by [method@GdkPixbuf.Pixbuf.save_to_callback]. + * + * This function is called once for each block of bytes that is "written" + * by `gdk_pixbuf_save_to_callback()`. + * + * If successful it should return `TRUE`; if an error occurs it should set + * `error` and return `FALSE`, in which case `gdk_pixbuf_save_to_callback()` + * will fail with the same error. + * + * Returns: `TRUE` if successful, `FALSE` otherwise + * + * Since: 2.4 + */ + +typedef gboolean (*GdkPixbufSaveFunc) (const gchar *buf, + gsize count, + GError **error, + gpointer data); + +GDK_PIXBUF_AVAILABLE_IN_2_4 +gboolean gdk_pixbuf_save_to_callback (GdkPixbuf *pixbuf, + GdkPixbufSaveFunc save_func, + gpointer user_data, + const char *type, + GError **error, + ...) G_GNUC_NULL_TERMINATED; + +GDK_PIXBUF_AVAILABLE_IN_2_4 +gboolean gdk_pixbuf_save_to_callbackv (GdkPixbuf *pixbuf, + GdkPixbufSaveFunc save_func, + gpointer user_data, + const char *type, + char **option_keys, + char **option_values, + GError **error); + +/* Saving into a newly allocated char array */ + +GDK_PIXBUF_AVAILABLE_IN_2_4 +gboolean gdk_pixbuf_save_to_buffer (GdkPixbuf *pixbuf, + gchar **buffer, + gsize *buffer_size, + const char *type, + GError **error, + ...) G_GNUC_NULL_TERMINATED; + +GDK_PIXBUF_AVAILABLE_IN_2_4 +gboolean gdk_pixbuf_save_to_bufferv (GdkPixbuf *pixbuf, + gchar **buffer, + gsize *buffer_size, + const char *type, + char **option_keys, + char **option_values, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_2_14 +GdkPixbuf *gdk_pixbuf_new_from_stream (GInputStream *stream, + GCancellable *cancellable, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_new_from_stream_async (GInputStream *stream, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_new_from_stream_finish (GAsyncResult *async_result, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_2_14 +GdkPixbuf *gdk_pixbuf_new_from_stream_at_scale (GInputStream *stream, + gint width, + gint height, + gboolean preserve_aspect_ratio, + GCancellable *cancellable, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_new_from_stream_at_scale_async (GInputStream *stream, + gint width, + gint height, + gboolean preserve_aspect_ratio, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GDK_PIXBUF_AVAILABLE_IN_2_14 +gboolean gdk_pixbuf_save_to_stream (GdkPixbuf *pixbuf, + GOutputStream *stream, + const char *type, + GCancellable *cancellable, + GError **error, + ...); + +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_save_to_stream_async (GdkPixbuf *pixbuf, + GOutputStream *stream, + const gchar *type, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data, + ...); + +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_save_to_stream_finish (GAsyncResult *async_result, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_2_36 +void gdk_pixbuf_save_to_streamv_async (GdkPixbuf *pixbuf, + GOutputStream *stream, + const gchar *type, + gchar **option_keys, + gchar **option_values, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); + +GDK_PIXBUF_AVAILABLE_IN_2_36 +gboolean gdk_pixbuf_save_to_streamv (GdkPixbuf *pixbuf, + GOutputStream *stream, + const char *type, + char **option_keys, + char **option_values, + GCancellable *cancellable, + GError **error); + +/* Adding an alpha channel */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_add_alpha (const GdkPixbuf *pixbuf, gboolean substitute_color, + guchar r, guchar g, guchar b); + +/* Copy an area of a pixbuf onto another one */ +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_copy_area (const GdkPixbuf *src_pixbuf, + int src_x, int src_y, + int width, int height, + GdkPixbuf *dest_pixbuf, + int dest_x, int dest_y); + +/* Brighten/darken and optionally make it pixelated-looking */ +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_saturate_and_pixelate (const GdkPixbuf *src, + GdkPixbuf *dest, + gfloat saturation, + gboolean pixelate); + +/* Transform an image to agree with its embedded orientation option / tag */ +GDK_PIXBUF_AVAILABLE_IN_2_12 +GdkPixbuf *gdk_pixbuf_apply_embedded_orientation (GdkPixbuf *src); + +/* key/value pairs that can be attached by the pixbuf loader */ +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_set_option (GdkPixbuf *pixbuf, + const gchar *key, + const gchar *value); +GDK_PIXBUF_AVAILABLE_IN_ALL +const gchar * gdk_pixbuf_get_option (GdkPixbuf *pixbuf, + const gchar *key); +GDK_PIXBUF_AVAILABLE_IN_2_36 +gboolean gdk_pixbuf_remove_option (GdkPixbuf *pixbuf, + const gchar *key); +GDK_PIXBUF_AVAILABLE_IN_2_32 +GHashTable * gdk_pixbuf_get_options (GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_2_36 +gboolean gdk_pixbuf_copy_options (GdkPixbuf *src_pixbuf, + GdkPixbuf *dest_pixbuf); + + +G_END_DECLS + + +#endif /* GDK_PIXBUF_CORE_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-enum-types.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-enum-types.h new file mode 100644 index 0000000000000000000000000000000000000000..f69266478af05f50ef0e599d91d984c1f31ac5f6 --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-enum-types.h @@ -0,0 +1,40 @@ + +/* This file is generated by glib-mkenums, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */ + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef __GDK_PIXBUF_ENUM_TYPES_H__ +#define __GDK_PIXBUF_ENUM_TYPES_H__ + +#include + +#include + +G_BEGIN_DECLS + +/* enumerations from "gdk-pixbuf-core.h" */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_alpha_mode_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_PIXBUF_ALPHA_MODE (gdk_pixbuf_alpha_mode_get_type ()) +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_colorspace_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_COLORSPACE (gdk_colorspace_get_type ()) +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_error_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_PIXBUF_ERROR (gdk_pixbuf_error_get_type ()) + +/* enumerations from "gdk-pixbuf-transform.h" */ +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_interp_type_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_INTERP_TYPE (gdk_interp_type_get_type ()) +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_rotation_get_type (void) G_GNUC_CONST; +#define GDK_TYPE_PIXBUF_ROTATION (gdk_pixbuf_rotation_get_type ()) +G_END_DECLS + +#endif /* __GDK_PIXBUF_ENUM_TYPES_H__ */ + +/* Generated data ends here */ + diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-features.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-features.h new file mode 100644 index 0000000000000000000000000000000000000000..958040f497633d499aaffd1731ea2a197426847c --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-features.h @@ -0,0 +1,115 @@ +#ifndef __GDK_PIXBUF_FEATURES_H__ +#define __GDK_PIXBUF_FEATURES_H__ + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +/** + * GDK_PIXBUF_MAJOR: + * + * Major version of gdk-pixbuf library, that is the "0" in + * "0.8.2" for example. + */ +/** + * GDK_PIXBUF_MINOR: + * + * Minor version of gdk-pixbuf library, that is the "8" in + * "0.8.2" for example. + */ +/** + * GDK_PIXBUF_MICRO: + * + * Micro version of gdk-pixbuf library, that is the "2" in + * "0.8.2" for example. + */ +/** + * GDK_PIXBUF_VERSION: + * + * Contains the full version of GdkPixbuf as a string. + * + * This is the version being compiled against; contrast with + * `gdk_pixbuf_version`. + */ + +#define GDK_PIXBUF_MAJOR (2) +#define GDK_PIXBUF_MINOR (42) +#define GDK_PIXBUF_MICRO (10) +#define GDK_PIXBUF_VERSION "2.42.10" + +#ifndef _GDK_PIXBUF_EXTERN +#define _GDK_PIXBUF_EXTERN extern +#endif + +/* We prefix variable declarations so they can + * properly get exported/imported from Windows DLLs. + */ +#ifdef G_PLATFORM_WIN32 +# ifdef GDK_PIXBUF_STATIC_COMPILATION +# define GDK_PIXBUF_VAR extern +# else /* !GDK_PIXBUF_STATIC_COMPILATION */ +# ifdef GDK_PIXBUF_C_COMPILATION +# ifdef DLL_EXPORT +# define GDK_PIXBUF_VAR _GDK_PIXBUF_EXTERN +# else /* !DLL_EXPORT */ +# define GDK_PIXBUF_VAR extern +# endif /* !DLL_EXPORT */ +# else /* !GDK_PIXBUF_C_COMPILATION */ +# define GDK_PIXBUF_VAR extern __declspec(dllimport) +# endif /* !GDK_PIXBUF_C_COMPILATION */ +# endif /* !GDK_PIXBUF_STATIC_COMPILATION */ +#else /* !G_PLATFORM_WIN32 */ +# define GDK_PIXBUF_VAR _GDK_PIXBUF_EXTERN +#endif /* !G_PLATFORM_WIN32 */ + +/** + * gdk_pixbuf_major_version: + * + * The major version number of the gdk-pixbuf library. (e.g. in + * gdk-pixbuf version 1.2.5 this is 1.) + * + * + * This variable is in the library, so represents the + * gdk-pixbuf library you have linked against. Contrast with the + * `GDK_PIXBUF_MAJOR` macro, which represents the major version of the + * gdk-pixbuf headers you have included. + */ +/** + * gdk_pixbuf_minor_version: + * + * The minor version number of the gdk-pixbuf library. (e.g. in + * gdk-pixbuf version 1.2.5 this is 2.) + * + * + * This variable is in the library, so represents the + * gdk-pixbuf library you have linked against. Contrast with the + * `GDK_PIXBUF_MINOR` macro, which represents the minor version of the + * gdk-pixbuf headers you have included. + */ +/** + * gdk_pixbuf_micro_version: + * + * The micro version number of the gdk-pixbuf library. (e.g. in + * gdk-pixbuf version 1.2.5 this is 5.) + * + * + * This variable is in the library, so represents the + * gdk-pixbuf library you have linked against. Contrast with the + * `GDK_PIXBUF_MICRO` macro, which represents the micro version of the + * gdk-pixbuf headers you have included. + */ +/** + * gdk_pixbuf_version: + * + * Contains the full version of the gdk-pixbuf library as a string. + * This is the version currently in use by a running program. + */ + +GDK_PIXBUF_VAR const guint gdk_pixbuf_major_version; +GDK_PIXBUF_VAR const guint gdk_pixbuf_minor_version; +GDK_PIXBUF_VAR const guint gdk_pixbuf_micro_version; +GDK_PIXBUF_VAR const char *gdk_pixbuf_version; + +#endif /* __GDK_PIXBUF_FEATURES_H__ */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-io.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-io.h new file mode 100644 index 0000000000000000000000000000000000000000..7565744e5952e3bb9c87efad7da053be1193b06c --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-io.h @@ -0,0 +1,481 @@ +/* GdkPixbuf library - Io handling. This is an internal header for + * GdkPixbuf. You should never use it unless you are doing development for + * GdkPixbuf itself. + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Jonathan Blandford + * Michael Fulbright + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_IO_H +#define GDK_PIXBUF_IO_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +typedef struct _GdkPixbufFormat GdkPixbufFormat; + +GDK_PIXBUF_AVAILABLE_IN_2_40 +gboolean gdk_pixbuf_init_modules (const char *path, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_format_get_type (void) G_GNUC_CONST; + +GDK_PIXBUF_AVAILABLE_IN_ALL +GSList *gdk_pixbuf_get_formats (void); +GDK_PIXBUF_AVAILABLE_IN_2_2 +gchar *gdk_pixbuf_format_get_name (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_2 +gchar *gdk_pixbuf_format_get_description (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_2 +gchar **gdk_pixbuf_format_get_mime_types (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_2 +gchar **gdk_pixbuf_format_get_extensions (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_36 +gboolean gdk_pixbuf_format_is_save_option_supported (GdkPixbufFormat *format, + const gchar *option_key); +GDK_PIXBUF_AVAILABLE_IN_2_2 +gboolean gdk_pixbuf_format_is_writable (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_6 +gboolean gdk_pixbuf_format_is_scalable (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_6 +gboolean gdk_pixbuf_format_is_disabled (GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_2_6 +void gdk_pixbuf_format_set_disabled (GdkPixbufFormat *format, + gboolean disabled); +GDK_PIXBUF_AVAILABLE_IN_2_6 +gchar *gdk_pixbuf_format_get_license (GdkPixbufFormat *format); + +GDK_PIXBUF_AVAILABLE_IN_2_4 +GdkPixbufFormat *gdk_pixbuf_get_file_info (const gchar *filename, + gint *width, + gint *height); +GDK_PIXBUF_AVAILABLE_IN_2_32 +void gdk_pixbuf_get_file_info_async (const gchar *filename, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data); +GDK_PIXBUF_AVAILABLE_IN_2_32 +GdkPixbufFormat *gdk_pixbuf_get_file_info_finish (GAsyncResult *async_result, + gint *width, + gint *height, + GError **error); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufFormat *gdk_pixbuf_format_copy (const GdkPixbufFormat *format); +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_format_free (GdkPixbufFormat *format); + +#ifdef GDK_PIXBUF_ENABLE_BACKEND + + + +/** + * GdkPixbufModuleSizeFunc: + * @width: pointer to a location containing the current image width + * @height: pointer to a location containing the current image height + * @user_data: the loader. + * + * Defines the type of the function that gets called once the size + * of the loaded image is known. + * + * The function is expected to set @width and @height to the desired + * size to which the image should be scaled. If a module has no efficient + * way to achieve the desired scaling during the loading of the image, it may + * either ignore the size request, or only approximate it - gdk-pixbuf will + * then perform the required scaling on the completely loaded image. + * + * If the function sets @width or @height to zero, the module should interpret + * this as a hint that it will be closed soon and shouldn't allocate further + * resources. This convention is used to implement gdk_pixbuf_get_file_info() + * efficiently. + * + * Since: 2.2 + */ +typedef void (* GdkPixbufModuleSizeFunc) (gint *width, + gint *height, + gpointer user_data); + +/** + * GdkPixbufModulePreparedFunc: + * @pixbuf: the #GdkPixbuf that is currently being loaded. + * @anim: if an animation is being loaded, the #GdkPixbufAnimation, else %NULL. + * @user_data: the loader. + * + * Defines the type of the function that gets called once the initial + * setup of @pixbuf is done. + * + * #GdkPixbufLoader uses a function of this type to emit the + * "area_prepared" + * signal. + * + * Since: 2.2 + */ +typedef void (* GdkPixbufModulePreparedFunc) (GdkPixbuf *pixbuf, + GdkPixbufAnimation *anim, + gpointer user_data); + +/** + * GdkPixbufModuleUpdatedFunc: + * @pixbuf: the #GdkPixbuf that is currently being loaded. + * @x: the X origin of the updated area. + * @y: the Y origin of the updated area. + * @width: the width of the updated area. + * @height: the height of the updated area. + * @user_data: the loader. + * + * Defines the type of the function that gets called every time a region + * of @pixbuf is updated. + * + * #GdkPixbufLoader uses a function of this type to emit the + * "area_updated" + * signal. + * + * Since: 2.2 + */ +typedef void (* GdkPixbufModuleUpdatedFunc) (GdkPixbuf *pixbuf, + int x, + int y, + int width, + int height, + gpointer user_data); + +/** + * GdkPixbufModulePattern: + * @prefix: the prefix for this pattern + * @mask: mask containing bytes which modify how the prefix is matched against + * test data + * @relevance: relevance of this pattern + * + * The signature prefix for a module. + * + * The signature of a module is a set of prefixes. Prefixes are encoded as + * pairs of ordinary strings, where the second string, called the mask, if + * not `NULL`, must be of the same length as the first one and may contain + * ' ', '!', 'x', 'z', and 'n' to indicate bytes that must be matched, + * not matched, "don't-care"-bytes, zeros and non-zeros, respectively. + * + * Each prefix has an associated integer that describes the relevance of + * the prefix, with 0 meaning a mismatch and 100 a "perfect match". + * + * Starting with gdk-pixbuf 2.8, the first byte of the mask may be '*', + * indicating an unanchored pattern that matches not only at the beginning, + * but also in the middle. Versions prior to 2.8 will interpret the '*' + * like an 'x'. + * + * The signature of a module is stored as an array of + * `GdkPixbufModulePatterns`. The array is terminated by a pattern + * where the `prefix` is `NULL`. + * + * ```c + * GdkPixbufModulePattern *signature[] = { + * { "abcdx", " !x z", 100 }, + * { "bla", NULL, 90 }, + * { NULL, NULL, 0 } + * }; + * ``` + * + * In the example above, the signature matches e.g. "auud\0" with + * relevance 100, and "blau" with relevance 90. + * + * Since: 2.2 + */ +typedef struct _GdkPixbufModulePattern GdkPixbufModulePattern; +struct _GdkPixbufModulePattern { + char *prefix; + char *mask; + int relevance; +}; + +/** + * GdkPixbufModuleLoadFunc: + * @f: the file stream from which the image should be loaded + * @error: return location for a loading error + * + * Loads a file from a standard C file stream into a new `GdkPixbuf`. + * + * In case of error, this function should return `NULL` and set the `error` argument. + * + * Returns: (transfer full): a newly created `GdkPixbuf` for the contents of the file + */ +typedef GdkPixbuf *(* GdkPixbufModuleLoadFunc) (FILE *f, + GError **error); + +/** + * GdkPixbufModuleLoadXpmDataFunc: + * @data: (array zero-terminated=1): the XPM data + * + * Loads XPM data into a new `GdkPixbuf`. + * + * Returns: (transfer full): a newly created `GdkPixbuf` for the XPM data + */ +typedef GdkPixbuf *(* GdkPixbufModuleLoadXpmDataFunc) (const char **data); + +/** + * GdkPixbufModuleLoadAnimationFunc: + * @f: the file stream from which the image should be loaded + * @error: return location for a loading error + * + * Loads a file from a standard C file stream into a new `GdkPixbufAnimation`. + * + * In case of error, this function should return `NULL` and set the `error` argument. + * + * Returns: (transfer full): a newly created `GdkPixbufAnimation` for the contents of the file + */ +typedef GdkPixbufAnimation *(* GdkPixbufModuleLoadAnimationFunc) (FILE *f, + GError **error); + +/** + * GdkPixbufModuleBeginLoadFunc: + * @size_func: the function to be called when the size is known + * @prepared_func: the function to be called when the data has been prepared + * @updated_func: the function to be called when the data has been updated + * @user_data: the data to be passed to the functions + * @error: return location for a loading error + * + * Sets up the image loading state. + * + * The image loader is responsible for storing the given function pointers + * and user data, and call them when needed. + * + * The image loader should set up an internal state object, and return it + * from this function; the state object will then be updated from the + * [callback@GdkPixbuf.PixbufModuleIncrementLoadFunc] callback, and will be freed + * by [callback@GdkPixbuf.PixbufModuleStopLoadFunc] callback. + * + * Returns: (transfer full): the data to be passed to + * [callback@GdkPixbuf.PixbufModuleIncrementLoadFunc] + * and [callback@GdkPixbuf.PixbufModuleStopLoadFunc], or `NULL` in case of error + */ +typedef gpointer (* GdkPixbufModuleBeginLoadFunc) (GdkPixbufModuleSizeFunc size_func, + GdkPixbufModulePreparedFunc prepared_func, + GdkPixbufModuleUpdatedFunc updated_func, + gpointer user_data, + GError **error); + +/** + * GdkPixbufModuleStopLoadFunc: + * @context: (transfer full): the state object created by [callback@GdkPixbuf.PixbufModuleBeginLoadFunc] + * @error: return location for a loading error + * + * Finalizes the image loading state. + * + * This function is called on success and error states. + * + * Returns: `TRUE` if the loading operation was successful + */ +typedef gboolean (* GdkPixbufModuleStopLoadFunc) (gpointer context, + GError **error); + +/** + * GdkPixbufModuleIncrementLoadFunc: + * @context: (transfer none): the state object created by [callback@GdkPixbuf.PixbufModuleBeginLoadFunc] + * @buf: (array length=size) (element-type guint8): the data to load + * @size: the length of the data to load + * @error: return location for a loading error + * + * Incrementally loads a buffer into the image data. + * + * Returns: `TRUE` if the incremental load was successful + */ +typedef gboolean (* GdkPixbufModuleIncrementLoadFunc) (gpointer context, + const guchar *buf, + guint size, + GError **error); + +/** + * GdkPixbufModuleSaveFunc: + * @f: the file stream into which the image should be saved + * @pixbuf: the image to save + * @param_keys: (nullable) (array zero-terminated=1): parameter keys to save + * @param_values: (nullable) (array zero-terminated=1): parameter values to save + * @error: return location for a saving error + * + * Saves a `GdkPixbuf` into a standard C file stream. + * + * The optional `param_keys` and `param_values` arrays contain the keys and + * values (in the same order) for attributes to be saved alongside the image + * data. + * + * Returns: `TRUE` on success; in case of failure, `FALSE` is returned and + * the `error` is set + */ +typedef gboolean (* GdkPixbufModuleSaveFunc) (FILE *f, + GdkPixbuf *pixbuf, + gchar **param_keys, + gchar **param_values, + GError **error); + +/** + * GdkPixbufModuleSaveCallbackFunc: + * @save_func: the function to call when saving + * @user_data: (closure): the data to pass to @save_func + * @pixbuf: the `GdkPixbuf` to save + * @option_keys: (nullable) (array zero-terminated=1): an array of option names + * @option_values: (nullable) (array zero-terminated=1): an array of option values + * @error: return location for a save error + * + * Saves a `GdkPixbuf` by calling the provided function. + * + * The optional `option_keys` and `option_values` arrays contain the keys and + * values (in the same order) for attributes to be saved alongside the image + * data. + * + * Returns: `TRUE` on success; in case of failure, `FALSE` is returned and + * the `error` is set + */ +typedef gboolean (* GdkPixbufModuleSaveCallbackFunc) (GdkPixbufSaveFunc save_func, + gpointer user_data, + GdkPixbuf *pixbuf, + gchar **option_keys, + gchar **option_values, + GError **error); + +/** + * GdkPixbufModuleSaveOptionSupportedFunc: + * @option_key: the option key to check + * + * Checks whether the given `option_key` is supported when saving. + * + * Returns: `TRUE` if the option is supported + */ +typedef gboolean (* GdkPixbufModuleSaveOptionSupportedFunc) (const gchar *option_key); + +typedef struct _GdkPixbufModule GdkPixbufModule; +struct _GdkPixbufModule { + char *module_name; + char *module_path; + GModule *module; + GdkPixbufFormat *info; + + /* Atomic loading */ + GdkPixbufModuleLoadFunc load; + GdkPixbufModuleLoadXpmDataFunc load_xpm_data; + + /* Incremental loading */ + GdkPixbufModuleBeginLoadFunc begin_load; + GdkPixbufModuleStopLoadFunc stop_load; + GdkPixbufModuleIncrementLoadFunc load_increment; + + /* Animation loading */ + GdkPixbufModuleLoadAnimationFunc load_animation; + + /* Saving */ + GdkPixbufModuleSaveFunc save; + GdkPixbufModuleSaveCallbackFunc save_to_callback; + GdkPixbufModuleSaveOptionSupportedFunc is_save_option_supported; + + /*< private >*/ + void (*_reserved1) (void); + void (*_reserved2) (void); + void (*_reserved3) (void); + void (*_reserved4) (void); +}; + +/** + * GdkPixbufModuleFillVtableFunc: + * @module: a #GdkPixbufModule. + * + * Defines the type of the function used to set the vtable of a + * #GdkPixbufModule when it is loaded. + * + * Since: 2.2 + */ +typedef void (* GdkPixbufModuleFillVtableFunc) (GdkPixbufModule *module); + +/** + * GdkPixbufModuleFillInfoFunc: + * @info: a #GdkPixbufFormat. + * + * Defines the type of the function used to fill a + * #GdkPixbufFormat structure with information about a module. + * + * Since: 2.2 + */ +typedef void (* GdkPixbufModuleFillInfoFunc) (GdkPixbufFormat *info); + +/** + * GdkPixbufFormatFlags: + * @GDK_PIXBUF_FORMAT_WRITABLE: the module can write out images in the format. + * @GDK_PIXBUF_FORMAT_SCALABLE: the image format is scalable + * @GDK_PIXBUF_FORMAT_THREADSAFE: the module is threadsafe. gdk-pixbuf + * ignores modules that are not marked as threadsafe. (Since 2.28). + * + * Flags which allow a module to specify further details about the supported + * operations. + * + * Since: 2.2 + */ +typedef enum /*< skip >*/ +{ + GDK_PIXBUF_FORMAT_WRITABLE = 1 << 0, + GDK_PIXBUF_FORMAT_SCALABLE = 1 << 1, + GDK_PIXBUF_FORMAT_THREADSAFE = 1 << 2 +} GdkPixbufFormatFlags; + +/** + * GdkPixbufFormat: + * @name: the name of the image format + * @signature: the signature of the module + * @domain: the message domain for the `description` + * @description: a description of the image format + * @mime_types: (array zero-terminated=1): the MIME types for the image format + * @extensions: (array zero-terminated=1): typical filename extensions for the + * image format + * @flags: a combination of `GdkPixbufFormatFlags` + * @disabled: a boolean determining whether the loader is disabled` + * @license: a string containing license information, typically set to + * shorthands like "GPL", "LGPL", etc. + * + * A `GdkPixbufFormat` contains information about the image format accepted + * by a module. + * + * Only modules should access the fields directly, applications should + * use the `gdk_pixbuf_format_*` family of functions. + * + * Since: 2.2 + */ +struct _GdkPixbufFormat { + gchar *name; + GdkPixbufModulePattern *signature; + gchar *domain; + gchar *description; + gchar **mime_types; + gchar **extensions; + guint32 flags; + gboolean disabled; + gchar *license; +}; + +#endif /* GDK_PIXBUF_ENABLE_BACKEND */ + +G_END_DECLS + +#endif /* GDK_PIXBUF_IO_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-loader.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-loader.h new file mode 100644 index 0000000000000000000000000000000000000000..1cc34136baf8cbe3fb6cdcad39449f29559c4caf --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-loader.h @@ -0,0 +1,113 @@ +/* GdkPixbuf library - Progressive loader object + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Jonathan Blandford + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_LOADER_H +#define GDK_PIXBUF_LOADER_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include +#include +#include +#include + +G_BEGIN_DECLS + +#define GDK_TYPE_PIXBUF_LOADER (gdk_pixbuf_loader_get_type ()) +#define GDK_PIXBUF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoader)) +#define GDK_PIXBUF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) +#define GDK_IS_PIXBUF_LOADER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GDK_TYPE_PIXBUF_LOADER)) +#define GDK_IS_PIXBUF_LOADER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_LOADER)) +#define GDK_PIXBUF_LOADER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_LOADER, GdkPixbufLoaderClass)) + +typedef struct _GdkPixbufLoader GdkPixbufLoader; +struct _GdkPixbufLoader +{ + /*< private >*/ + GObject parent_instance; + + gpointer priv; +}; + +typedef struct _GdkPixbufLoaderClass GdkPixbufLoaderClass; +struct _GdkPixbufLoaderClass +{ + GObjectClass parent_class; + + void (*size_prepared) (GdkPixbufLoader *loader, + int width, + int height); + + void (*area_prepared) (GdkPixbufLoader *loader); + + /* Last known frame needs a redraw for x, y, width, height */ + void (*area_updated) (GdkPixbufLoader *loader, + int x, + int y, + int width, + int height); + + void (*closed) (GdkPixbufLoader *loader); +}; + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_loader_get_type (void) G_GNUC_CONST; +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufLoader * gdk_pixbuf_loader_new (void); +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufLoader * gdk_pixbuf_loader_new_with_type (const char *image_type, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_4 +GdkPixbufLoader * gdk_pixbuf_loader_new_with_mime_type (const char *mime_type, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_2 +void gdk_pixbuf_loader_set_size (GdkPixbufLoader *loader, + int width, + int height); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_loader_write (GdkPixbufLoader *loader, + const guchar *buf, + gsize count, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_30 +gboolean gdk_pixbuf_loader_write_bytes (GdkPixbufLoader *loader, + GBytes *buffer, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf * gdk_pixbuf_loader_get_pixbuf (GdkPixbufLoader *loader); +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbufAnimation * gdk_pixbuf_loader_get_animation (GdkPixbufLoader *loader); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_loader_close (GdkPixbufLoader *loader, + GError **error); +GDK_PIXBUF_AVAILABLE_IN_2_2 +GdkPixbufFormat *gdk_pixbuf_loader_get_format (GdkPixbufLoader *loader); + +G_END_DECLS + +#endif + + diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-macros.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-macros.h new file mode 100644 index 0000000000000000000000000000000000000000..6461c5420707953655cc85153e395e400cfc18be --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-macros.h @@ -0,0 +1,718 @@ +/* GdkPixbuf library - GdkPixbuf Macros + * + * Copyright (C) 2016 Chun-wei Fan + * + * Authors: Chun-wei Fan + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#ifndef GDK_PIXBUF_MACROS_H +#define GDK_PIXBUF_MACROS_H + +#include + +#include + +/** + * GDK_PIXBUF_CHECK_VERSION: + * @major: major version (e.g. 2 for version 2.34.0) + * @minor: minor version (e.g. 34 for version 2.34.0) + * @micro: micro version (e.g. 0 for version 2.34.0) + * + * Macro to test the version of GdkPixbuf being compiled against. + * + * Returns: %TRUE if the version of the GdkPixbuf header files + * is the same as or newer than the passed-in version. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_CHECK_VERSION(major, minor, micro) \ + (GDK_PIXBUF_MAJOR > (major) || \ + (GDK_PIXBUF_MAJOR == (major) && GDK_PIXBUF_MINOR > (minor)) || \ + (GDK_PIXBUF_MAJOR == (major) && GDK_PIXBUF_MINOR == (minor) && \ + GDK_PIXBUF_MICRO >= (micro))) + +/** + * GDK_PIXBUF_VERSION_2_0: + * + * A macro that evaluates to the 2.0 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_0 (G_ENCODE_VERSION (2, 0)) + +/** + * GDK_PIXBUF_VERSION_2_2: + * + * A macro that evaluates to the 2.2 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_2 (G_ENCODE_VERSION (2, 2)) + +/** + * GDK_PIXBUF_VERSION_2_4: + * + * A macro that evaluates to the 2.4 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_4 (G_ENCODE_VERSION (2, 4)) + +/** + * GDK_PIXBUF_VERSION_2_6: + * + * A macro that evaluates to the 2.6 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_6 (G_ENCODE_VERSION (2, 6)) + +/** + * GDK_PIXBUF_VERSION_2_8: + * + * A macro that evaluates to the 2.8 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_8 (G_ENCODE_VERSION (2, 8)) + +/** + * GDK_PIXBUF_VERSION_2_10: + * + * A macro that evaluates to the 2.10 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_10 (G_ENCODE_VERSION (2, 10)) + +/** + * GDK_PIXBUF_VERSION_2_12: + * + * A macro that evaluates to the 2.12 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_12 (G_ENCODE_VERSION (2, 12)) + +/** + * GDK_PIXBUF_VERSION_2_14: + * + * A macro that evaluates to the 2.14 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_14 (G_ENCODE_VERSION (2, 14)) + +/** + * GDK_PIXBUF_VERSION_2_16: + * + * A macro that evaluates to the 2.16 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_16 (G_ENCODE_VERSION (2, 16)) + +/** + * GDK_PIXBUF_VERSION_2_18: + * + * A macro that evaluates to the 2.18 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_18 (G_ENCODE_VERSION (2, 18)) + +/** + * GDK_PIXBUF_VERSION_2_20: + * + * A macro that evaluates to the 2.20 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_20 (G_ENCODE_VERSION (2, 20)) + +/** + * GDK_PIXBUF_VERSION_2_22: + * + * A macro that evaluates to the 2.22 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_22 (G_ENCODE_VERSION (2, 22)) + +/** + * GDK_PIXBUF_VERSION_2_24: + * + * A macro that evaluates to the 2.24 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_24 (G_ENCODE_VERSION (2, 24)) + +/** + * GDK_PIXBUF_VERSION_2_26: + * + * A macro that evaluates to the 2.26 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_26 (G_ENCODE_VERSION (2, 26)) + +/** + * GDK_PIXBUF_VERSION_2_28: + * + * A macro that evaluates to the 2.28 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_28 (G_ENCODE_VERSION (2, 28)) + +/** + * GDK_PIXBUF_VERSION_2_30: + * + * A macro that evaluates to the 2.30 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_30 (G_ENCODE_VERSION (2, 30)) + +/** + * GDK_PIXBUF_VERSION_2_32: + * + * A macro that evaluates to the 2.32 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_32 (G_ENCODE_VERSION (2, 32)) + +/** + * GDK_PIXBUF_VERSION_2_34: + * + * A macro that evaluates to the 2.34 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_34 (G_ENCODE_VERSION (2, 34)) + +/** + * GDK_PIXBUF_VERSION_2_36: + * + * A macro that evaluates to the 2.36 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.36 + */ +#define GDK_PIXBUF_VERSION_2_36 (G_ENCODE_VERSION (2, 36)) + +/** + * GDK_PIXBUF_VERSION_2_38: + * + * A macro that evaluates to the 2.38 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.38 + */ +#define GDK_PIXBUF_VERSION_2_38 (G_ENCODE_VERSION (2, 38)) + +/** + * GDK_PIXBUF_VERSION_2_40: + * + * A macro that evaluates to the 2.40 version of GdkPixbuf, + * in a format that can be used by the C pre-processor. + * + * Since: 2.40 + */ +#define GDK_PIXBUF_VERSION_2_40 (G_ENCODE_VERSION (2, 40)) + +#ifndef __GTK_DOC_IGNORE__ +#if (GDK_PIXBUF_MINOR % 2) +#define GDK_PIXBUF_VERSION_CUR_STABLE (G_ENCODE_VERSION (GDK_PIXBUF_MAJOR, GDK_PIXBUF_MINOR + 1)) +#else +#define GDK_PIXBUF_VERSION_CUR_STABLE (G_ENCODE_VERSION (GDK_PIXBUF_MAJOR, GDK_PIXBUF_MINOR)) +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if (GDK_PIXBUF_MINOR % 2) +#define GDK_PIXBUF_VERSION_PREV_STABLE (G_ENCODE_VERSION (GDK_PIXBUF_MAJOR, GDK_PIXBUF_MINOR - 1)) +#else +#define GDK_PIXBUF_VERSION_PREV_STABLE (G_ENCODE_VERSION (GDK_PIXBUF_MAJOR, GDK_PIXBUF_MINOR - 2)) +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +/** + * GDK_PIXBUF_VERSION_MIN_REQUIRED: + * + * A macro that should be defined by the user prior to including + * the gdk-pixbuf.h header. + * The definition should be one of the predefined version + * macros: %GDK_PIXBUF_VERSION_2_0, %GDK_PIXBUF_VERSION_2_2, ... + * + * This macro defines the lower bound for the GdkPixbuf API to use. + * + * If a function has been deprecated in a newer version of GdkPixbuf, + * defining this symbol hides the compiler warnings for those functions + * without disabling warnings for the other deprecated functions. + * + * + * Warning: if you define this macro, do not forget to update it! Especially + * when writing new code. Otherwise you can miss the new deprecations. + * + * + * Since: 2.36 + */ +#ifndef GDK_PIXBUF_VERSION_MIN_REQUIRED +#define GDK_PIXBUF_VERSION_MIN_REQUIRED (GDK_PIXBUF_VERSION_CUR_STABLE) +#endif + +/** + * GDK_PIXBUF_VERSION_MAX_ALLOWED: + * + * A macro that should be defined by the user prior to including + * the gdk-pixbuf.h header. + * The definition should be one of the predefined version + * macros: %GDK_PIXBUF_VERSION_2_0, %GDK_PIXBUF_VERSION_2_2, ... + * + * This macro defines the upper bound for the GdkPixbuf API to use. + * + * If a function has been introduced in a newer version of GdkPixbuf, + * it is possible to use this symbol to get compiler warnings when + * trying to use that function. + * + * Since: 2.36 + */ +#ifndef GDK_PIXBUF_VERSION_MAX_ALLOWED +#if GDK_PIXBUF_VERSION_MIN_REQUIRED > GDK_PIXBUF_VERSION_PREV_STABLE +#define GDK_PIXBUF_VERSION_MAX_ALLOWED GDK_PIXBUF_VERSION_MIN_REQUIRED +#else +#define GDK_PIXBUF_VERSION_MAX_ALLOWED GDK_PIXBUF_VERSION_CUR_STABLE +#endif +#endif + +/* sanity checks */ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_MIN_REQUIRED +#error "GDK_PIXBUF_VERSION_MAX_ALLOWED must be >= GDK_PIXBUF_VERSION_MIN_REQUIRED" +#endif +#if GDK_PIXBUF_VERSION_MIN_REQUIRED < GDK_PIXBUF_VERSION_2_0 +#error "GDK_PIXBUF_VERSION_MIN_REQUIRED must be >= GDK_PIXBUF_VERSION_2_0" +#endif + +#ifndef __GTK_DOC_IGNORE__ +#define GDK_PIXBUF_AVAILABLE_IN_ALL _GDK_PIXBUF_EXTERN +#endif + +/* Every new stable minor release should add a set of macros here */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_0 +#define GDK_PIXBUF_DEPRECATED_IN_2_0 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_0 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_0_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_0 +#define GDK_PIXBUF_AVAILABLE_IN_2_0 G_UNAVAILABLE(2, 0) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_0 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_2 +#define GDK_PIXBUF_DEPRECATED_IN_2_2 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_2_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_2 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_2_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_2 +#define GDK_PIXBUF_AVAILABLE_IN_2_2 G_UNAVAILABLE(2, 2) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_2 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_4 +#define GDK_PIXBUF_DEPRECATED_IN_2_4 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_4_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_4 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_4_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_4 +#define GDK_PIXBUF_AVAILABLE_IN_2_4 G_UNAVAILABLE(2, 4) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_4 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_6 +#define GDK_PIXBUF_DEPRECATED_IN_2_6 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_6_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_6 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_6_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_6 +#define GDK_PIXBUF_AVAILABLE_IN_2_6 G_UNAVAILABLE(2, 6) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_6 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_8 +#define GDK_PIXBUF_DEPRECATED_IN_2_8 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_8_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_8 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_8_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_8 +#define GDK_PIXBUF_AVAILABLE_IN_2_8 G_UNAVAILABLE(2, 8) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_8 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_10 +#define GDK_PIXBUF_DEPRECATED_IN_2_10 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_10_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_10 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_10_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_10 +#define GDK_PIXBUF_AVAILABLE_IN_2_10 G_UNAVAILABLE(2, 10) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_10 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_12 +#define GDK_PIXBUF_DEPRECATED_IN_2_12 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_12_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_12 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_12_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_12 +#define GDK_PIXBUF_AVAILABLE_IN_2_12 G_UNAVAILABLE(2, 12) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_12 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_14 +#define GDK_PIXBUF_DEPRECATED_IN_2_14 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_14_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_14 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_14_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_14 +#define GDK_PIXBUF_AVAILABLE_IN_2_14 G_UNAVAILABLE(2, 14) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_14 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_16 +#define GDK_PIXBUF_DEPRECATED_IN_2_16 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_16_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_16 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_16_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_16 +#define GDK_PIXBUF_AVAILABLE_IN_2_16 G_UNAVAILABLE(2, 16) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_16 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_18 +#define GDK_PIXBUF_DEPRECATED_IN_2_18 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_18_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_18 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_18_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_18 +#define GDK_PIXBUF_AVAILABLE_IN_2_18 G_UNAVAILABLE(2, 18) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_18 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_20 +#define GDK_PIXBUF_DEPRECATED_IN_2_20 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_20_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_20 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_20_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_20 +#define GDK_PIXBUF_AVAILABLE_IN_2_20 G_UNAVAILABLE(2, 20) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_20 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_22 +#define GDK_PIXBUF_DEPRECATED_IN_2_22 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_22_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_22 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_22_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_22 +#define GDK_PIXBUF_AVAILABLE_IN_2_22 G_UNAVAILABLE(2, 22) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_22 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_24 +#define GDK_PIXBUF_DEPRECATED_IN_2_24 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_24_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_24 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_24_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_24 +#define GDK_PIXBUF_AVAILABLE_IN_2_24 G_UNAVAILABLE(2, 24) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_24 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_26 +#define GDK_PIXBUF_DEPRECATED_IN_2_26 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_26_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_26 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_26_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_26 +#define GDK_PIXBUF_AVAILABLE_IN_2_26 G_UNAVAILABLE(2, 26) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_26 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_28 +#define GDK_PIXBUF_DEPRECATED_IN_2_28 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_28_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_28 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_28_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_28 +#define GDK_PIXBUF_AVAILABLE_IN_2_28 G_UNAVAILABLE(2, 28) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_28 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_30 +#define GDK_PIXBUF_DEPRECATED_IN_2_30 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_30_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_30 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_30_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_30 +#define GDK_PIXBUF_AVAILABLE_IN_2_30 G_UNAVAILABLE(2, 30) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_30 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_32 +#define GDK_PIXBUF_DEPRECATED_IN_2_32 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_32_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_32 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_32_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_32 +#define GDK_PIXBUF_AVAILABLE_IN_2_32 G_UNAVAILABLE(2, 32) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_32 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_34 +#define GDK_PIXBUF_DEPRECATED_IN_2_34 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_34_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_34 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_34_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_34 +#define GDK_PIXBUF_AVAILABLE_IN_2_34 G_UNAVAILABLE(2, 34) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_34 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_36 +#define GDK_PIXBUF_DEPRECATED_IN_2_36 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_36_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_36 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_36_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_36 +#define GDK_PIXBUF_AVAILABLE_IN_2_36 G_UNAVAILABLE(2, 36) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_36 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_38 +#define GDK_PIXBUF_DEPRECATED_IN_2_38 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_38_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_38 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_38_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_38 +#define GDK_PIXBUF_AVAILABLE_IN_2_38 G_UNAVAILABLE(2, 38) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_38 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MIN_REQUIRED >= GDK_PIXBUF_VERSION_2_40 +#define GDK_PIXBUF_DEPRECATED_IN_2_40 G_DEPRECATED _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_40_FOR(f) G_DEPRECATED_FOR(f) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_DEPRECATED_IN_2_40 _GDK_PIXBUF_EXTERN +#define GDK_PIXBUF_DEPRECATED_IN_2_40_FOR(f) _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#ifndef __GTK_DOC_IGNORE__ +#if GDK_PIXBUF_VERSION_MAX_ALLOWED < GDK_PIXBUF_VERSION_2_40 +#define GDK_PIXBUF_AVAILABLE_IN_2_40 G_UNAVAILABLE(2, 40) _GDK_PIXBUF_EXTERN +#else +#define GDK_PIXBUF_AVAILABLE_IN_2_40 _GDK_PIXBUF_EXTERN +#endif +#endif /* __GTK_DOC_IGNORE__ */ + +#endif /* GDK_PIXBUF_MACROS_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-marshal.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-marshal.h new file mode 100644 index 0000000000000000000000000000000000000000..8cd84acec9d807aa0296be8013aab921220996fb --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-marshal.h @@ -0,0 +1,33 @@ +/* This file is generated by glib-genmarshal, do not modify it. This code is licensed under the same license as the containing project. Note that it links to GLib, so must comply with the LGPL linking clauses. */ +#pragma once + +#include + +G_BEGIN_DECLS + +/* VOID:VOID (../gdk-pixbuf/gdk-pixbuf-marshal.list:25) */ +#define _gdk_pixbuf_marshal_VOID__VOID g_cclosure_marshal_VOID__VOID + +/* VOID:INT,INT (../gdk-pixbuf/gdk-pixbuf-marshal.list:26) */ +extern +void _gdk_pixbuf_marshal_VOID__INT_INT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* VOID:INT,INT,INT,INT (../gdk-pixbuf/gdk-pixbuf-marshal.list:27) */ +extern +void _gdk_pixbuf_marshal_VOID__INT_INT_INT_INT (GClosure *closure, + GValue *return_value, + guint n_param_values, + const GValue *param_values, + gpointer invocation_hint, + gpointer marshal_data); + +/* VOID:POINTER (../gdk-pixbuf/gdk-pixbuf-marshal.list:28) */ +#define _gdk_pixbuf_marshal_VOID__POINTER g_cclosure_marshal_VOID__POINTER + + +G_END_DECLS diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-simple-anim.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-simple-anim.h new file mode 100644 index 0000000000000000000000000000000000000000..487120e0be7b9bf9a5603e227513212f1ce87424 --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-simple-anim.h @@ -0,0 +1,70 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* GdkPixbuf library - Simple frame-based animations + * + * Copyright (C) 2004 Dom Lachowicz + * + * Authors: Dom Lachowicz + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_SIMPLE_ANIM_H +#define GDK_PIXBUF_SIMPLE_ANIM_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include + +G_BEGIN_DECLS + +/** + * GdkPixbufSimpleAnim: + * + * An opaque struct representing a simple animation. + */ +typedef struct _GdkPixbufSimpleAnim GdkPixbufSimpleAnim; +typedef struct _GdkPixbufSimpleAnimClass GdkPixbufSimpleAnimClass; + +#define GDK_TYPE_PIXBUF_SIMPLE_ANIM (gdk_pixbuf_simple_anim_get_type ()) +#define GDK_PIXBUF_SIMPLE_ANIM(object) (G_TYPE_CHECK_INSTANCE_CAST ((object), GDK_TYPE_PIXBUF_SIMPLE_ANIM, GdkPixbufSimpleAnim)) +#define GDK_IS_PIXBUF_SIMPLE_ANIM(object) (G_TYPE_CHECK_INSTANCE_TYPE ((object), GDK_TYPE_PIXBUF_SIMPLE_ANIM)) + +#define GDK_PIXBUF_SIMPLE_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_PIXBUF_SIMPLE_ANIM, GdkPixbufSimpleAnimClass)) +#define GDK_IS_PIXBUF_SIMPLE_ANIM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_PIXBUF_SIMPLE_ANIM)) +#define GDK_PIXBUF_SIMPLE_ANIM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_PIXBUF_SIMPLE_ANIM, GdkPixbufSimpleAnimClass)) + +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_simple_anim_get_type (void) G_GNUC_CONST; +GDK_PIXBUF_AVAILABLE_IN_ALL +GType gdk_pixbuf_simple_anim_iter_get_type (void) G_GNUC_CONST; + +GDK_PIXBUF_AVAILABLE_IN_2_8 +GdkPixbufSimpleAnim *gdk_pixbuf_simple_anim_new (gint width, + gint height, + gfloat rate); +GDK_PIXBUF_AVAILABLE_IN_2_8 +void gdk_pixbuf_simple_anim_add_frame (GdkPixbufSimpleAnim *animation, + GdkPixbuf *pixbuf); +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_simple_anim_set_loop (GdkPixbufSimpleAnim *animation, + gboolean loop); +GDK_PIXBUF_AVAILABLE_IN_ALL +gboolean gdk_pixbuf_simple_anim_get_loop (GdkPixbufSimpleAnim *animation); + +G_END_DECLS + + +#endif /* GDK_PIXBUF_SIMPLE_ANIM_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-transform.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-transform.h new file mode 100644 index 0000000000000000000000000000000000000000..2ba28c49fad058392f1aac9d72c21b7e7648c78e --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf-transform.h @@ -0,0 +1,168 @@ +/* GdkPixbuf library - transformations + * + * Copyright (C) 2003 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Havoc Pennington + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_TRANSFORM_H +#define GDK_PIXBUF_TRANSFORM_H + +#if defined(GDK_PIXBUF_DISABLE_SINGLE_INCLUDES) && !defined (GDK_PIXBUF_H_INSIDE) && !defined (GDK_PIXBUF_COMPILATION) +#error "Only can be included directly." +#endif + +#include +#include + + +G_BEGIN_DECLS + +/* Scaling */ + +/** + * GdkInterpType: + * @GDK_INTERP_NEAREST: Nearest neighbor sampling; this is the fastest + * and lowest quality mode. Quality is normally unacceptable when scaling + * down, but may be OK when scaling up. + * @GDK_INTERP_TILES: This is an accurate simulation of the PostScript + * image operator without any interpolation enabled. Each pixel is + * rendered as a tiny parallelogram of solid color, the edges of which + * are implemented with antialiasing. It resembles nearest neighbor for + * enlargement, and bilinear for reduction. + * @GDK_INTERP_BILINEAR: Best quality/speed balance; use this mode by + * default. Bilinear interpolation. For enlargement, it is + * equivalent to point-sampling the ideal bilinear-interpolated image. + * For reduction, it is equivalent to laying down small tiles and + * integrating over the coverage area. + * @GDK_INTERP_HYPER: This is the slowest and highest quality + * reconstruction function. It is derived from the hyperbolic filters in + * Wolberg's "Digital Image Warping", and is formally defined as the + * hyperbolic-filter sampling the ideal hyperbolic-filter interpolated + * image (the filter is designed to be idempotent for 1:1 pixel mapping). + * **Deprecated**: this interpolation filter is deprecated, as in reality + * it has a lower quality than the @GDK_INTERP_BILINEAR filter + * (Since: 2.38) + * + * Interpolation modes for scaling functions. + * + * The `GDK_INTERP_NEAREST` mode is the fastest scaling method, but has + * horrible quality when scaling down; `GDK_INTERP_BILINEAR` is the best + * choice if you aren't sure what to choose, it has a good speed/quality + * balance. + * + * **Note**: Cubic filtering is missing from the list; hyperbolic + * interpolation is just as fast and results in higher quality. + */ +typedef enum { + GDK_INTERP_NEAREST, + GDK_INTERP_TILES, + GDK_INTERP_BILINEAR, + GDK_INTERP_HYPER +} GdkInterpType; + +/** + * GdkPixbufRotation: + * @GDK_PIXBUF_ROTATE_NONE: No rotation. + * @GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE: Rotate by 90 degrees. + * @GDK_PIXBUF_ROTATE_UPSIDEDOWN: Rotate by 180 degrees. + * @GDK_PIXBUF_ROTATE_CLOCKWISE: Rotate by 270 degrees. + * + * The possible rotations which can be passed to gdk_pixbuf_rotate_simple(). + * + * To make them easier to use, their numerical values are the actual degrees. + */ +typedef enum { + GDK_PIXBUF_ROTATE_NONE = 0, + GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE = 90, + GDK_PIXBUF_ROTATE_UPSIDEDOWN = 180, + GDK_PIXBUF_ROTATE_CLOCKWISE = 270 +} GdkPixbufRotation; + +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_scale (const GdkPixbuf *src, + GdkPixbuf *dest, + int dest_x, + int dest_y, + int dest_width, + int dest_height, + double offset_x, + double offset_y, + double scale_x, + double scale_y, + GdkInterpType interp_type); +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_composite (const GdkPixbuf *src, + GdkPixbuf *dest, + int dest_x, + int dest_y, + int dest_width, + int dest_height, + double offset_x, + double offset_y, + double scale_x, + double scale_y, + GdkInterpType interp_type, + int overall_alpha); +GDK_PIXBUF_AVAILABLE_IN_ALL +void gdk_pixbuf_composite_color (const GdkPixbuf *src, + GdkPixbuf *dest, + int dest_x, + int dest_y, + int dest_width, + int dest_height, + double offset_x, + double offset_y, + double scale_x, + double scale_y, + GdkInterpType interp_type, + int overall_alpha, + int check_x, + int check_y, + int check_size, + guint32 color1, + guint32 color2); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_scale_simple (const GdkPixbuf *src, + int dest_width, + int dest_height, + GdkInterpType interp_type); + +GDK_PIXBUF_AVAILABLE_IN_ALL +GdkPixbuf *gdk_pixbuf_composite_color_simple (const GdkPixbuf *src, + int dest_width, + int dest_height, + GdkInterpType interp_type, + int overall_alpha, + int check_size, + guint32 color1, + guint32 color2); + +GDK_PIXBUF_AVAILABLE_IN_2_6 +GdkPixbuf *gdk_pixbuf_rotate_simple (const GdkPixbuf *src, + GdkPixbufRotation angle); +GDK_PIXBUF_AVAILABLE_IN_2_6 +GdkPixbuf *gdk_pixbuf_flip (const GdkPixbuf *src, + gboolean horizontal); + +G_END_DECLS + + +#endif /* GDK_PIXBUF_TRANSFORM_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h new file mode 100644 index 0000000000000000000000000000000000000000..0770b2fd9f772eb21ec5e68eaa78c834ae1f8f03 --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixbuf.h @@ -0,0 +1,46 @@ +/* GdkPixbuf library - Main header file + * + * Copyright (C) 1999 The Free Software Foundation + * + * Authors: Mark Crichton + * Miguel de Icaza + * Federico Mena-Quintero + * Havoc Pennington + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ + +#ifndef GDK_PIXBUF_H +#define GDK_PIXBUF_H + +#define GDK_PIXBUF_H_INSIDE + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include + +#undef GDK_PIXBUF_H_INSIDE + +#endif /* GDK_PIXBUF_H */ diff --git a/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixdata.h b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixdata.h new file mode 100644 index 0000000000000000000000000000000000000000..4c25698a28b7b65f02e1a391b65832f75cb18a4c --- /dev/null +++ b/data/miniconda3/include/gdk-pixbuf-2.0/gdk-pixbuf/gdk-pixdata.h @@ -0,0 +1,165 @@ +/* GdkPixbuf library - GdkPixdata - functions for inlined pixbuf handling + * Copyright (C) 1999, 2001 Tim Janik + * + * 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; either + * version 2 of the License, or (at your option) any later version. + * + * 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, see . + */ +#ifndef __GDK_PIXDATA_H__ +#define __GDK_PIXDATA_H__ + +#ifndef GDK_PIXBUF_DISABLE_DEPRECATED +#include + +G_BEGIN_DECLS + +/** + * GDK_PIXBUF_MAGIC_NUMBER: + * + * Magic number for #GdkPixdata structures. + **/ +#define GDK_PIXBUF_MAGIC_NUMBER (0x47646b50) /* 'GdkP' */ + +/** + * GdkPixdataType: + * @GDK_PIXDATA_COLOR_TYPE_RGB: each pixel has red, green and blue samples. + * @GDK_PIXDATA_COLOR_TYPE_RGBA: each pixel has red, green and blue samples + * and an alpha value. + * @GDK_PIXDATA_COLOR_TYPE_MASK: mask for the colortype flags of the enum. + * @GDK_PIXDATA_SAMPLE_WIDTH_8: each sample has 8 bits. + * @GDK_PIXDATA_SAMPLE_WIDTH_MASK: mask for the sample width flags of the enum. + * @GDK_PIXDATA_ENCODING_RAW: the pixel data is in raw form. + * @GDK_PIXDATA_ENCODING_RLE: the pixel data is run-length encoded. Runs may + * be up to 127 bytes long; their length is stored in a single byte + * preceding the pixel data for the run. If a run is constant, its length + * byte has the high bit set and the pixel data consists of a single pixel + * which must be repeated. + * @GDK_PIXDATA_ENCODING_MASK: mask for the encoding flags of the enum. + * + * An enumeration containing three sets of flags for a #GdkPixdata struct: + * one for the used colorspace, one for the width of the samples and one + * for the encoding of the pixel data. + * + * Deprecated: 2.32 + **/ +typedef enum +{ + /* colorspace + alpha */ + GDK_PIXDATA_COLOR_TYPE_RGB = 0x01, + GDK_PIXDATA_COLOR_TYPE_RGBA = 0x02, + GDK_PIXDATA_COLOR_TYPE_MASK = 0xff, + /* width, support 8bits only currently */ + GDK_PIXDATA_SAMPLE_WIDTH_8 = 0x01 << 16, + GDK_PIXDATA_SAMPLE_WIDTH_MASK = 0x0f << 16, + /* encoding */ + GDK_PIXDATA_ENCODING_RAW = 0x01 << 24, + GDK_PIXDATA_ENCODING_RLE = 0x02 << 24, + GDK_PIXDATA_ENCODING_MASK = 0x0f << 24 +} GdkPixdataType; + +typedef struct _GdkPixdata GdkPixdata; +struct _GdkPixdata +{ + guint32 magic; /* GDK_PIXBUF_MAGIC_NUMBER */ + gint32 length; /* <1 to disable length checks, otherwise: + * GDK_PIXDATA_HEADER_LENGTH + pixel_data length + */ + guint32 pixdata_type; /* GdkPixdataType */ + guint32 rowstride; + guint32 width; + guint32 height; + guint8 *pixel_data; +}; + +/** + * GDK_PIXDATA_HEADER_LENGTH: + * + * The length of a #GdkPixdata structure without the @pixel_data pointer. + * + * Deprecated: 2.32 + **/ +#define GDK_PIXDATA_HEADER_LENGTH (4 + 4 + 4 + 4 + 4 + 4) + +/* the returned stream is plain htonl of GdkPixdata members + pixel_data */ +GDK_PIXBUF_DEPRECATED_IN_2_32 +guint8* gdk_pixdata_serialize (const GdkPixdata *pixdata, + guint *stream_length_p); +GDK_PIXBUF_DEPRECATED_IN_2_32 +gboolean gdk_pixdata_deserialize (GdkPixdata *pixdata, + guint stream_length, + const guint8 *stream, + GError **error); +GDK_PIXBUF_DEPRECATED_IN_2_32 +gpointer gdk_pixdata_from_pixbuf (GdkPixdata *pixdata, + const GdkPixbuf *pixbuf, + gboolean use_rle); +GDK_PIXBUF_DEPRECATED_IN_2_32 +GdkPixbuf* gdk_pixbuf_from_pixdata (const GdkPixdata *pixdata, + gboolean copy_pixels, + GError **error); +/** + * GdkPixdataDumpType: + * @GDK_PIXDATA_DUMP_PIXDATA_STREAM: Generate pixbuf data stream (a single + * string containing a serialized #GdkPixdata structure in network byte + * order). + * @GDK_PIXDATA_DUMP_PIXDATA_STRUCT: Generate #GdkPixdata structure (needs + * the #GdkPixdata structure definition from gdk-pixdata.h). + * @GDK_PIXDATA_DUMP_MACROS: Generate *_ROWSTRIDE, + * *_WIDTH, *_HEIGHT, + * *_BYTES_PER_PIXEL and + * *_RLE_PIXEL_DATA or *_PIXEL_DATA + * macro definitions for the image. + * @GDK_PIXDATA_DUMP_GTYPES: Generate GLib data types instead of + * standard C data types. + * @GDK_PIXDATA_DUMP_CTYPES: Generate standard C data types instead of + * GLib data types. + * @GDK_PIXDATA_DUMP_STATIC: Generate static symbols. + * @GDK_PIXDATA_DUMP_CONST: Generate const symbols. + * @GDK_PIXDATA_DUMP_RLE_DECODER: Provide a *_RUN_LENGTH_DECODE(image_buf, rle_data, size, bpp) + * macro definition to decode run-length encoded image data. + * + * An enumeration which is used by gdk_pixdata_to_csource() to + * determine the form of C source to be generated. The three values + * @GDK_PIXDATA_DUMP_PIXDATA_STREAM, @GDK_PIXDATA_DUMP_PIXDATA_STRUCT + * and @GDK_PIXDATA_DUMP_MACROS are mutually exclusive, as are + * @GDK_PIXBUF_DUMP_GTYPES and @GDK_PIXBUF_DUMP_CTYPES. The remaining + * elements are optional flags that can be freely added. + * + * Deprecated: 2.32 + **/ +typedef enum +{ + /* type of source to save */ + GDK_PIXDATA_DUMP_PIXDATA_STREAM = 0, + GDK_PIXDATA_DUMP_PIXDATA_STRUCT = 1, + GDK_PIXDATA_DUMP_MACROS = 2, + /* type of variables to use */ + GDK_PIXDATA_DUMP_GTYPES = 0, + GDK_PIXDATA_DUMP_CTYPES = 1 << 8, + GDK_PIXDATA_DUMP_STATIC = 1 << 9, + GDK_PIXDATA_DUMP_CONST = 1 << 10, + /* save RLE decoder macro? */ + GDK_PIXDATA_DUMP_RLE_DECODER = 1 << 16 +} GdkPixdataDumpType; + + +GDK_PIXBUF_DEPRECATED_IN_2_32 +GString* gdk_pixdata_to_csource (GdkPixdata *pixdata, + const gchar *name, + GdkPixdataDumpType dump_type); + + +G_END_DECLS + +#endif /* GDK_PIXBUF_DISABLE_DEPRECATED */ + +#endif /* __GDK_PIXDATA_H__ */ diff --git a/data/miniconda3/include/gtest/internal/custom/README.md b/data/miniconda3/include/gtest/internal/custom/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ff391fb4e2b5765cac8c6943359b15bbd5f4f149 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/custom/README.md @@ -0,0 +1,56 @@ +# Customization Points + +The custom directory is an injection point for custom user configurations. + +## Header `gtest.h` + +### The following macros can be defined: + +* `GTEST_OS_STACK_TRACE_GETTER_` - The name of an implementation of + `OsStackTraceGetterInterface`. +* `GTEST_CUSTOM_TEMPDIR_FUNCTION_` - An override for `testing::TempDir()`. See + `testing::TempDir` for semantics and signature. + +## Header `gtest-port.h` + +The following macros can be defined: + +### Flag related macros: + +* `GTEST_FLAG(flag_name)` +* `GTEST_USE_OWN_FLAGFILE_FLAG_` - Define to 0 when the system provides its + own flagfile flag parsing. +* `GTEST_DECLARE_bool_(name)` +* `GTEST_DECLARE_int32_(name)` +* `GTEST_DECLARE_string_(name)` +* `GTEST_DEFINE_bool_(name, default_val, doc)` +* `GTEST_DEFINE_int32_(name, default_val, doc)` +* `GTEST_DEFINE_string_(name, default_val, doc)` + +### Logging: + +* `GTEST_LOG_(severity)` +* `GTEST_CHECK_(condition)` +* Functions `LogToStderr()` and `FlushInfoLog()` have to be provided too. + +### Threading: + +* `GTEST_HAS_NOTIFICATION_` - Enabled if Notification is already provided. +* `GTEST_HAS_MUTEX_AND_THREAD_LOCAL_` - Enabled if `Mutex` and `ThreadLocal` + are already provided. Must also provide `GTEST_DECLARE_STATIC_MUTEX_(mutex)` + and `GTEST_DEFINE_STATIC_MUTEX_(mutex)` +* `GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks)` +* `GTEST_LOCK_EXCLUDED_(locks)` + +### Underlying library support features + +* `GTEST_HAS_CXXABI_H_` + +### Exporting API symbols: + +* `GTEST_API_` - Specifier for exported symbols. + +## Header `gtest-printers.h` + +* See documentation at `gtest/gtest-printers.h` for details on how to define a + custom printer. diff --git a/data/miniconda3/include/gtest/internal/custom/gtest-port.h b/data/miniconda3/include/gtest/internal/custom/gtest-port.h new file mode 100644 index 0000000000000000000000000000000000000000..db02881c0c899a74f07985980afa2e6e98c68875 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/custom/gtest-port.h @@ -0,0 +1,37 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// Injection point for custom user configurations. See README for details +// +// ** Custom implementation starts here ** + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PORT_H_ diff --git a/data/miniconda3/include/gtest/internal/custom/gtest-printers.h b/data/miniconda3/include/gtest/internal/custom/gtest-printers.h new file mode 100644 index 0000000000000000000000000000000000000000..b9495d83783bcde050f5fdc177036aa4880b3fd9 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/custom/gtest-printers.h @@ -0,0 +1,42 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// This file provides an injection point for custom printers in a local +// installation of gTest. +// It will be included from gtest-printers.h and the overrides in this file +// will be visible to everyone. +// +// Injection point for custom user configurations. See README for details +// +// ** Custom implementation starts here ** + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_PRINTERS_H_ diff --git a/data/miniconda3/include/gtest/internal/custom/gtest.h b/data/miniconda3/include/gtest/internal/custom/gtest.h new file mode 100644 index 0000000000000000000000000000000000000000..afaaf17ba28e3beb790a12638cffec8dba5698ea --- /dev/null +++ b/data/miniconda3/include/gtest/internal/custom/gtest.h @@ -0,0 +1,37 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// Injection point for custom user configurations. See README for details +// +// ** Custom implementation starts here ** + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_CUSTOM_GTEST_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-death-test-internal.h b/data/miniconda3/include/gtest/internal/gtest-death-test-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..490296dfad2d00c4811eb49126ab2656961c778d --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-death-test-internal.h @@ -0,0 +1,304 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This header file defines internal utilities needed for implementing +// death tests. They are subject to change without notice. +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ + +#include "gtest/gtest-matchers.h" +#include "gtest/internal/gtest-internal.h" + +#include +#include + +namespace testing { +namespace internal { + +GTEST_DECLARE_string_(internal_run_death_test); + +// Names of the flags (needed for parsing Google Test flags). +const char kDeathTestStyleFlag[] = "death_test_style"; +const char kDeathTestUseFork[] = "death_test_use_fork"; +const char kInternalRunDeathTestFlag[] = "internal_run_death_test"; + +#if GTEST_HAS_DEATH_TEST + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) + +// DeathTest is a class that hides much of the complexity of the +// GTEST_DEATH_TEST_ macro. It is abstract; its static Create method +// returns a concrete class that depends on the prevailing death test +// style, as defined by the --gtest_death_test_style and/or +// --gtest_internal_run_death_test flags. + +// In describing the results of death tests, these terms are used with +// the corresponding definitions: +// +// exit status: The integer exit information in the format specified +// by wait(2) +// exit code: The integer code passed to exit(3), _exit(2), or +// returned from main() +class GTEST_API_ DeathTest { + public: + // Create returns false if there was an error determining the + // appropriate action to take for the current death test; for example, + // if the gtest_death_test_style flag is set to an invalid value. + // The LastMessage method will return a more detailed message in that + // case. Otherwise, the DeathTest pointer pointed to by the "test" + // argument is set. If the death test should be skipped, the pointer + // is set to NULL; otherwise, it is set to the address of a new concrete + // DeathTest object that controls the execution of the current test. + static bool Create(const char* statement, Matcher matcher, + const char* file, int line, DeathTest** test); + DeathTest(); + virtual ~DeathTest() { } + + // A helper class that aborts a death test when it's deleted. + class ReturnSentinel { + public: + explicit ReturnSentinel(DeathTest* test) : test_(test) { } + ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); } + private: + DeathTest* const test_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ReturnSentinel); + } GTEST_ATTRIBUTE_UNUSED_; + + // An enumeration of possible roles that may be taken when a death + // test is encountered. EXECUTE means that the death test logic should + // be executed immediately. OVERSEE means that the program should prepare + // the appropriate environment for a child process to execute the death + // test, then wait for it to complete. + enum TestRole { OVERSEE_TEST, EXECUTE_TEST }; + + // An enumeration of the three reasons that a test might be aborted. + enum AbortReason { + TEST_ENCOUNTERED_RETURN_STATEMENT, + TEST_THREW_EXCEPTION, + TEST_DID_NOT_DIE + }; + + // Assumes one of the above roles. + virtual TestRole AssumeRole() = 0; + + // Waits for the death test to finish and returns its status. + virtual int Wait() = 0; + + // Returns true if the death test passed; that is, the test process + // exited during the test, its exit status matches a user-supplied + // predicate, and its stderr output matches a user-supplied regular + // expression. + // The user-supplied predicate may be a macro expression rather + // than a function pointer or functor, or else Wait and Passed could + // be combined. + virtual bool Passed(bool exit_status_ok) = 0; + + // Signals that the death test did not die as expected. + virtual void Abort(AbortReason reason) = 0; + + // Returns a human-readable outcome message regarding the outcome of + // the last death test. + static const char* LastMessage(); + + static void set_last_death_test_message(const std::string& message); + + private: + // A string containing a description of the outcome of the last death test. + static std::string last_death_test_message_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); +}; + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 + +// Factory interface for death tests. May be mocked out for testing. +class DeathTestFactory { + public: + virtual ~DeathTestFactory() { } + virtual bool Create(const char* statement, + Matcher matcher, const char* file, + int line, DeathTest** test) = 0; +}; + +// A concrete DeathTestFactory implementation for normal use. +class DefaultDeathTestFactory : public DeathTestFactory { + public: + bool Create(const char* statement, Matcher matcher, + const char* file, int line, DeathTest** test) override; +}; + +// Returns true if exit_status describes a process that was terminated +// by a signal, or exited normally with a nonzero exit code. +GTEST_API_ bool ExitedUnsuccessfully(int exit_status); + +// A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads +// and interpreted as a regex (rather than an Eq matcher) for legacy +// compatibility. +inline Matcher MakeDeathTestMatcher( + ::testing::internal::RE regex) { + return ContainsRegex(regex.pattern()); +} +inline Matcher MakeDeathTestMatcher(const char* regex) { + return ContainsRegex(regex); +} +inline Matcher MakeDeathTestMatcher( + const ::std::string& regex) { + return ContainsRegex(regex); +} + +// If a Matcher is passed to EXPECT_DEATH (etc.), it's +// used directly. +inline Matcher MakeDeathTestMatcher( + Matcher matcher) { + return matcher; +} + +// Traps C++ exceptions escaping statement and reports them as test +// failures. Note that trapping SEH exceptions is not implemented here. +# if GTEST_HAS_EXCEPTIONS +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (const ::std::exception& gtest_exception) { \ + fprintf(\ + stderr, \ + "\n%s: Caught std::exception-derived exception escaping the " \ + "death test statement. Exception message: %s\n", \ + ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ + gtest_exception.what()); \ + fflush(stderr); \ + death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ + } catch (...) { \ + death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ + } + +# else +# define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) + +# endif + +// This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*, +// ASSERT_EXIT*, and EXPECT_EXIT*. +#define GTEST_DEATH_TEST_(statement, predicate, regex_or_matcher, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + ::testing::internal::DeathTest* gtest_dt; \ + if (!::testing::internal::DeathTest::Create( \ + #statement, \ + ::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \ + __FILE__, __LINE__, >est_dt)) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ + } \ + if (gtest_dt != nullptr) { \ + std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \ + switch (gtest_dt->AssumeRole()) { \ + case ::testing::internal::DeathTest::OVERSEE_TEST: \ + if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ + } \ + break; \ + case ::testing::internal::DeathTest::EXECUTE_TEST: { \ + ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ + gtest_dt); \ + GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ + gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ + break; \ + } \ + default: \ + break; \ + } \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \ + : fail(::testing::internal::DeathTest::LastMessage()) +// The symbol "fail" here expands to something into which a message +// can be streamed. + +// This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in +// NDEBUG mode. In this case we need the statements to be executed and the macro +// must accept a streamed message even though the message is never printed. +// The regex object is not evaluated, but it is used to prevent "unused" +// warnings and to avoid an expression that doesn't compile in debug mode. +#define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } else if (!::testing::internal::AlwaysTrue()) { \ + ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \ + } else \ + ::testing::Message() + +// A class representing the parsed contents of the +// --gtest_internal_run_death_test flag, as it existed when +// RUN_ALL_TESTS was called. +class InternalRunDeathTestFlag { + public: + InternalRunDeathTestFlag(const std::string& a_file, + int a_line, + int an_index, + int a_write_fd) + : file_(a_file), line_(a_line), index_(an_index), + write_fd_(a_write_fd) {} + + ~InternalRunDeathTestFlag() { + if (write_fd_ >= 0) + posix::Close(write_fd_); + } + + const std::string& file() const { return file_; } + int line() const { return line_; } + int index() const { return index_; } + int write_fd() const { return write_fd_; } + + private: + std::string file_; + int line_; + int index_; + int write_fd_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); +}; + +// Returns a newly created InternalRunDeathTestFlag object with fields +// initialized from the GTEST_FLAG(internal_run_death_test) flag if +// the flag is specified; otherwise returns NULL. +InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); + +#endif // GTEST_HAS_DEATH_TEST + +} // namespace internal +} // namespace testing + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-filepath.h b/data/miniconda3/include/gtest/internal/gtest-filepath.h new file mode 100644 index 0000000000000000000000000000000000000000..0c033abc34e0036f39d582366ebe46cb66f2680c --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-filepath.h @@ -0,0 +1,211 @@ +// Copyright 2008, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// Google Test filepath utilities +// +// This header file declares classes and functions used internally by +// Google Test. They are subject to change without notice. +// +// This file is #included in gtest/internal/gtest-internal.h. +// Do not include this header file separately! + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ + +#include "gtest/internal/gtest-string.h" + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) + +namespace testing { +namespace internal { + +// FilePath - a class for file and directory pathname manipulation which +// handles platform-specific conventions (like the pathname separator). +// Used for helper functions for naming files in a directory for xml output. +// Except for Set methods, all methods are const or static, which provides an +// "immutable value object" -- useful for peace of mind. +// A FilePath with a value ending in a path separator ("like/this/") represents +// a directory, otherwise it is assumed to represent a file. In either case, +// it may or may not represent an actual file or directory in the file system. +// Names are NOT checked for syntax correctness -- no checking for illegal +// characters, malformed paths, etc. + +class GTEST_API_ FilePath { + public: + FilePath() : pathname_("") { } + FilePath(const FilePath& rhs) : pathname_(rhs.pathname_) { } + + explicit FilePath(const std::string& pathname) : pathname_(pathname) { + Normalize(); + } + + FilePath& operator=(const FilePath& rhs) { + Set(rhs); + return *this; + } + + void Set(const FilePath& rhs) { + pathname_ = rhs.pathname_; + } + + const std::string& string() const { return pathname_; } + const char* c_str() const { return pathname_.c_str(); } + + // Returns the current working directory, or "" if unsuccessful. + static FilePath GetCurrentDir(); + + // Given directory = "dir", base_name = "test", number = 0, + // extension = "xml", returns "dir/test.xml". If number is greater + // than zero (e.g., 12), returns "dir/test_12.xml". + // On Windows platform, uses \ as the separator rather than /. + static FilePath MakeFileName(const FilePath& directory, + const FilePath& base_name, + int number, + const char* extension); + + // Given directory = "dir", relative_path = "test.xml", + // returns "dir/test.xml". + // On Windows, uses \ as the separator rather than /. + static FilePath ConcatPaths(const FilePath& directory, + const FilePath& relative_path); + + // Returns a pathname for a file that does not currently exist. The pathname + // will be directory/base_name.extension or + // directory/base_name_.extension if directory/base_name.extension + // already exists. The number will be incremented until a pathname is found + // that does not already exist. + // Examples: 'dir/foo_test.xml' or 'dir/foo_test_1.xml'. + // There could be a race condition if two or more processes are calling this + // function at the same time -- they could both pick the same filename. + static FilePath GenerateUniqueFileName(const FilePath& directory, + const FilePath& base_name, + const char* extension); + + // Returns true if and only if the path is "". + bool IsEmpty() const { return pathname_.empty(); } + + // If input name has a trailing separator character, removes it and returns + // the name, otherwise return the name string unmodified. + // On Windows platform, uses \ as the separator, other platforms use /. + FilePath RemoveTrailingPathSeparator() const; + + // Returns a copy of the FilePath with the directory part removed. + // Example: FilePath("path/to/file").RemoveDirectoryName() returns + // FilePath("file"). If there is no directory part ("just_a_file"), it returns + // the FilePath unmodified. If there is no file part ("just_a_dir/") it + // returns an empty FilePath (""). + // On Windows platform, '\' is the path separator, otherwise it is '/'. + FilePath RemoveDirectoryName() const; + + // RemoveFileName returns the directory path with the filename removed. + // Example: FilePath("path/to/file").RemoveFileName() returns "path/to/". + // If the FilePath is "a_file" or "/a_file", RemoveFileName returns + // FilePath("./") or, on Windows, FilePath(".\\"). If the filepath does + // not have a file, like "just/a/dir/", it returns the FilePath unmodified. + // On Windows platform, '\' is the path separator, otherwise it is '/'. + FilePath RemoveFileName() const; + + // Returns a copy of the FilePath with the case-insensitive extension removed. + // Example: FilePath("dir/file.exe").RemoveExtension("EXE") returns + // FilePath("dir/file"). If a case-insensitive extension is not + // found, returns a copy of the original FilePath. + FilePath RemoveExtension(const char* extension) const; + + // Creates directories so that path exists. Returns true if successful or if + // the directories already exist; returns false if unable to create + // directories for any reason. Will also return false if the FilePath does + // not represent a directory (that is, it doesn't end with a path separator). + bool CreateDirectoriesRecursively() const; + + // Create the directory so that path exists. Returns true if successful or + // if the directory already exists; returns false if unable to create the + // directory for any reason, including if the parent directory does not + // exist. Not named "CreateDirectory" because that's a macro on Windows. + bool CreateFolder() const; + + // Returns true if FilePath describes something in the file-system, + // either a file, directory, or whatever, and that something exists. + bool FileOrDirectoryExists() const; + + // Returns true if pathname describes a directory in the file-system + // that exists. + bool DirectoryExists() const; + + // Returns true if FilePath ends with a path separator, which indicates that + // it is intended to represent a directory. Returns false otherwise. + // This does NOT check that a directory (or file) actually exists. + bool IsDirectory() const; + + // Returns true if pathname describes a root directory. (Windows has one + // root directory per disk drive.) + bool IsRootDirectory() const; + + // Returns true if pathname describes an absolute path. + bool IsAbsolutePath() const; + + private: + // Replaces multiple consecutive separators with a single separator. + // For example, "bar///foo" becomes "bar/foo". Does not eliminate other + // redundancies that might be in a pathname involving "." or "..". + // + // A pathname with multiple consecutive separators may occur either through + // user error or as a result of some scripts or APIs that generate a pathname + // with a trailing separator. On other platforms the same API or script + // may NOT generate a pathname with a trailing "/". Then elsewhere that + // pathname may have another "/" and pathname components added to it, + // without checking for the separator already being there. + // The script language and operating system may allow paths like "foo//bar" + // but some of the functions in FilePath will not handle that correctly. In + // particular, RemoveTrailingPathSeparator() only removes one separator, and + // it is called in CreateDirectoriesRecursively() assuming that it will change + // a pathname from directory syntax (trailing separator) to filename syntax. + // + // On Windows this method also replaces the alternate path separator '/' with + // the primary path separator '\\', so that for example "bar\\/\\foo" becomes + // "bar\\foo". + + void Normalize(); + + // Returns a pointer to the last occurrence of a valid path separator in + // the FilePath. On Windows, for example, both '/' and '\' are valid path + // separators. Returns NULL if no path separator was found. + const char* FindLastPathSeparator() const; + + std::string pathname_; +}; // class FilePath + +} // namespace internal +} // namespace testing + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_FILEPATH_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-internal.h b/data/miniconda3/include/gtest/internal/gtest-internal.h new file mode 100644 index 0000000000000000000000000000000000000000..f8cbdbd81d9a4c6be040c47fdd8dc8622df061cd --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-internal.h @@ -0,0 +1,1560 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This header file declares functions and macros used internally by +// Google Test. They are subject to change without notice. + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ + +#include "gtest/internal/gtest-port.h" + +#if GTEST_OS_LINUX +# include +# include +# include +# include +#endif // GTEST_OS_LINUX + +#if GTEST_HAS_EXCEPTIONS +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gtest/gtest-message.h" +#include "gtest/internal/gtest-filepath.h" +#include "gtest/internal/gtest-string.h" +#include "gtest/internal/gtest-type-util.h" + +// Due to C++ preprocessor weirdness, we need double indirection to +// concatenate two tokens when one of them is __LINE__. Writing +// +// foo ## __LINE__ +// +// will result in the token foo__LINE__, instead of foo followed by +// the current line number. For more details, see +// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6 +#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar) +#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo ## bar + +// Stringifies its argument. +// Work around a bug in visual studio which doesn't accept code like this: +// +// #define GTEST_STRINGIFY_(name) #name +// #define MACRO(a, b, c) ... GTEST_STRINGIFY_(a) ... +// MACRO(, x, y) +// +// Complaining about the argument to GTEST_STRINGIFY_ being empty. +// This is allowed by the spec. +#define GTEST_STRINGIFY_HELPER_(name, ...) #name +#define GTEST_STRINGIFY_(...) GTEST_STRINGIFY_HELPER_(__VA_ARGS__, ) + +namespace proto2 { +class MessageLite; +} + +namespace testing { + +// Forward declarations. + +class AssertionResult; // Result of an assertion. +class Message; // Represents a failure message. +class Test; // Represents a test. +class TestInfo; // Information about a test. +class TestPartResult; // Result of a test part. +class UnitTest; // A collection of test suites. + +template +::std::string PrintToString(const T& value); + +namespace internal { + +struct TraceInfo; // Information about a trace point. +class TestInfoImpl; // Opaque implementation of TestInfo +class UnitTestImpl; // Opaque implementation of UnitTest + +// The text used in failure messages to indicate the start of the +// stack trace. +GTEST_API_ extern const char kStackTraceMarker[]; + +// An IgnoredValue object can be implicitly constructed from ANY value. +class IgnoredValue { + struct Sink {}; + public: + // This constructor template allows any value to be implicitly + // converted to IgnoredValue. The object has no data member and + // doesn't try to remember anything about the argument. We + // deliberately omit the 'explicit' keyword in order to allow the + // conversion to be implicit. + // Disable the conversion if T already has a magical conversion operator. + // Otherwise we get ambiguity. + template ::value, + int>::type = 0> + IgnoredValue(const T& /* ignored */) {} // NOLINT(runtime/explicit) +}; + +// Appends the user-supplied message to the Google-Test-generated message. +GTEST_API_ std::string AppendUserMessage( + const std::string& gtest_msg, const Message& user_msg); + +#if GTEST_HAS_EXCEPTIONS + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4275 \ +/* an exported class was derived from a class that was not exported */) + +// This exception is thrown by (and only by) a failed Google Test +// assertion when GTEST_FLAG(throw_on_failure) is true (if exceptions +// are enabled). We derive it from std::runtime_error, which is for +// errors presumably detectable only at run time. Since +// std::runtime_error inherits from std::exception, many testing +// frameworks know how to extract and print the message inside it. +class GTEST_API_ GoogleTestFailureException : public ::std::runtime_error { + public: + explicit GoogleTestFailureException(const TestPartResult& failure); +}; + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4275 + +#endif // GTEST_HAS_EXCEPTIONS + +namespace edit_distance { +// Returns the optimal edits to go from 'left' to 'right'. +// All edits cost the same, with replace having lower priority than +// add/remove. +// Simple implementation of the Wagner-Fischer algorithm. +// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm +enum EditType { kMatch, kAdd, kRemove, kReplace }; +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, const std::vector& right); + +// Same as above, but the input is represented as strings. +GTEST_API_ std::vector CalculateOptimalEdits( + const std::vector& left, + const std::vector& right); + +// Create a diff of the input strings in Unified diff format. +GTEST_API_ std::string CreateUnifiedDiff(const std::vector& left, + const std::vector& right, + size_t context = 2); + +} // namespace edit_distance + +// Calculate the diff between 'left' and 'right' and return it in unified diff +// format. +// If not null, stores in 'total_line_count' the total number of lines found +// in left + right. +GTEST_API_ std::string DiffStrings(const std::string& left, + const std::string& right, + size_t* total_line_count); + +// Constructs and returns the message for an equality assertion +// (e.g. ASSERT_EQ, EXPECT_STREQ, etc) failure. +// +// The first four parameters are the expressions used in the assertion +// and their values, as strings. For example, for ASSERT_EQ(foo, bar) +// where foo is 5 and bar is 6, we have: +// +// expected_expression: "foo" +// actual_expression: "bar" +// expected_value: "5" +// actual_value: "6" +// +// The ignoring_case parameter is true if and only if the assertion is a +// *_STRCASEEQ*. When it's true, the string " (ignoring case)" will +// be inserted into the message. +GTEST_API_ AssertionResult EqFailure(const char* expected_expression, + const char* actual_expression, + const std::string& expected_value, + const std::string& actual_value, + bool ignoring_case); + +// Constructs a failure message for Boolean assertions such as EXPECT_TRUE. +GTEST_API_ std::string GetBoolAssertionFailureMessage( + const AssertionResult& assertion_result, + const char* expression_text, + const char* actual_predicate_value, + const char* expected_predicate_value); + +// This template class represents an IEEE floating-point number +// (either single-precision or double-precision, depending on the +// template parameters). +// +// The purpose of this class is to do more sophisticated number +// comparison. (Due to round-off error, etc, it's very unlikely that +// two floating-points will be equal exactly. Hence a naive +// comparison by the == operation often doesn't work.) +// +// Format of IEEE floating-point: +// +// The most-significant bit being the leftmost, an IEEE +// floating-point looks like +// +// sign_bit exponent_bits fraction_bits +// +// Here, sign_bit is a single bit that designates the sign of the +// number. +// +// For float, there are 8 exponent bits and 23 fraction bits. +// +// For double, there are 11 exponent bits and 52 fraction bits. +// +// More details can be found at +// http://en.wikipedia.org/wiki/IEEE_floating-point_standard. +// +// Template parameter: +// +// RawType: the raw floating-point type (either float or double) +template +class FloatingPoint { + public: + // Defines the unsigned integer type that has the same size as the + // floating point number. + typedef typename TypeWithSize::UInt Bits; + + // Constants. + + // # of bits in a number. + static const size_t kBitCount = 8*sizeof(RawType); + + // # of fraction bits in a number. + static const size_t kFractionBitCount = + std::numeric_limits::digits - 1; + + // # of exponent bits in a number. + static const size_t kExponentBitCount = kBitCount - 1 - kFractionBitCount; + + // The mask for the sign bit. + static const Bits kSignBitMask = static_cast(1) << (kBitCount - 1); + + // The mask for the fraction bits. + static const Bits kFractionBitMask = + ~static_cast(0) >> (kExponentBitCount + 1); + + // The mask for the exponent bits. + static const Bits kExponentBitMask = ~(kSignBitMask | kFractionBitMask); + + // How many ULP's (Units in the Last Place) we want to tolerate when + // comparing two numbers. The larger the value, the more error we + // allow. A 0 value means that two numbers must be exactly the same + // to be considered equal. + // + // The maximum error of a single floating-point operation is 0.5 + // units in the last place. On Intel CPU's, all floating-point + // calculations are done with 80-bit precision, while double has 64 + // bits. Therefore, 4 should be enough for ordinary use. + // + // See the following article for more details on ULP: + // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/ + static const uint32_t kMaxUlps = 4; + + // Constructs a FloatingPoint from a raw floating-point number. + // + // On an Intel CPU, passing a non-normalized NAN (Not a Number) + // around may change its bits, although the new value is guaranteed + // to be also a NAN. Therefore, don't expect this constructor to + // preserve the bits in x when x is a NAN. + explicit FloatingPoint(const RawType& x) { u_.value_ = x; } + + // Static methods + + // Reinterprets a bit pattern as a floating-point number. + // + // This function is needed to test the AlmostEquals() method. + static RawType ReinterpretBits(const Bits bits) { + FloatingPoint fp(0); + fp.u_.bits_ = bits; + return fp.u_.value_; + } + + // Returns the floating-point number that represent positive infinity. + static RawType Infinity() { + return ReinterpretBits(kExponentBitMask); + } + + // Returns the maximum representable finite floating-point number. + static RawType Max(); + + // Non-static methods + + // Returns the bits that represents this number. + const Bits &bits() const { return u_.bits_; } + + // Returns the exponent bits of this number. + Bits exponent_bits() const { return kExponentBitMask & u_.bits_; } + + // Returns the fraction bits of this number. + Bits fraction_bits() const { return kFractionBitMask & u_.bits_; } + + // Returns the sign bit of this number. + Bits sign_bit() const { return kSignBitMask & u_.bits_; } + + // Returns true if and only if this is NAN (not a number). + bool is_nan() const { + // It's a NAN if the exponent bits are all ones and the fraction + // bits are not entirely zeros. + return (exponent_bits() == kExponentBitMask) && (fraction_bits() != 0); + } + + // Returns true if and only if this number is at most kMaxUlps ULP's away + // from rhs. In particular, this function: + // + // - returns false if either number is (or both are) NAN. + // - treats really large numbers as almost equal to infinity. + // - thinks +0.0 and -0.0 are 0 DLP's apart. + bool AlmostEquals(const FloatingPoint& rhs) const { + // The IEEE standard says that any comparison operation involving + // a NAN must return false. + if (is_nan() || rhs.is_nan()) return false; + + return DistanceBetweenSignAndMagnitudeNumbers(u_.bits_, rhs.u_.bits_) + <= kMaxUlps; + } + + private: + // The data type used to store the actual floating-point number. + union FloatingPointUnion { + RawType value_; // The raw floating-point number. + Bits bits_; // The bits that represent the number. + }; + + // Converts an integer from the sign-and-magnitude representation to + // the biased representation. More precisely, let N be 2 to the + // power of (kBitCount - 1), an integer x is represented by the + // unsigned number x + N. + // + // For instance, + // + // -N + 1 (the most negative number representable using + // sign-and-magnitude) is represented by 1; + // 0 is represented by N; and + // N - 1 (the biggest number representable using + // sign-and-magnitude) is represented by 2N - 1. + // + // Read http://en.wikipedia.org/wiki/Signed_number_representations + // for more details on signed number representations. + static Bits SignAndMagnitudeToBiased(const Bits &sam) { + if (kSignBitMask & sam) { + // sam represents a negative number. + return ~sam + 1; + } else { + // sam represents a positive number. + return kSignBitMask | sam; + } + } + + // Given two numbers in the sign-and-magnitude representation, + // returns the distance between them as an unsigned number. + static Bits DistanceBetweenSignAndMagnitudeNumbers(const Bits &sam1, + const Bits &sam2) { + const Bits biased1 = SignAndMagnitudeToBiased(sam1); + const Bits biased2 = SignAndMagnitudeToBiased(sam2); + return (biased1 >= biased2) ? (biased1 - biased2) : (biased2 - biased1); + } + + FloatingPointUnion u_; +}; + +// We cannot use std::numeric_limits::max() as it clashes with the max() +// macro defined by . +template <> +inline float FloatingPoint::Max() { return FLT_MAX; } +template <> +inline double FloatingPoint::Max() { return DBL_MAX; } + +// Typedefs the instances of the FloatingPoint template class that we +// care to use. +typedef FloatingPoint Float; +typedef FloatingPoint Double; + +// In order to catch the mistake of putting tests that use different +// test fixture classes in the same test suite, we need to assign +// unique IDs to fixture classes and compare them. The TypeId type is +// used to hold such IDs. The user should treat TypeId as an opaque +// type: the only operation allowed on TypeId values is to compare +// them for equality using the == operator. +typedef const void* TypeId; + +template +class TypeIdHelper { + public: + // dummy_ must not have a const type. Otherwise an overly eager + // compiler (e.g. MSVC 7.1 & 8.0) may try to merge + // TypeIdHelper::dummy_ for different Ts as an "optimization". + static bool dummy_; +}; + +template +bool TypeIdHelper::dummy_ = false; + +// GetTypeId() returns the ID of type T. Different values will be +// returned for different types. Calling the function twice with the +// same type argument is guaranteed to return the same ID. +template +TypeId GetTypeId() { + // The compiler is required to allocate a different + // TypeIdHelper::dummy_ variable for each T used to instantiate + // the template. Therefore, the address of dummy_ is guaranteed to + // be unique. + return &(TypeIdHelper::dummy_); +} + +// Returns the type ID of ::testing::Test. Always call this instead +// of GetTypeId< ::testing::Test>() to get the type ID of +// ::testing::Test, as the latter may give the wrong result due to a +// suspected linker bug when compiling Google Test as a Mac OS X +// framework. +GTEST_API_ TypeId GetTestTypeId(); + +// Defines the abstract factory interface that creates instances +// of a Test object. +class TestFactoryBase { + public: + virtual ~TestFactoryBase() {} + + // Creates a test instance to run. The instance is both created and destroyed + // within TestInfoImpl::Run() + virtual Test* CreateTest() = 0; + + protected: + TestFactoryBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestFactoryBase); +}; + +// This class provides implementation of TeastFactoryBase interface. +// It is used in TEST and TEST_F macros. +template +class TestFactoryImpl : public TestFactoryBase { + public: + Test* CreateTest() override { return new TestClass; } +}; + +#if GTEST_OS_WINDOWS + +// Predicate-formatters for implementing the HRESULT checking macros +// {ASSERT|EXPECT}_HRESULT_{SUCCEEDED|FAILED} +// We pass a long instead of HRESULT to avoid causing an +// include dependency for the HRESULT type. +GTEST_API_ AssertionResult IsHRESULTSuccess(const char* expr, + long hr); // NOLINT +GTEST_API_ AssertionResult IsHRESULTFailure(const char* expr, + long hr); // NOLINT + +#endif // GTEST_OS_WINDOWS + +// Types of SetUpTestSuite() and TearDownTestSuite() functions. +using SetUpTestSuiteFunc = void (*)(); +using TearDownTestSuiteFunc = void (*)(); + +struct CodeLocation { + CodeLocation(const std::string& a_file, int a_line) + : file(a_file), line(a_line) {} + + std::string file; + int line; +}; + +// Helper to identify which setup function for TestCase / TestSuite to call. +// Only one function is allowed, either TestCase or TestSute but not both. + +// Utility functions to help SuiteApiResolver +using SetUpTearDownSuiteFuncType = void (*)(); + +inline SetUpTearDownSuiteFuncType GetNotDefaultOrNull( + SetUpTearDownSuiteFuncType a, SetUpTearDownSuiteFuncType def) { + return a == def ? nullptr : a; +} + +template +// Note that SuiteApiResolver inherits from T because +// SetUpTestSuite()/TearDownTestSuite() could be protected. Ths way +// SuiteApiResolver can access them. +struct SuiteApiResolver : T { + // testing::Test is only forward declared at this point. So we make it a + // dependend class for the compiler to be OK with it. + using Test = + typename std::conditional::type; + + static SetUpTearDownSuiteFuncType GetSetUpCaseOrSuite(const char* filename, + int line_num) { +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + SetUpTearDownSuiteFuncType test_case_fp = + GetNotDefaultOrNull(&T::SetUpTestCase, &Test::SetUpTestCase); + SetUpTearDownSuiteFuncType test_suite_fp = + GetNotDefaultOrNull(&T::SetUpTestSuite, &Test::SetUpTestSuite); + + GTEST_CHECK_(!test_case_fp || !test_suite_fp) + << "Test can not provide both SetUpTestSuite and SetUpTestCase, please " + "make sure there is only one present at " + << filename << ":" << line_num; + + return test_case_fp != nullptr ? test_case_fp : test_suite_fp; +#else + (void)(filename); + (void)(line_num); + return &T::SetUpTestSuite; +#endif + } + + static SetUpTearDownSuiteFuncType GetTearDownCaseOrSuite(const char* filename, + int line_num) { +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + SetUpTearDownSuiteFuncType test_case_fp = + GetNotDefaultOrNull(&T::TearDownTestCase, &Test::TearDownTestCase); + SetUpTearDownSuiteFuncType test_suite_fp = + GetNotDefaultOrNull(&T::TearDownTestSuite, &Test::TearDownTestSuite); + + GTEST_CHECK_(!test_case_fp || !test_suite_fp) + << "Test can not provide both TearDownTestSuite and TearDownTestCase," + " please make sure there is only one present at" + << filename << ":" << line_num; + + return test_case_fp != nullptr ? test_case_fp : test_suite_fp; +#else + (void)(filename); + (void)(line_num); + return &T::TearDownTestSuite; +#endif + } +}; + +// Creates a new TestInfo object and registers it with Google Test; +// returns the created object. +// +// Arguments: +// +// test_suite_name: name of the test suite +// name: name of the test +// type_param: the name of the test's type parameter, or NULL if +// this is not a typed or a type-parameterized test. +// value_param: text representation of the test's value parameter, +// or NULL if this is not a type-parameterized test. +// code_location: code location where the test is defined +// fixture_class_id: ID of the test fixture class +// set_up_tc: pointer to the function that sets up the test suite +// tear_down_tc: pointer to the function that tears down the test suite +// factory: pointer to the factory that creates a test object. +// The newly created TestInfo instance will assume +// ownership of the factory object. +GTEST_API_ TestInfo* MakeAndRegisterTestInfo( + const char* test_suite_name, const char* name, const char* type_param, + const char* value_param, CodeLocation code_location, + TypeId fixture_class_id, SetUpTestSuiteFunc set_up_tc, + TearDownTestSuiteFunc tear_down_tc, TestFactoryBase* factory); + +// If *pstr starts with the given prefix, modifies *pstr to be right +// past the prefix and returns true; otherwise leaves *pstr unchanged +// and returns false. None of pstr, *pstr, and prefix can be NULL. +GTEST_API_ bool SkipPrefix(const char* prefix, const char** pstr); + +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251 \ +/* class A needs to have dll-interface to be used by clients of class B */) + +// State of the definition of a type-parameterized test suite. +class GTEST_API_ TypedTestSuitePState { + public: + TypedTestSuitePState() : registered_(false) {} + + // Adds the given test name to defined_test_names_ and return true + // if the test suite hasn't been registered; otherwise aborts the + // program. + bool AddTestName(const char* file, int line, const char* case_name, + const char* test_name) { + if (registered_) { + fprintf(stderr, + "%s Test %s must be defined before " + "REGISTER_TYPED_TEST_SUITE_P(%s, ...).\n", + FormatFileLocation(file, line).c_str(), test_name, case_name); + fflush(stderr); + posix::Abort(); + } + registered_tests_.insert( + ::std::make_pair(test_name, CodeLocation(file, line))); + return true; + } + + bool TestExists(const std::string& test_name) const { + return registered_tests_.count(test_name) > 0; + } + + const CodeLocation& GetCodeLocation(const std::string& test_name) const { + RegisteredTestsMap::const_iterator it = registered_tests_.find(test_name); + GTEST_CHECK_(it != registered_tests_.end()); + return it->second; + } + + // Verifies that registered_tests match the test names in + // defined_test_names_; returns registered_tests if successful, or + // aborts the program otherwise. + const char* VerifyRegisteredTestNames(const char* test_suite_name, + const char* file, int line, + const char* registered_tests); + + private: + typedef ::std::map RegisteredTestsMap; + + bool registered_; + RegisteredTestsMap registered_tests_; +}; + +// Legacy API is deprecated but still available +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ +using TypedTestCasePState = TypedTestSuitePState; +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4251 + +// Skips to the first non-space char after the first comma in 'str'; +// returns NULL if no comma is found in 'str'. +inline const char* SkipComma(const char* str) { + const char* comma = strchr(str, ','); + if (comma == nullptr) { + return nullptr; + } + while (IsSpace(*(++comma))) {} + return comma; +} + +// Returns the prefix of 'str' before the first comma in it; returns +// the entire string if it contains no comma. +inline std::string GetPrefixUntilComma(const char* str) { + const char* comma = strchr(str, ','); + return comma == nullptr ? str : std::string(str, comma); +} + +// Splits a given string on a given delimiter, populating a given +// vector with the fields. +void SplitString(const ::std::string& str, char delimiter, + ::std::vector< ::std::string>* dest); + +// The default argument to the template below for the case when the user does +// not provide a name generator. +struct DefaultNameGenerator { + template + static std::string GetName(int i) { + return StreamableToString(i); + } +}; + +template +struct NameGeneratorSelector { + typedef Provided type; +}; + +template +void GenerateNamesRecursively(internal::None, std::vector*, int) {} + +template +void GenerateNamesRecursively(Types, std::vector* result, int i) { + result->push_back(NameGenerator::template GetName(i)); + GenerateNamesRecursively(typename Types::Tail(), result, + i + 1); +} + +template +std::vector GenerateNames() { + std::vector result; + GenerateNamesRecursively(Types(), &result, 0); + return result; +} + +// TypeParameterizedTest::Register() +// registers a list of type-parameterized tests with Google Test. The +// return value is insignificant - we just need to return something +// such that we can call this function in a namespace scope. +// +// Implementation note: The GTEST_TEMPLATE_ macro declares a template +// template parameter. It's defined in gtest-type-util.h. +template +class TypeParameterizedTest { + public: + // 'index' is the index of the test in the type list 'Types' + // specified in INSTANTIATE_TYPED_TEST_SUITE_P(Prefix, TestSuite, + // Types). Valid values for 'index' are [0, N - 1] where N is the + // length of Types. + static bool Register(const char* prefix, const CodeLocation& code_location, + const char* case_name, const char* test_names, int index, + const std::vector& type_names = + GenerateNames()) { + typedef typename Types::Head Type; + typedef Fixture FixtureClass; + typedef typename GTEST_BIND_(TestSel, Type) TestClass; + + // First, registers the first type-parameterized test in the type + // list. + MakeAndRegisterTestInfo( + (std::string(prefix) + (prefix[0] == '\0' ? "" : "/") + case_name + + "/" + type_names[static_cast(index)]) + .c_str(), + StripTrailingSpaces(GetPrefixUntilComma(test_names)).c_str(), + GetTypeName().c_str(), + nullptr, // No value parameter. + code_location, GetTypeId(), + SuiteApiResolver::GetSetUpCaseOrSuite( + code_location.file.c_str(), code_location.line), + SuiteApiResolver::GetTearDownCaseOrSuite( + code_location.file.c_str(), code_location.line), + new TestFactoryImpl); + + // Next, recurses (at compile time) with the tail of the type list. + return TypeParameterizedTest::Register(prefix, + code_location, + case_name, + test_names, + index + 1, + type_names); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTest { + public: + static bool Register(const char* /*prefix*/, const CodeLocation&, + const char* /*case_name*/, const char* /*test_names*/, + int /*index*/, + const std::vector& = + std::vector() /*type_names*/) { + return true; + } +}; + +GTEST_API_ void RegisterTypeParameterizedTestSuite(const char* test_suite_name, + CodeLocation code_location); +GTEST_API_ void RegisterTypeParameterizedTestSuiteInstantiation( + const char* case_name); + +// TypeParameterizedTestSuite::Register() +// registers *all combinations* of 'Tests' and 'Types' with Google +// Test. The return value is insignificant - we just need to return +// something such that we can call this function in a namespace scope. +template +class TypeParameterizedTestSuite { + public: + static bool Register(const char* prefix, CodeLocation code_location, + const TypedTestSuitePState* state, const char* case_name, + const char* test_names, + const std::vector& type_names = + GenerateNames()) { + RegisterTypeParameterizedTestSuiteInstantiation(case_name); + std::string test_name = StripTrailingSpaces( + GetPrefixUntilComma(test_names)); + if (!state->TestExists(test_name)) { + fprintf(stderr, "Failed to get code location for test %s.%s at %s.", + case_name, test_name.c_str(), + FormatFileLocation(code_location.file.c_str(), + code_location.line).c_str()); + fflush(stderr); + posix::Abort(); + } + const CodeLocation& test_location = state->GetCodeLocation(test_name); + + typedef typename Tests::Head Head; + + // First, register the first test in 'Test' for each type in 'Types'. + TypeParameterizedTest::Register( + prefix, test_location, case_name, test_names, 0, type_names); + + // Next, recurses (at compile time) with the tail of the test list. + return TypeParameterizedTestSuite::Register(prefix, code_location, + state, case_name, + SkipComma(test_names), + type_names); + } +}; + +// The base case for the compile time recursion. +template +class TypeParameterizedTestSuite { + public: + static bool Register(const char* /*prefix*/, const CodeLocation&, + const TypedTestSuitePState* /*state*/, + const char* /*case_name*/, const char* /*test_names*/, + const std::vector& = + std::vector() /*type_names*/) { + return true; + } +}; + +// Returns the current OS stack trace as an std::string. +// +// The maximum number of stack frames to be included is specified by +// the gtest_stack_trace_depth flag. The skip_count parameter +// specifies the number of top frames to be skipped, which doesn't +// count against the number of frames to be included. +// +// For example, if Foo() calls Bar(), which in turn calls +// GetCurrentOsStackTraceExceptTop(..., 1), Foo() will be included in +// the trace but Bar() and GetCurrentOsStackTraceExceptTop() won't. +GTEST_API_ std::string GetCurrentOsStackTraceExceptTop( + UnitTest* unit_test, int skip_count); + +// Helpers for suppressing warnings on unreachable code or constant +// condition. + +// Always returns true. +GTEST_API_ bool AlwaysTrue(); + +// Always returns false. +inline bool AlwaysFalse() { return !AlwaysTrue(); } + +// Helper for suppressing false warning from Clang on a const char* +// variable declared in a conditional expression always being NULL in +// the else branch. +struct GTEST_API_ ConstCharPtr { + ConstCharPtr(const char* str) : value(str) {} + operator bool() const { return true; } + const char* value; +}; + +// Helper for declaring std::string within 'if' statement +// in pre C++17 build environment. +struct TrueWithString { + TrueWithString() = default; + explicit TrueWithString(const char* str) : value(str) {} + explicit TrueWithString(const std::string& str) : value(str) {} + explicit operator bool() const { return true; } + std::string value; +}; + +// A simple Linear Congruential Generator for generating random +// numbers with a uniform distribution. Unlike rand() and srand(), it +// doesn't use global state (and therefore can't interfere with user +// code). Unlike rand_r(), it's portable. An LCG isn't very random, +// but it's good enough for our purposes. +class GTEST_API_ Random { + public: + static const uint32_t kMaxRange = 1u << 31; + + explicit Random(uint32_t seed) : state_(seed) {} + + void Reseed(uint32_t seed) { state_ = seed; } + + // Generates a random number from [0, range). Crashes if 'range' is + // 0 or greater than kMaxRange. + uint32_t Generate(uint32_t range); + + private: + uint32_t state_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(Random); +}; + +// Turns const U&, U&, const U, and U all into U. +#define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ + typename std::remove_const::type>::type + +// HasDebugStringAndShortDebugString::value is a compile-time bool constant +// that's true if and only if T has methods DebugString() and ShortDebugString() +// that return std::string. +template +class HasDebugStringAndShortDebugString { + private: + template + static auto CheckDebugString(C*) -> typename std::is_same< + std::string, decltype(std::declval().DebugString())>::type; + template + static std::false_type CheckDebugString(...); + + template + static auto CheckShortDebugString(C*) -> typename std::is_same< + std::string, decltype(std::declval().ShortDebugString())>::type; + template + static std::false_type CheckShortDebugString(...); + + using HasDebugStringType = decltype(CheckDebugString(nullptr)); + using HasShortDebugStringType = decltype(CheckShortDebugString(nullptr)); + + public: + static constexpr bool value = + HasDebugStringType::value && HasShortDebugStringType::value; +}; + +template +constexpr bool HasDebugStringAndShortDebugString::value; + +// When the compiler sees expression IsContainerTest(0), if C is an +// STL-style container class, the first overload of IsContainerTest +// will be viable (since both C::iterator* and C::const_iterator* are +// valid types and NULL can be implicitly converted to them). It will +// be picked over the second overload as 'int' is a perfect match for +// the type of argument 0. If C::iterator or C::const_iterator is not +// a valid type, the first overload is not viable, and the second +// overload will be picked. Therefore, we can determine whether C is +// a container class by checking the type of IsContainerTest(0). +// The value of the expression is insignificant. +// +// In C++11 mode we check the existence of a const_iterator and that an +// iterator is properly implemented for the container. +// +// For pre-C++11 that we look for both C::iterator and C::const_iterator. +// The reason is that C++ injects the name of a class as a member of the +// class itself (e.g. you can refer to class iterator as either +// 'iterator' or 'iterator::iterator'). If we look for C::iterator +// only, for example, we would mistakenly think that a class named +// iterator is an STL container. +// +// Also note that the simpler approach of overloading +// IsContainerTest(typename C::const_iterator*) and +// IsContainerTest(...) doesn't work with Visual Age C++ and Sun C++. +typedef int IsContainer; +template ().begin()), + class = decltype(::std::declval().end()), + class = decltype(++::std::declval()), + class = decltype(*::std::declval()), + class = typename C::const_iterator> +IsContainer IsContainerTest(int /* dummy */) { + return 0; +} + +typedef char IsNotContainer; +template +IsNotContainer IsContainerTest(long /* dummy */) { return '\0'; } + +// Trait to detect whether a type T is a hash table. +// The heuristic used is that the type contains an inner type `hasher` and does +// not contain an inner type `reverse_iterator`. +// If the container is iterable in reverse, then order might actually matter. +template +struct IsHashTable { + private: + template + static char test(typename U::hasher*, typename U::reverse_iterator*); + template + static int test(typename U::hasher*, ...); + template + static char test(...); + + public: + static const bool value = sizeof(test(nullptr, nullptr)) == sizeof(int); +}; + +template +const bool IsHashTable::value; + +template (0)) == sizeof(IsContainer)> +struct IsRecursiveContainerImpl; + +template +struct IsRecursiveContainerImpl : public std::false_type {}; + +// Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to +// obey the same inconsistencies as the IsContainerTest, namely check if +// something is a container is relying on only const_iterator in C++11 and +// is relying on both const_iterator and iterator otherwise +template +struct IsRecursiveContainerImpl { + using value_type = decltype(*std::declval()); + using type = + std::is_same::type>::type, + C>; +}; + +// IsRecursiveContainer is a unary compile-time predicate that +// evaluates whether C is a recursive container type. A recursive container +// type is a container type whose value_type is equal to the container type +// itself. An example for a recursive container type is +// boost::filesystem::path, whose iterator has a value_type that is equal to +// boost::filesystem::path. +template +struct IsRecursiveContainer : public IsRecursiveContainerImpl::type {}; + +// Utilities for native arrays. + +// ArrayEq() compares two k-dimensional native arrays using the +// elements' operator==, where k can be any integer >= 0. When k is +// 0, ArrayEq() degenerates into comparing a single pair of values. + +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs); + +// This generic version is used when k is 0. +template +inline bool ArrayEq(const T& lhs, const U& rhs) { return lhs == rhs; } + +// This overload is used when k >= 1. +template +inline bool ArrayEq(const T(&lhs)[N], const U(&rhs)[N]) { + return internal::ArrayEq(lhs, N, rhs); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous ArrayEq() function, arrays with different sizes would +// lead to different copies of the template code. +template +bool ArrayEq(const T* lhs, size_t size, const U* rhs) { + for (size_t i = 0; i != size; i++) { + if (!internal::ArrayEq(lhs[i], rhs[i])) + return false; + } + return true; +} + +// Finds the first element in the iterator range [begin, end) that +// equals elem. Element may be a native array type itself. +template +Iter ArrayAwareFind(Iter begin, Iter end, const Element& elem) { + for (Iter it = begin; it != end; ++it) { + if (internal::ArrayEq(*it, elem)) + return it; + } + return end; +} + +// CopyArray() copies a k-dimensional native array using the elements' +// operator=, where k can be any integer >= 0. When k is 0, +// CopyArray() degenerates into copying a single value. + +template +void CopyArray(const T* from, size_t size, U* to); + +// This generic version is used when k is 0. +template +inline void CopyArray(const T& from, U* to) { *to = from; } + +// This overload is used when k >= 1. +template +inline void CopyArray(const T(&from)[N], U(*to)[N]) { + internal::CopyArray(from, N, *to); +} + +// This helper reduces code bloat. If we instead put its logic inside +// the previous CopyArray() function, arrays with different sizes +// would lead to different copies of the template code. +template +void CopyArray(const T* from, size_t size, U* to) { + for (size_t i = 0; i != size; i++) { + internal::CopyArray(from[i], to + i); + } +} + +// The relation between an NativeArray object (see below) and the +// native array it represents. +// We use 2 different structs to allow non-copyable types to be used, as long +// as RelationToSourceReference() is passed. +struct RelationToSourceReference {}; +struct RelationToSourceCopy {}; + +// Adapts a native array to a read-only STL-style container. Instead +// of the complete STL container concept, this adaptor only implements +// members useful for Google Mock's container matchers. New members +// should be added as needed. To simplify the implementation, we only +// support Element being a raw type (i.e. having no top-level const or +// reference modifier). It's the client's responsibility to satisfy +// this requirement. Element can be an array type itself (hence +// multi-dimensional arrays are supported). +template +class NativeArray { + public: + // STL-style container typedefs. + typedef Element value_type; + typedef Element* iterator; + typedef const Element* const_iterator; + + // Constructs from a native array. References the source. + NativeArray(const Element* array, size_t count, RelationToSourceReference) { + InitRef(array, count); + } + + // Constructs from a native array. Copies the source. + NativeArray(const Element* array, size_t count, RelationToSourceCopy) { + InitCopy(array, count); + } + + // Copy constructor. + NativeArray(const NativeArray& rhs) { + (this->*rhs.clone_)(rhs.array_, rhs.size_); + } + + ~NativeArray() { + if (clone_ != &NativeArray::InitRef) + delete[] array_; + } + + // STL-style container methods. + size_t size() const { return size_; } + const_iterator begin() const { return array_; } + const_iterator end() const { return array_ + size_; } + bool operator==(const NativeArray& rhs) const { + return size() == rhs.size() && + ArrayEq(begin(), size(), rhs.begin()); + } + + private: + static_assert(!std::is_const::value, "Type must not be const"); + static_assert(!std::is_reference::value, + "Type must not be a reference"); + + // Initializes this object with a copy of the input. + void InitCopy(const Element* array, size_t a_size) { + Element* const copy = new Element[a_size]; + CopyArray(array, a_size, copy); + array_ = copy; + size_ = a_size; + clone_ = &NativeArray::InitCopy; + } + + // Initializes this object with a reference of the input. + void InitRef(const Element* array, size_t a_size) { + array_ = array; + size_ = a_size; + clone_ = &NativeArray::InitRef; + } + + const Element* array_; + size_t size_; + void (NativeArray::*clone_)(const Element*, size_t); +}; + +// Backport of std::index_sequence. +template +struct IndexSequence { + using type = IndexSequence; +}; + +// Double the IndexSequence, and one if plus_one is true. +template +struct DoubleSequence; +template +struct DoubleSequence, sizeofT> { + using type = IndexSequence; +}; +template +struct DoubleSequence, sizeofT> { + using type = IndexSequence; +}; + +// Backport of std::make_index_sequence. +// It uses O(ln(N)) instantiation depth. +template +struct MakeIndexSequenceImpl + : DoubleSequence::type, + N / 2>::type {}; + +template <> +struct MakeIndexSequenceImpl<0> : IndexSequence<> {}; + +template +using MakeIndexSequence = typename MakeIndexSequenceImpl::type; + +template +using IndexSequenceFor = typename MakeIndexSequence::type; + +template +struct Ignore { + Ignore(...); // NOLINT +}; + +template +struct ElemFromListImpl; +template +struct ElemFromListImpl> { + // We make Ignore a template to solve a problem with MSVC. + // A non-template Ignore would work fine with `decltype(Ignore(I))...`, but + // MSVC doesn't understand how to deal with that pack expansion. + // Use `0 * I` to have a single instantiation of Ignore. + template + static R Apply(Ignore<0 * I>..., R (*)(), ...); +}; + +template +struct ElemFromList { + using type = + decltype(ElemFromListImpl::type>::Apply( + static_cast(nullptr)...)); +}; + +struct FlatTupleConstructTag {}; + +template +class FlatTuple; + +template +struct FlatTupleElemBase; + +template +struct FlatTupleElemBase, I> { + using value_type = typename ElemFromList::type; + FlatTupleElemBase() = default; + template + explicit FlatTupleElemBase(FlatTupleConstructTag, Arg&& t) + : value(std::forward(t)) {} + value_type value; +}; + +template +struct FlatTupleBase; + +template +struct FlatTupleBase, IndexSequence> + : FlatTupleElemBase, Idx>... { + using Indices = IndexSequence; + FlatTupleBase() = default; + template + explicit FlatTupleBase(FlatTupleConstructTag, Args&&... args) + : FlatTupleElemBase, Idx>(FlatTupleConstructTag{}, + std::forward(args))... {} + + template + const typename ElemFromList::type& Get() const { + return FlatTupleElemBase, I>::value; + } + + template + typename ElemFromList::type& Get() { + return FlatTupleElemBase, I>::value; + } + + template + auto Apply(F&& f) -> decltype(std::forward(f)(this->Get()...)) { + return std::forward(f)(Get()...); + } + + template + auto Apply(F&& f) const -> decltype(std::forward(f)(this->Get()...)) { + return std::forward(f)(Get()...); + } +}; + +// Analog to std::tuple but with different tradeoffs. +// This class minimizes the template instantiation depth, thus allowing more +// elements than std::tuple would. std::tuple has been seen to require an +// instantiation depth of more than 10x the number of elements in some +// implementations. +// FlatTuple and ElemFromList are not recursive and have a fixed depth +// regardless of T... +// MakeIndexSequence, on the other hand, it is recursive but with an +// instantiation depth of O(ln(N)). +template +class FlatTuple + : private FlatTupleBase, + typename MakeIndexSequence::type> { + using Indices = typename FlatTupleBase< + FlatTuple, typename MakeIndexSequence::type>::Indices; + + public: + FlatTuple() = default; + template + explicit FlatTuple(FlatTupleConstructTag tag, Args&&... args) + : FlatTuple::FlatTupleBase(tag, std::forward(args)...) {} + + using FlatTuple::FlatTupleBase::Apply; + using FlatTuple::FlatTupleBase::Get; +}; + +// Utility functions to be called with static_assert to induce deprecation +// warnings. +GTEST_INTERNAL_DEPRECATED( + "INSTANTIATE_TEST_CASE_P is deprecated, please use " + "INSTANTIATE_TEST_SUITE_P") +constexpr bool InstantiateTestCase_P_IsDeprecated() { return true; } + +GTEST_INTERNAL_DEPRECATED( + "TYPED_TEST_CASE_P is deprecated, please use " + "TYPED_TEST_SUITE_P") +constexpr bool TypedTestCase_P_IsDeprecated() { return true; } + +GTEST_INTERNAL_DEPRECATED( + "TYPED_TEST_CASE is deprecated, please use " + "TYPED_TEST_SUITE") +constexpr bool TypedTestCaseIsDeprecated() { return true; } + +GTEST_INTERNAL_DEPRECATED( + "REGISTER_TYPED_TEST_CASE_P is deprecated, please use " + "REGISTER_TYPED_TEST_SUITE_P") +constexpr bool RegisterTypedTestCase_P_IsDeprecated() { return true; } + +GTEST_INTERNAL_DEPRECATED( + "INSTANTIATE_TYPED_TEST_CASE_P is deprecated, please use " + "INSTANTIATE_TYPED_TEST_SUITE_P") +constexpr bool InstantiateTypedTestCase_P_IsDeprecated() { return true; } + +} // namespace internal +} // namespace testing + +namespace std { +// Some standard library implementations use `struct tuple_size` and some use +// `class tuple_size`. Clang warns about the mismatch. +// https://reviews.llvm.org/D55466 +#ifdef __clang__ +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wmismatched-tags" +#endif +template +struct tuple_size> + : std::integral_constant {}; +#ifdef __clang__ +#pragma clang diagnostic pop +#endif +} // namespace std + +#define GTEST_MESSAGE_AT_(file, line, message, result_type) \ + ::testing::internal::AssertHelper(result_type, file, line, message) \ + = ::testing::Message() + +#define GTEST_MESSAGE_(message, result_type) \ + GTEST_MESSAGE_AT_(__FILE__, __LINE__, message, result_type) + +#define GTEST_FATAL_FAILURE_(message) \ + return GTEST_MESSAGE_(message, ::testing::TestPartResult::kFatalFailure) + +#define GTEST_NONFATAL_FAILURE_(message) \ + GTEST_MESSAGE_(message, ::testing::TestPartResult::kNonFatalFailure) + +#define GTEST_SUCCESS_(message) \ + GTEST_MESSAGE_(message, ::testing::TestPartResult::kSuccess) + +#define GTEST_SKIP_(message) \ + return GTEST_MESSAGE_(message, ::testing::TestPartResult::kSkip) + +// Suppress MSVC warning 4072 (unreachable code) for the code following +// statement if it returns or throws (or doesn't return or throw in some +// situations). +// NOTE: The "else" is important to keep this expansion to prevent a top-level +// "else" from attaching to our "if". +#define GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) \ + if (::testing::internal::AlwaysTrue()) { \ + statement; \ + } else /* NOLINT */ \ + static_assert(true, "") // User must have a semicolon after expansion. + +#if GTEST_HAS_EXCEPTIONS + +namespace testing { +namespace internal { + +class NeverThrown { + public: + const char* what() const noexcept { + return "this exception should never be thrown"; + } +}; + +} // namespace internal +} // namespace testing + +#if GTEST_HAS_RTTI + +#define GTEST_EXCEPTION_TYPE_(e) ::testing::internal::GetTypeName(typeid(e)) + +#else // GTEST_HAS_RTTI + +#define GTEST_EXCEPTION_TYPE_(e) \ + std::string { "an std::exception-derived error" } + +#endif // GTEST_HAS_RTTI + +#define GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception) \ + catch (typename std::conditional< \ + std::is_same::type>::type, \ + std::exception>::value, \ + const ::testing::internal::NeverThrown&, const std::exception&>::type \ + e) { \ + gtest_msg.value = "Expected: " #statement \ + " throws an exception of type " #expected_exception \ + ".\n Actual: it throws "; \ + gtest_msg.value += GTEST_EXCEPTION_TYPE_(e); \ + gtest_msg.value += " with description \""; \ + gtest_msg.value += e.what(); \ + gtest_msg.value += "\"."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } + +#else // GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception) + +#endif // GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_THROW_(statement, expected_exception, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::TrueWithString gtest_msg{}) { \ + bool gtest_caught_expected = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + } \ + GTEST_TEST_THROW_CATCH_STD_EXCEPTION_(statement, expected_exception) \ + catch (...) { \ + gtest_msg.value = "Expected: " #statement \ + " throws an exception of type " #expected_exception \ + ".\n Actual: it throws a different type."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + if (!gtest_caught_expected) { \ + gtest_msg.value = "Expected: " #statement \ + " throws an exception of type " #expected_exception \ + ".\n Actual: it throws nothing."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ + } else /*NOLINT*/ \ + GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__) \ + : fail(gtest_msg.value.c_str()) + +#if GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ + catch (std::exception const& e) { \ + gtest_msg.value = "it throws "; \ + gtest_msg.value += GTEST_EXCEPTION_TYPE_(e); \ + gtest_msg.value += " with description \""; \ + gtest_msg.value += e.what(); \ + gtest_msg.value += "\"."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } + +#else // GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() + +#endif // GTEST_HAS_EXCEPTIONS + +#define GTEST_TEST_NO_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::TrueWithString gtest_msg{}) { \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + GTEST_TEST_NO_THROW_CATCH_STD_EXCEPTION_() \ + catch (...) { \ + gtest_msg.value = "it throws."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ + fail(("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: " + gtest_msg.value).c_str()) + +#define GTEST_TEST_ANY_THROW_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + bool gtest_caught_any = false; \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (...) { \ + gtest_caught_any = true; \ + } \ + if (!gtest_caught_any) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testanythrow_, __LINE__): \ + fail("Expected: " #statement " throws an exception.\n" \ + " Actual: it doesn't.") + + +// Implements Boolean test assertions such as EXPECT_TRUE. expression can be +// either a boolean expression or an AssertionResult. text is a textual +// representation of expression as it was passed into the EXPECT_TRUE. +#define GTEST_TEST_BOOLEAN_(expression, text, actual, expected, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (const ::testing::AssertionResult gtest_ar_ = \ + ::testing::AssertionResult(expression)) \ + ; \ + else \ + fail(::testing::internal::GetBoolAssertionFailureMessage(\ + gtest_ar_, text, #actual, #expected).c_str()) + +#define GTEST_TEST_NO_FATAL_FAILURE_(statement, fail) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + ::testing::internal::HasNewFatalFailureHelper gtest_fatal_failure_checker; \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + if (gtest_fatal_failure_checker.has_new_fatal_failure()) { \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__); \ + } \ + } else \ + GTEST_CONCAT_TOKEN_(gtest_label_testnofatal_, __LINE__): \ + fail("Expected: " #statement " doesn't generate new fatal " \ + "failures in the current thread.\n" \ + " Actual: it does.") + +// Expands to the name of the class that implements the given test. +#define GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + test_suite_name##_##test_name##_Test + +// Helper macro for defining tests. +#define GTEST_TEST_(test_suite_name, test_name, parent_class, parent_id) \ + static_assert(sizeof(GTEST_STRINGIFY_(test_suite_name)) > 1, \ + "test_suite_name must not be empty"); \ + static_assert(sizeof(GTEST_STRINGIFY_(test_name)) > 1, \ + "test_name must not be empty"); \ + class GTEST_TEST_CLASS_NAME_(test_suite_name, test_name) \ + : public parent_class { \ + public: \ + GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() = default; \ + ~GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)() override = default; \ + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name)); \ + GTEST_DISALLOW_MOVE_AND_ASSIGN_(GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name)); \ + \ + private: \ + void TestBody() override; \ + static ::testing::TestInfo* const test_info_ GTEST_ATTRIBUTE_UNUSED_; \ + }; \ + \ + ::testing::TestInfo* const GTEST_TEST_CLASS_NAME_(test_suite_name, \ + test_name)::test_info_ = \ + ::testing::internal::MakeAndRegisterTestInfo( \ + #test_suite_name, #test_name, nullptr, nullptr, \ + ::testing::internal::CodeLocation(__FILE__, __LINE__), (parent_id), \ + ::testing::internal::SuiteApiResolver< \ + parent_class>::GetSetUpCaseOrSuite(__FILE__, __LINE__), \ + ::testing::internal::SuiteApiResolver< \ + parent_class>::GetTearDownCaseOrSuite(__FILE__, __LINE__), \ + new ::testing::internal::TestFactoryImpl); \ + void GTEST_TEST_CLASS_NAME_(test_suite_name, test_name)::TestBody() + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_INTERNAL_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-param-util.h b/data/miniconda3/include/gtest/internal/gtest-param-util.h new file mode 100644 index 0000000000000000000000000000000000000000..c2ef6e3124b05f4be2459b62d463b2b910e5c294 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-param-util.h @@ -0,0 +1,947 @@ +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. + + +// Type and function utilities for implementing parameterized tests. + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gtest/internal/gtest-internal.h" +#include "gtest/internal/gtest-port.h" +#include "gtest/gtest-printers.h" +#include "gtest/gtest-test-part.h" + +namespace testing { +// Input to a parameterized test name generator, describing a test parameter. +// Consists of the parameter value and the integer parameter index. +template +struct TestParamInfo { + TestParamInfo(const ParamType& a_param, size_t an_index) : + param(a_param), + index(an_index) {} + ParamType param; + size_t index; +}; + +// A builtin parameterized test name generator which returns the result of +// testing::PrintToString. +struct PrintToStringParamName { + template + std::string operator()(const TestParamInfo& info) const { + return PrintToString(info.param); + } +}; + +namespace internal { + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// Utility Functions + +// Outputs a message explaining invalid registration of different +// fixture class for the same test suite. This may happen when +// TEST_P macro is used to define two tests with the same name +// but in different namespaces. +GTEST_API_ void ReportInvalidTestSuiteType(const char* test_suite_name, + CodeLocation code_location); + +template class ParamGeneratorInterface; +template class ParamGenerator; + +// Interface for iterating over elements provided by an implementation +// of ParamGeneratorInterface. +template +class ParamIteratorInterface { + public: + virtual ~ParamIteratorInterface() {} + // A pointer to the base generator instance. + // Used only for the purposes of iterator comparison + // to make sure that two iterators belong to the same generator. + virtual const ParamGeneratorInterface* BaseGenerator() const = 0; + // Advances iterator to point to the next element + // provided by the generator. The caller is responsible + // for not calling Advance() on an iterator equal to + // BaseGenerator()->End(). + virtual void Advance() = 0; + // Clones the iterator object. Used for implementing copy semantics + // of ParamIterator. + virtual ParamIteratorInterface* Clone() const = 0; + // Dereferences the current iterator and provides (read-only) access + // to the pointed value. It is the caller's responsibility not to call + // Current() on an iterator equal to BaseGenerator()->End(). + // Used for implementing ParamGenerator::operator*(). + virtual const T* Current() const = 0; + // Determines whether the given iterator and other point to the same + // element in the sequence generated by the generator. + // Used for implementing ParamGenerator::operator==(). + virtual bool Equals(const ParamIteratorInterface& other) const = 0; +}; + +// Class iterating over elements provided by an implementation of +// ParamGeneratorInterface. It wraps ParamIteratorInterface +// and implements the const forward iterator concept. +template +class ParamIterator { + public: + typedef T value_type; + typedef const T& reference; + typedef ptrdiff_t difference_type; + + // ParamIterator assumes ownership of the impl_ pointer. + ParamIterator(const ParamIterator& other) : impl_(other.impl_->Clone()) {} + ParamIterator& operator=(const ParamIterator& other) { + if (this != &other) + impl_.reset(other.impl_->Clone()); + return *this; + } + + const T& operator*() const { return *impl_->Current(); } + const T* operator->() const { return impl_->Current(); } + // Prefix version of operator++. + ParamIterator& operator++() { + impl_->Advance(); + return *this; + } + // Postfix version of operator++. + ParamIterator operator++(int /*unused*/) { + ParamIteratorInterface* clone = impl_->Clone(); + impl_->Advance(); + return ParamIterator(clone); + } + bool operator==(const ParamIterator& other) const { + return impl_.get() == other.impl_.get() || impl_->Equals(*other.impl_); + } + bool operator!=(const ParamIterator& other) const { + return !(*this == other); + } + + private: + friend class ParamGenerator; + explicit ParamIterator(ParamIteratorInterface* impl) : impl_(impl) {} + std::unique_ptr > impl_; +}; + +// ParamGeneratorInterface is the binary interface to access generators +// defined in other translation units. +template +class ParamGeneratorInterface { + public: + typedef T ParamType; + + virtual ~ParamGeneratorInterface() {} + + // Generator interface definition + virtual ParamIteratorInterface* Begin() const = 0; + virtual ParamIteratorInterface* End() const = 0; +}; + +// Wraps ParamGeneratorInterface and provides general generator syntax +// compatible with the STL Container concept. +// This class implements copy initialization semantics and the contained +// ParamGeneratorInterface instance is shared among all copies +// of the original object. This is possible because that instance is immutable. +template +class ParamGenerator { + public: + typedef ParamIterator iterator; + + explicit ParamGenerator(ParamGeneratorInterface* impl) : impl_(impl) {} + ParamGenerator(const ParamGenerator& other) : impl_(other.impl_) {} + + ParamGenerator& operator=(const ParamGenerator& other) { + impl_ = other.impl_; + return *this; + } + + iterator begin() const { return iterator(impl_->Begin()); } + iterator end() const { return iterator(impl_->End()); } + + private: + std::shared_ptr > impl_; +}; + +// Generates values from a range of two comparable values. Can be used to +// generate sequences of user-defined types that implement operator+() and +// operator<(). +// This class is used in the Range() function. +template +class RangeGenerator : public ParamGeneratorInterface { + public: + RangeGenerator(T begin, T end, IncrementT step) + : begin_(begin), end_(end), + step_(step), end_index_(CalculateEndIndex(begin, end, step)) {} + ~RangeGenerator() override {} + + ParamIteratorInterface* Begin() const override { + return new Iterator(this, begin_, 0, step_); + } + ParamIteratorInterface* End() const override { + return new Iterator(this, end_, end_index_, step_); + } + + private: + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, T value, int index, + IncrementT step) + : base_(base), value_(value), index_(index), step_(step) {} + ~Iterator() override {} + + const ParamGeneratorInterface* BaseGenerator() const override { + return base_; + } + void Advance() override { + value_ = static_cast(value_ + step_); + index_++; + } + ParamIteratorInterface* Clone() const override { + return new Iterator(*this); + } + const T* Current() const override { return &value_; } + bool Equals(const ParamIteratorInterface& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const int other_index = + CheckedDowncastToActualType(&other)->index_; + return index_ == other_index; + } + + private: + Iterator(const Iterator& other) + : ParamIteratorInterface(), + base_(other.base_), value_(other.value_), index_(other.index_), + step_(other.step_) {} + + // No implementation - assignment is unsupported. + void operator=(const Iterator& other); + + const ParamGeneratorInterface* const base_; + T value_; + int index_; + const IncrementT step_; + }; // class RangeGenerator::Iterator + + static int CalculateEndIndex(const T& begin, + const T& end, + const IncrementT& step) { + int end_index = 0; + for (T i = begin; i < end; i = static_cast(i + step)) + end_index++; + return end_index; + } + + // No implementation - assignment is unsupported. + void operator=(const RangeGenerator& other); + + const T begin_; + const T end_; + const IncrementT step_; + // The index for the end() iterator. All the elements in the generated + // sequence are indexed (0-based) to aid iterator comparison. + const int end_index_; +}; // class RangeGenerator + + +// Generates values from a pair of STL-style iterators. Used in the +// ValuesIn() function. The elements are copied from the source range +// since the source can be located on the stack, and the generator +// is likely to persist beyond that stack frame. +template +class ValuesInIteratorRangeGenerator : public ParamGeneratorInterface { + public: + template + ValuesInIteratorRangeGenerator(ForwardIterator begin, ForwardIterator end) + : container_(begin, end) {} + ~ValuesInIteratorRangeGenerator() override {} + + ParamIteratorInterface* Begin() const override { + return new Iterator(this, container_.begin()); + } + ParamIteratorInterface* End() const override { + return new Iterator(this, container_.end()); + } + + private: + typedef typename ::std::vector ContainerType; + + class Iterator : public ParamIteratorInterface { + public: + Iterator(const ParamGeneratorInterface* base, + typename ContainerType::const_iterator iterator) + : base_(base), iterator_(iterator) {} + ~Iterator() override {} + + const ParamGeneratorInterface* BaseGenerator() const override { + return base_; + } + void Advance() override { + ++iterator_; + value_.reset(); + } + ParamIteratorInterface* Clone() const override { + return new Iterator(*this); + } + // We need to use cached value referenced by iterator_ because *iterator_ + // can return a temporary object (and of type other then T), so just + // having "return &*iterator_;" doesn't work. + // value_ is updated here and not in Advance() because Advance() + // can advance iterator_ beyond the end of the range, and we cannot + // detect that fact. The client code, on the other hand, is + // responsible for not calling Current() on an out-of-range iterator. + const T* Current() const override { + if (value_.get() == nullptr) value_.reset(new T(*iterator_)); + return value_.get(); + } + bool Equals(const ParamIteratorInterface& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + return iterator_ == + CheckedDowncastToActualType(&other)->iterator_; + } + + private: + Iterator(const Iterator& other) + // The explicit constructor call suppresses a false warning + // emitted by gcc when supplied with the -Wextra option. + : ParamIteratorInterface(), + base_(other.base_), + iterator_(other.iterator_) {} + + const ParamGeneratorInterface* const base_; + typename ContainerType::const_iterator iterator_; + // A cached value of *iterator_. We keep it here to allow access by + // pointer in the wrapping iterator's operator->(). + // value_ needs to be mutable to be accessed in Current(). + // Use of std::unique_ptr helps manage cached value's lifetime, + // which is bound by the lifespan of the iterator itself. + mutable std::unique_ptr value_; + }; // class ValuesInIteratorRangeGenerator::Iterator + + // No implementation - assignment is unsupported. + void operator=(const ValuesInIteratorRangeGenerator& other); + + const ContainerType container_; +}; // class ValuesInIteratorRangeGenerator + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Default parameterized test name generator, returns a string containing the +// integer test parameter index. +template +std::string DefaultParamName(const TestParamInfo& info) { + Message name_stream; + name_stream << info.index; + return name_stream.GetString(); +} + +template +void TestNotEmpty() { + static_assert(sizeof(T) == 0, "Empty arguments are not allowed."); +} +template +void TestNotEmpty(const T&) {} + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Stores a parameter value and later creates tests parameterized with that +// value. +template +class ParameterizedTestFactory : public TestFactoryBase { + public: + typedef typename TestClass::ParamType ParamType; + explicit ParameterizedTestFactory(ParamType parameter) : + parameter_(parameter) {} + Test* CreateTest() override { + TestClass::SetParam(¶meter_); + return new TestClass(); + } + + private: + const ParamType parameter_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// TestMetaFactoryBase is a base class for meta-factories that create +// test factories for passing into MakeAndRegisterTestInfo function. +template +class TestMetaFactoryBase { + public: + virtual ~TestMetaFactoryBase() {} + + virtual TestFactoryBase* CreateTestFactory(ParamType parameter) = 0; +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// TestMetaFactory creates test factories for passing into +// MakeAndRegisterTestInfo function. Since MakeAndRegisterTestInfo receives +// ownership of test factory pointer, same factory object cannot be passed +// into that method twice. But ParameterizedTestSuiteInfo is going to call +// it for each Test/Parameter value combination. Thus it needs meta factory +// creator class. +template +class TestMetaFactory + : public TestMetaFactoryBase { + public: + using ParamType = typename TestSuite::ParamType; + + TestMetaFactory() {} + + TestFactoryBase* CreateTestFactory(ParamType parameter) override { + return new ParameterizedTestFactory(parameter); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(TestMetaFactory); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestSuiteInfoBase is a generic interface +// to ParameterizedTestSuiteInfo classes. ParameterizedTestSuiteInfoBase +// accumulates test information provided by TEST_P macro invocations +// and generators provided by INSTANTIATE_TEST_SUITE_P macro invocations +// and uses that information to register all resulting test instances +// in RegisterTests method. The ParameterizeTestSuiteRegistry class holds +// a collection of pointers to the ParameterizedTestSuiteInfo objects +// and calls RegisterTests() on each of them when asked. +class ParameterizedTestSuiteInfoBase { + public: + virtual ~ParameterizedTestSuiteInfoBase() {} + + // Base part of test suite name for display purposes. + virtual const std::string& GetTestSuiteName() const = 0; + // Test suite id to verify identity. + virtual TypeId GetTestSuiteTypeId() const = 0; + // UnitTest class invokes this method to register tests in this + // test suite right before running them in RUN_ALL_TESTS macro. + // This method should not be called more than once on any single + // instance of a ParameterizedTestSuiteInfoBase derived class. + virtual void RegisterTests() = 0; + + protected: + ParameterizedTestSuiteInfoBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfoBase); +}; + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Report a the name of a test_suit as safe to ignore +// as the side effect of construction of this type. +struct GTEST_API_ MarkAsIgnored { + explicit MarkAsIgnored(const char* test_suite); +}; + +GTEST_API_ void InsertSyntheticTestCase(const std::string& name, + CodeLocation location, bool has_test_p); + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestSuiteInfo accumulates tests obtained from TEST_P +// macro invocations for a particular test suite and generators +// obtained from INSTANTIATE_TEST_SUITE_P macro invocations for that +// test suite. It registers tests with all values generated by all +// generators when asked. +template +class ParameterizedTestSuiteInfo : public ParameterizedTestSuiteInfoBase { + public: + // ParamType and GeneratorCreationFunc are private types but are required + // for declarations of public methods AddTestPattern() and + // AddTestSuiteInstantiation(). + using ParamType = typename TestSuite::ParamType; + // A function that returns an instance of appropriate generator type. + typedef ParamGenerator(GeneratorCreationFunc)(); + using ParamNameGeneratorFunc = std::string(const TestParamInfo&); + + explicit ParameterizedTestSuiteInfo(const char* name, + CodeLocation code_location) + : test_suite_name_(name), code_location_(code_location) {} + + // Test suite base name for display purposes. + const std::string& GetTestSuiteName() const override { + return test_suite_name_; + } + // Test suite id to verify identity. + TypeId GetTestSuiteTypeId() const override { return GetTypeId(); } + // TEST_P macro uses AddTestPattern() to record information + // about a single test in a LocalTestInfo structure. + // test_suite_name is the base name of the test suite (without invocation + // prefix). test_base_name is the name of an individual test without + // parameter index. For the test SequenceA/FooTest.DoBar/1 FooTest is + // test suite base name and DoBar is test base name. + void AddTestPattern(const char* test_suite_name, const char* test_base_name, + TestMetaFactoryBase* meta_factory, + CodeLocation code_location) { + tests_.push_back(std::shared_ptr(new TestInfo( + test_suite_name, test_base_name, meta_factory, code_location))); + } + // INSTANTIATE_TEST_SUITE_P macro uses AddGenerator() to record information + // about a generator. + int AddTestSuiteInstantiation(const std::string& instantiation_name, + GeneratorCreationFunc* func, + ParamNameGeneratorFunc* name_func, + const char* file, int line) { + instantiations_.push_back( + InstantiationInfo(instantiation_name, func, name_func, file, line)); + return 0; // Return value used only to run this method in namespace scope. + } + // UnitTest class invokes this method to register tests in this test suite + // right before running tests in RUN_ALL_TESTS macro. + // This method should not be called more than once on any single + // instance of a ParameterizedTestSuiteInfoBase derived class. + // UnitTest has a guard to prevent from calling this method more than once. + void RegisterTests() override { + bool generated_instantiations = false; + + for (typename TestInfoContainer::iterator test_it = tests_.begin(); + test_it != tests_.end(); ++test_it) { + std::shared_ptr test_info = *test_it; + for (typename InstantiationContainer::iterator gen_it = + instantiations_.begin(); gen_it != instantiations_.end(); + ++gen_it) { + const std::string& instantiation_name = gen_it->name; + ParamGenerator generator((*gen_it->generator)()); + ParamNameGeneratorFunc* name_func = gen_it->name_func; + const char* file = gen_it->file; + int line = gen_it->line; + + std::string test_suite_name; + if ( !instantiation_name.empty() ) + test_suite_name = instantiation_name + "/"; + test_suite_name += test_info->test_suite_base_name; + + size_t i = 0; + std::set test_param_names; + for (typename ParamGenerator::iterator param_it = + generator.begin(); + param_it != generator.end(); ++param_it, ++i) { + generated_instantiations = true; + + Message test_name_stream; + + std::string param_name = name_func( + TestParamInfo(*param_it, i)); + + GTEST_CHECK_(IsValidParamName(param_name)) + << "Parameterized test name '" << param_name + << "' is invalid, in " << file + << " line " << line << std::endl; + + GTEST_CHECK_(test_param_names.count(param_name) == 0) + << "Duplicate parameterized test name '" << param_name + << "', in " << file << " line " << line << std::endl; + + test_param_names.insert(param_name); + + if (!test_info->test_base_name.empty()) { + test_name_stream << test_info->test_base_name << "/"; + } + test_name_stream << param_name; + MakeAndRegisterTestInfo( + test_suite_name.c_str(), test_name_stream.GetString().c_str(), + nullptr, // No type parameter. + PrintToString(*param_it).c_str(), test_info->code_location, + GetTestSuiteTypeId(), + SuiteApiResolver::GetSetUpCaseOrSuite(file, line), + SuiteApiResolver::GetTearDownCaseOrSuite(file, line), + test_info->test_meta_factory->CreateTestFactory(*param_it)); + } // for param_it + } // for gen_it + } // for test_it + + if (!generated_instantiations) { + // There are no generaotrs, or they all generate nothing ... + InsertSyntheticTestCase(GetTestSuiteName(), code_location_, + !tests_.empty()); + } + } // RegisterTests + + private: + // LocalTestInfo structure keeps information about a single test registered + // with TEST_P macro. + struct TestInfo { + TestInfo(const char* a_test_suite_base_name, const char* a_test_base_name, + TestMetaFactoryBase* a_test_meta_factory, + CodeLocation a_code_location) + : test_suite_base_name(a_test_suite_base_name), + test_base_name(a_test_base_name), + test_meta_factory(a_test_meta_factory), + code_location(a_code_location) {} + + const std::string test_suite_base_name; + const std::string test_base_name; + const std::unique_ptr > test_meta_factory; + const CodeLocation code_location; + }; + using TestInfoContainer = ::std::vector >; + // Records data received from INSTANTIATE_TEST_SUITE_P macros: + // + struct InstantiationInfo { + InstantiationInfo(const std::string &name_in, + GeneratorCreationFunc* generator_in, + ParamNameGeneratorFunc* name_func_in, + const char* file_in, + int line_in) + : name(name_in), + generator(generator_in), + name_func(name_func_in), + file(file_in), + line(line_in) {} + + std::string name; + GeneratorCreationFunc* generator; + ParamNameGeneratorFunc* name_func; + const char* file; + int line; + }; + typedef ::std::vector InstantiationContainer; + + static bool IsValidParamName(const std::string& name) { + // Check for empty string + if (name.empty()) + return false; + + // Check for invalid characters + for (std::string::size_type index = 0; index < name.size(); ++index) { + if (!IsAlNum(name[index]) && name[index] != '_') + return false; + } + + return true; + } + + const std::string test_suite_name_; + CodeLocation code_location_; + TestInfoContainer tests_; + InstantiationContainer instantiations_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteInfo); +}; // class ParameterizedTestSuiteInfo + +// Legacy API is deprecated but still available +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ +template +using ParameterizedTestCaseInfo = ParameterizedTestSuiteInfo; +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// ParameterizedTestSuiteRegistry contains a map of +// ParameterizedTestSuiteInfoBase classes accessed by test suite names. TEST_P +// and INSTANTIATE_TEST_SUITE_P macros use it to locate their corresponding +// ParameterizedTestSuiteInfo descriptors. +class ParameterizedTestSuiteRegistry { + public: + ParameterizedTestSuiteRegistry() {} + ~ParameterizedTestSuiteRegistry() { + for (auto& test_suite_info : test_suite_infos_) { + delete test_suite_info; + } + } + + // Looks up or creates and returns a structure containing information about + // tests and instantiations of a particular test suite. + template + ParameterizedTestSuiteInfo* GetTestSuitePatternHolder( + const char* test_suite_name, CodeLocation code_location) { + ParameterizedTestSuiteInfo* typed_test_info = nullptr; + for (auto& test_suite_info : test_suite_infos_) { + if (test_suite_info->GetTestSuiteName() == test_suite_name) { + if (test_suite_info->GetTestSuiteTypeId() != GetTypeId()) { + // Complain about incorrect usage of Google Test facilities + // and terminate the program since we cannot guaranty correct + // test suite setup and tear-down in this case. + ReportInvalidTestSuiteType(test_suite_name, code_location); + posix::Abort(); + } else { + // At this point we are sure that the object we found is of the same + // type we are looking for, so we downcast it to that type + // without further checks. + typed_test_info = CheckedDowncastToActualType< + ParameterizedTestSuiteInfo >(test_suite_info); + } + break; + } + } + if (typed_test_info == nullptr) { + typed_test_info = new ParameterizedTestSuiteInfo( + test_suite_name, code_location); + test_suite_infos_.push_back(typed_test_info); + } + return typed_test_info; + } + void RegisterTests() { + for (auto& test_suite_info : test_suite_infos_) { + test_suite_info->RegisterTests(); + } + } +// Legacy API is deprecated but still available +#ifndef GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + template + ParameterizedTestCaseInfo* GetTestCasePatternHolder( + const char* test_case_name, CodeLocation code_location) { + return GetTestSuitePatternHolder(test_case_name, code_location); + } + +#endif // GTEST_REMOVE_LEGACY_TEST_CASEAPI_ + + private: + using TestSuiteInfoContainer = ::std::vector; + + TestSuiteInfoContainer test_suite_infos_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestSuiteRegistry); +}; + +// Keep track of what type-parameterized test suite are defined and +// where as well as which are intatiated. This allows susequently +// identifying suits that are defined but never used. +class TypeParameterizedTestSuiteRegistry { + public: + // Add a suite definition + void RegisterTestSuite(const char* test_suite_name, + CodeLocation code_location); + + // Add an instantiation of a suit. + void RegisterInstantiation(const char* test_suite_name); + + // For each suit repored as defined but not reported as instantiation, + // emit a test that reports that fact (configurably, as an error). + void CheckForInstantiations(); + + private: + struct TypeParameterizedTestSuiteInfo { + explicit TypeParameterizedTestSuiteInfo(CodeLocation c) + : code_location(c), instantiated(false) {} + + CodeLocation code_location; + bool instantiated; + }; + + std::map suites_; +}; + +} // namespace internal + +// Forward declarations of ValuesIn(), which is implemented in +// include/gtest/gtest-param-test.h. +template +internal::ParamGenerator ValuesIn( + const Container& container); + +namespace internal { +// Used in the Values() function to provide polymorphic capabilities. + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable : 4100) +#endif + +template +class ValueArray { + public: + explicit ValueArray(Ts... v) : v_(FlatTupleConstructTag{}, std::move(v)...) {} + + template + operator ParamGenerator() const { // NOLINT + return ValuesIn(MakeVector(MakeIndexSequence())); + } + + private: + template + std::vector MakeVector(IndexSequence) const { + return std::vector{static_cast(v_.template Get())...}; + } + + FlatTuple v_; +}; + +#ifdef _MSC_VER +#pragma warning(pop) +#endif + +template +class CartesianProductGenerator + : public ParamGeneratorInterface<::std::tuple> { + public: + typedef ::std::tuple ParamType; + + CartesianProductGenerator(const std::tuple...>& g) + : generators_(g) {} + ~CartesianProductGenerator() override {} + + ParamIteratorInterface* Begin() const override { + return new Iterator(this, generators_, false); + } + ParamIteratorInterface* End() const override { + return new Iterator(this, generators_, true); + } + + private: + template + class IteratorImpl; + template + class IteratorImpl> + : public ParamIteratorInterface { + public: + IteratorImpl(const ParamGeneratorInterface* base, + const std::tuple...>& generators, bool is_end) + : base_(base), + begin_(std::get(generators).begin()...), + end_(std::get(generators).end()...), + current_(is_end ? end_ : begin_) { + ComputeCurrentValue(); + } + ~IteratorImpl() override {} + + const ParamGeneratorInterface* BaseGenerator() const override { + return base_; + } + // Advance should not be called on beyond-of-range iterators + // so no component iterators must be beyond end of range, either. + void Advance() override { + assert(!AtEnd()); + // Advance the last iterator. + ++std::get(current_); + // if that reaches end, propagate that up. + AdvanceIfEnd(); + ComputeCurrentValue(); + } + ParamIteratorInterface* Clone() const override { + return new IteratorImpl(*this); + } + + const ParamType* Current() const override { return current_value_.get(); } + + bool Equals(const ParamIteratorInterface& other) const override { + // Having the same base generator guarantees that the other + // iterator is of the same type and we can downcast. + GTEST_CHECK_(BaseGenerator() == other.BaseGenerator()) + << "The program attempted to compare iterators " + << "from different generators." << std::endl; + const IteratorImpl* typed_other = + CheckedDowncastToActualType(&other); + + // We must report iterators equal if they both point beyond their + // respective ranges. That can happen in a variety of fashions, + // so we have to consult AtEnd(). + if (AtEnd() && typed_other->AtEnd()) return true; + + bool same = true; + bool dummy[] = { + (same = same && std::get(current_) == + std::get(typed_other->current_))...}; + (void)dummy; + return same; + } + + private: + template + void AdvanceIfEnd() { + if (std::get(current_) != std::get(end_)) return; + + bool last = ThisI == 0; + if (last) { + // We are done. Nothing else to propagate. + return; + } + + constexpr size_t NextI = ThisI - (ThisI != 0); + std::get(current_) = std::get(begin_); + ++std::get(current_); + AdvanceIfEnd(); + } + + void ComputeCurrentValue() { + if (!AtEnd()) + current_value_ = std::make_shared(*std::get(current_)...); + } + bool AtEnd() const { + bool at_end = false; + bool dummy[] = { + (at_end = at_end || std::get(current_) == std::get(end_))...}; + (void)dummy; + return at_end; + } + + const ParamGeneratorInterface* const base_; + std::tuple::iterator...> begin_; + std::tuple::iterator...> end_; + std::tuple::iterator...> current_; + std::shared_ptr current_value_; + }; + + using Iterator = IteratorImpl::type>; + + std::tuple...> generators_; +}; + +template +class CartesianProductHolder { + public: + CartesianProductHolder(const Gen&... g) : generators_(g...) {} + template + operator ParamGenerator<::std::tuple>() const { + return ParamGenerator<::std::tuple>( + new CartesianProductGenerator(generators_)); + } + + private: + std::tuple generators_; +}; + +} // namespace internal +} // namespace testing + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PARAM_UTIL_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-port-arch.h b/data/miniconda3/include/gtest/internal/gtest-port-arch.h new file mode 100644 index 0000000000000000000000000000000000000000..dd845915e3ca75abe421d828c35271927e1ca810 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-port-arch.h @@ -0,0 +1,114 @@ +// Copyright 2015, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This header file defines the GTEST_OS_* macro. +// It is separate from gtest-port.h so that custom/gtest-port.h can include it. + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ + +// Determines the platform on which Google Test is compiled. +#ifdef __CYGWIN__ +# define GTEST_OS_CYGWIN 1 +# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +# define GTEST_OS_WINDOWS_MINGW 1 +# define GTEST_OS_WINDOWS 1 +#elif defined _WIN32 +# define GTEST_OS_WINDOWS 1 +# ifdef _WIN32_WCE +# define GTEST_OS_WINDOWS_MOBILE 1 +# elif defined(WINAPI_FAMILY) +# include +# if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) +# define GTEST_OS_WINDOWS_DESKTOP 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_PHONE_APP) +# define GTEST_OS_WINDOWS_PHONE 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) +# define GTEST_OS_WINDOWS_RT 1 +# elif WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_TV_TITLE) +# define GTEST_OS_WINDOWS_PHONE 1 +# define GTEST_OS_WINDOWS_TV_TITLE 1 +# else + // WINAPI_FAMILY defined but no known partition matched. + // Default to desktop. +# define GTEST_OS_WINDOWS_DESKTOP 1 +# endif +# else +# define GTEST_OS_WINDOWS_DESKTOP 1 +# endif // _WIN32_WCE +#elif defined __OS2__ +# define GTEST_OS_OS2 1 +#elif defined __APPLE__ +# define GTEST_OS_MAC 1 +# include +# if TARGET_OS_IPHONE +# define GTEST_OS_IOS 1 +# endif +#elif defined __DragonFly__ +# define GTEST_OS_DRAGONFLY 1 +#elif defined __FreeBSD__ +# define GTEST_OS_FREEBSD 1 +#elif defined __Fuchsia__ +# define GTEST_OS_FUCHSIA 1 +#elif defined(__GLIBC__) && defined(__FreeBSD_kernel__) +# define GTEST_OS_GNU_KFREEBSD 1 +#elif defined __linux__ +# define GTEST_OS_LINUX 1 +# if defined __ANDROID__ +# define GTEST_OS_LINUX_ANDROID 1 +# endif +#elif defined __MVS__ +# define GTEST_OS_ZOS 1 +#elif defined(__sun) && defined(__SVR4) +# define GTEST_OS_SOLARIS 1 +#elif defined(_AIX) +# define GTEST_OS_AIX 1 +#elif defined(__hpux) +# define GTEST_OS_HPUX 1 +#elif defined __native_client__ +# define GTEST_OS_NACL 1 +#elif defined __NetBSD__ +# define GTEST_OS_NETBSD 1 +#elif defined __OpenBSD__ +# define GTEST_OS_OPENBSD 1 +#elif defined __QNX__ +# define GTEST_OS_QNX 1 +#elif defined(__HAIKU__) +#define GTEST_OS_HAIKU 1 +#elif defined ESP8266 +#define GTEST_OS_ESP8266 1 +#elif defined ESP32 +#define GTEST_OS_ESP32 1 +#elif defined(__XTENSA__) +#define GTEST_OS_XTENSA 1 +#endif // __CYGWIN__ + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_ARCH_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-port.h b/data/miniconda3/include/gtest/internal/gtest-port.h new file mode 100644 index 0000000000000000000000000000000000000000..0953a781c05514dea7461a49dd6b6d52587e800f --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-port.h @@ -0,0 +1,2389 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// Low-level types and utilities for porting Google Test to various +// platforms. All macros ending with _ and symbols defined in an +// internal namespace are subject to change without notice. Code +// outside Google Test MUST NOT USE THEM DIRECTLY. Macros that don't +// end with _ are part of Google Test's public API and can be used by +// code outside Google Test. +// +// This file is fundamental to Google Test. All other Google Test source +// files are expected to #include this. Therefore, it cannot #include +// any other Google Test header. + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ + +// Environment-describing macros +// ----------------------------- +// +// Google Test can be used in many different environments. Macros in +// this section tell Google Test what kind of environment it is being +// used in, such that Google Test can provide environment-specific +// features and implementations. +// +// Google Test tries to automatically detect the properties of its +// environment, so users usually don't need to worry about these +// macros. However, the automatic detection is not perfect. +// Sometimes it's necessary for a user to define some of the following +// macros in the build script to override Google Test's decisions. +// +// If the user doesn't define a macro in the list, Google Test will +// provide a default definition. After this header is #included, all +// macros in this list will be defined to either 1 or 0. +// +// Notes to maintainers: +// - Each macro here is a user-tweakable knob; do not grow the list +// lightly. +// - Use #if to key off these macros. Don't use #ifdef or "#if +// defined(...)", which will not work as these macros are ALWAYS +// defined. +// +// GTEST_HAS_CLONE - Define it to 1/0 to indicate that clone(2) +// is/isn't available. +// GTEST_HAS_EXCEPTIONS - Define it to 1/0 to indicate that exceptions +// are enabled. +// GTEST_HAS_POSIX_RE - Define it to 1/0 to indicate that POSIX regular +// expressions are/aren't available. +// GTEST_HAS_PTHREAD - Define it to 1/0 to indicate that +// is/isn't available. +// GTEST_HAS_RTTI - Define it to 1/0 to indicate that RTTI is/isn't +// enabled. +// GTEST_HAS_STD_WSTRING - Define it to 1/0 to indicate that +// std::wstring does/doesn't work (Google Test can +// be used where std::wstring is unavailable). +// GTEST_HAS_SEH - Define it to 1/0 to indicate whether the +// compiler supports Microsoft's "Structured +// Exception Handling". +// GTEST_HAS_STREAM_REDIRECTION +// - Define it to 1/0 to indicate whether the +// platform supports I/O stream redirection using +// dup() and dup2(). +// GTEST_LINKED_AS_SHARED_LIBRARY +// - Define to 1 when compiling tests that use +// Google Test as a shared library (known as +// DLL on Windows). +// GTEST_CREATE_SHARED_LIBRARY +// - Define to 1 when compiling Google Test itself +// as a shared library. +// GTEST_DEFAULT_DEATH_TEST_STYLE +// - The default value of --gtest_death_test_style. +// The legacy default has been "fast" in the open +// source version since 2008. The recommended value +// is "threadsafe", and can be set in +// custom/gtest-port.h. + +// Platform-indicating macros +// -------------------------- +// +// Macros indicating the platform on which Google Test is being used +// (a macro is defined to 1 if compiled on the given platform; +// otherwise UNDEFINED -- it's never defined to 0.). Google Test +// defines these macros automatically. Code outside Google Test MUST +// NOT define them. +// +// GTEST_OS_AIX - IBM AIX +// GTEST_OS_CYGWIN - Cygwin +// GTEST_OS_DRAGONFLY - DragonFlyBSD +// GTEST_OS_FREEBSD - FreeBSD +// GTEST_OS_FUCHSIA - Fuchsia +// GTEST_OS_GNU_KFREEBSD - GNU/kFreeBSD +// GTEST_OS_HAIKU - Haiku +// GTEST_OS_HPUX - HP-UX +// GTEST_OS_LINUX - Linux +// GTEST_OS_LINUX_ANDROID - Google Android +// GTEST_OS_MAC - Mac OS X +// GTEST_OS_IOS - iOS +// GTEST_OS_NACL - Google Native Client (NaCl) +// GTEST_OS_NETBSD - NetBSD +// GTEST_OS_OPENBSD - OpenBSD +// GTEST_OS_OS2 - OS/2 +// GTEST_OS_QNX - QNX +// GTEST_OS_SOLARIS - Sun Solaris +// GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) +// GTEST_OS_WINDOWS_DESKTOP - Windows Desktop +// GTEST_OS_WINDOWS_MINGW - MinGW +// GTEST_OS_WINDOWS_MOBILE - Windows Mobile +// GTEST_OS_WINDOWS_PHONE - Windows Phone +// GTEST_OS_WINDOWS_RT - Windows Store App/WinRT +// GTEST_OS_ZOS - z/OS +// +// Among the platforms, Cygwin, Linux, Mac OS X, and Windows have the +// most stable support. Since core members of the Google Test project +// don't have access to other platforms, support for them may be less +// stable. If you notice any problems on your platform, please notify +// googletestframework@googlegroups.com (patches for fixing them are +// even more welcome!). +// +// It is possible that none of the GTEST_OS_* macros are defined. + +// Feature-indicating macros +// ------------------------- +// +// Macros indicating which Google Test features are available (a macro +// is defined to 1 if the corresponding feature is supported; +// otherwise UNDEFINED -- it's never defined to 0.). Google Test +// defines these macros automatically. Code outside Google Test MUST +// NOT define them. +// +// These macros are public so that portable tests can be written. +// Such tests typically surround code using a feature with an #if +// which controls that code. For example: +// +// #if GTEST_HAS_DEATH_TEST +// EXPECT_DEATH(DoSomethingDeadly()); +// #endif +// +// GTEST_HAS_DEATH_TEST - death tests +// GTEST_HAS_TYPED_TEST - typed tests +// GTEST_HAS_TYPED_TEST_P - type-parameterized tests +// GTEST_IS_THREADSAFE - Google Test is thread-safe. +// GOOGLETEST_CM0007 DO NOT DELETE +// GTEST_USES_POSIX_RE - enhanced POSIX regex is used. Do not confuse with +// GTEST_HAS_POSIX_RE (see above) which users can +// define themselves. +// GTEST_USES_SIMPLE_RE - our own simple regex is used; +// the above RE\b(s) are mutually exclusive. + +// Misc public macros +// ------------------ +// +// GTEST_FLAG(flag_name) - references the variable corresponding to +// the given Google Test flag. + +// Internal utilities +// ------------------ +// +// The following macros and utilities are for Google Test's INTERNAL +// use only. Code outside Google Test MUST NOT USE THEM DIRECTLY. +// +// Macros for basic C++ coding: +// GTEST_AMBIGUOUS_ELSE_BLOCKER_ - for disabling a gcc warning. +// GTEST_ATTRIBUTE_UNUSED_ - declares that a class' instances or a +// variable don't have to be used. +// GTEST_DISALLOW_ASSIGN_ - disables copy operator=. +// GTEST_DISALLOW_COPY_AND_ASSIGN_ - disables copy ctor and operator=. +// GTEST_DISALLOW_MOVE_ASSIGN_ - disables move operator=. +// GTEST_DISALLOW_MOVE_AND_ASSIGN_ - disables move ctor and operator=. +// GTEST_MUST_USE_RESULT_ - declares that a function's result must be used. +// GTEST_INTENTIONAL_CONST_COND_PUSH_ - start code section where MSVC C4127 is +// suppressed (constant conditional). +// GTEST_INTENTIONAL_CONST_COND_POP_ - finish code section where MSVC C4127 +// is suppressed. +// GTEST_INTERNAL_HAS_ANY - for enabling UniversalPrinter or +// UniversalPrinter specializations. +// GTEST_INTERNAL_HAS_OPTIONAL - for enabling UniversalPrinter +// or +// UniversalPrinter +// specializations. +// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher or +// Matcher +// specializations. +// GTEST_INTERNAL_HAS_VARIANT - for enabling UniversalPrinter or +// UniversalPrinter +// specializations. +// +// Synchronization: +// Mutex, MutexLock, ThreadLocal, GetThreadCount() +// - synchronization primitives. +// +// Regular expressions: +// RE - a simple regular expression class using the POSIX +// Extended Regular Expression syntax on UNIX-like platforms +// GOOGLETEST_CM0008 DO NOT DELETE +// or a reduced regular exception syntax on other +// platforms, including Windows. +// Logging: +// GTEST_LOG_() - logs messages at the specified severity level. +// LogToStderr() - directs all log messages to stderr. +// FlushInfoLog() - flushes informational log messages. +// +// Stdout and stderr capturing: +// CaptureStdout() - starts capturing stdout. +// GetCapturedStdout() - stops capturing stdout and returns the captured +// string. +// CaptureStderr() - starts capturing stderr. +// GetCapturedStderr() - stops capturing stderr and returns the captured +// string. +// +// Integer types: +// TypeWithSize - maps an integer to a int type. +// TimeInMillis - integers of known sizes. +// BiggestInt - the biggest signed integer type. +// +// Command-line utilities: +// GTEST_DECLARE_*() - declares a flag. +// GTEST_DEFINE_*() - defines a flag. +// GetInjectableArgvs() - returns the command line as a vector of strings. +// +// Environment variable utilities: +// GetEnv() - gets the value of an environment variable. +// BoolFromGTestEnv() - parses a bool environment variable. +// Int32FromGTestEnv() - parses an int32_t environment variable. +// StringFromGTestEnv() - parses a string environment variable. +// +// Deprecation warnings: +// GTEST_INTERNAL_DEPRECATED(message) - attribute marking a function as +// deprecated; calling a marked function +// should generate a compiler warning + +#include // for isspace, etc +#include // for ptrdiff_t +#include +#include +#include + +#include +#include +#include +#include + +#ifndef _WIN32_WCE +# include +# include +#endif // !_WIN32_WCE + +#if defined __APPLE__ +# include +# include +#endif + +#include // NOLINT +#include +#include +#include // NOLINT +#include +#include // NOLINT + +#include "gtest/internal/custom/gtest-port.h" +#include "gtest/internal/gtest-port-arch.h" + +#if !defined(GTEST_DEV_EMAIL_) +# define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com" +# define GTEST_FLAG_PREFIX_ "gtest_" +# define GTEST_FLAG_PREFIX_DASH_ "gtest-" +# define GTEST_FLAG_PREFIX_UPPER_ "GTEST_" +# define GTEST_NAME_ "Google Test" +# define GTEST_PROJECT_URL_ "https://github.com/google/googletest/" +#endif // !defined(GTEST_DEV_EMAIL_) + +#if !defined(GTEST_INIT_GOOGLE_TEST_NAME_) +# define GTEST_INIT_GOOGLE_TEST_NAME_ "testing::InitGoogleTest" +#endif // !defined(GTEST_INIT_GOOGLE_TEST_NAME_) + +// Determines the version of gcc that is used to compile this. +#ifdef __GNUC__ +// 40302 means version 4.3.2. +# define GTEST_GCC_VER_ \ + (__GNUC__*10000 + __GNUC_MINOR__*100 + __GNUC_PATCHLEVEL__) +#endif // __GNUC__ + +// Macros for disabling Microsoft Visual C++ warnings. +// +// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385) +// /* code that triggers warnings C4800 and C4385 */ +// GTEST_DISABLE_MSC_WARNINGS_POP_() +#if defined(_MSC_VER) +# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \ + __pragma(warning(push)) \ + __pragma(warning(disable: warnings)) +# define GTEST_DISABLE_MSC_WARNINGS_POP_() \ + __pragma(warning(pop)) +#else +// Not all compilers are MSVC +# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) +# define GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif + +// Clang on Windows does not understand MSVC's pragma warning. +// We need clang-specific way to disable function deprecation warning. +#ifdef __clang__ +# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ + _Pragma("clang diagnostic push") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ + _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") +#define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ + _Pragma("clang diagnostic pop") +#else +# define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) +# define GTEST_DISABLE_MSC_DEPRECATED_POP_() \ + GTEST_DISABLE_MSC_WARNINGS_POP_() +#endif + +// Brings in definitions for functions used in the testing::internal::posix +// namespace (read, write, close, chdir, isatty, stat). We do not currently +// use them on Windows Mobile. +#if GTEST_OS_WINDOWS +# if !GTEST_OS_WINDOWS_MOBILE +# include +# include +# endif +// In order to avoid having to include , use forward declaration +#if GTEST_OS_WINDOWS_MINGW && !defined(__MINGW64_VERSION_MAJOR) +// MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two +// separate (equivalent) structs, instead of using typedef +typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION; +#else +// Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION. +// This assumption is verified by +// WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION. +typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION; +#endif +#elif GTEST_OS_XTENSA +#include +// Xtensa toolchains define strcasecmp in the string.h header instead of +// strings.h. string.h is already included. +#else +// This assumes that non-Windows OSes provide unistd.h. For OSes where this +// is not the case, we need to include headers that provide the functions +// mentioned above. +# include +# include +#endif // GTEST_OS_WINDOWS + +#if GTEST_OS_LINUX_ANDROID +// Used to define __ANDROID_API__ matching the target NDK API level. +# include // NOLINT +#endif + +// Defines this to true if and only if Google Test can use POSIX regular +// expressions. +#ifndef GTEST_HAS_POSIX_RE +# if GTEST_OS_LINUX_ANDROID +// On Android, is only available starting with Gingerbread. +# define GTEST_HAS_POSIX_RE (__ANDROID_API__ >= 9) +# else +#define GTEST_HAS_POSIX_RE (!GTEST_OS_WINDOWS && !GTEST_OS_XTENSA) +# endif +#endif + +#if GTEST_USES_PCRE +// The appropriate headers have already been included. + +#elif GTEST_HAS_POSIX_RE + +// On some platforms, needs someone to define size_t, and +// won't compile otherwise. We can #include it here as we already +// included , which is guaranteed to define size_t through +// . +# include // NOLINT + +# define GTEST_USES_POSIX_RE 1 + +#elif GTEST_OS_WINDOWS + +// is not available on Windows. Use our own simple regex +// implementation instead. +# define GTEST_USES_SIMPLE_RE 1 + +#else + +// may not be available on this platform. Use our own +// simple regex implementation instead. +# define GTEST_USES_SIMPLE_RE 1 + +#endif // GTEST_USES_PCRE + +#ifndef GTEST_HAS_EXCEPTIONS +// The user didn't tell us whether exceptions are enabled, so we need +// to figure it out. +# if defined(_MSC_VER) && defined(_CPPUNWIND) +// MSVC defines _CPPUNWIND to 1 if and only if exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__BORLANDC__) +// C++Builder's implementation of the STL uses the _HAS_EXCEPTIONS +// macro to enable exceptions, so we'll do the same. +// Assumes that exceptions are enabled by default. +# ifndef _HAS_EXCEPTIONS +# define _HAS_EXCEPTIONS 1 +# endif // _HAS_EXCEPTIONS +# define GTEST_HAS_EXCEPTIONS _HAS_EXCEPTIONS +# elif defined(__clang__) +// clang defines __EXCEPTIONS if and only if exceptions are enabled before clang +// 220714, but if and only if cleanups are enabled after that. In Obj-C++ files, +// there can be cleanups for ObjC exceptions which also need cleanups, even if +// C++ exceptions are disabled. clang has __has_feature(cxx_exceptions) which +// checks for C++ exceptions starting at clang r206352, but which checked for +// cleanups prior to that. To reliably check for C++ exception availability with +// clang, check for +// __EXCEPTIONS && __has_feature(cxx_exceptions). +# define GTEST_HAS_EXCEPTIONS (__EXCEPTIONS && __has_feature(cxx_exceptions)) +# elif defined(__GNUC__) && __EXCEPTIONS +// gcc defines __EXCEPTIONS to 1 if and only if exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__SUNPRO_CC) +// Sun Pro CC supports exceptions. However, there is no compile-time way of +// detecting whether they are enabled or not. Therefore, we assume that +// they are enabled unless the user tells us otherwise. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__IBMCPP__) && __EXCEPTIONS +// xlC defines __EXCEPTIONS to 1 if and only if exceptions are enabled. +# define GTEST_HAS_EXCEPTIONS 1 +# elif defined(__HP_aCC) +// Exception handling is in effect by default in HP aCC compiler. It has to +// be turned of by +noeh compiler option if desired. +# define GTEST_HAS_EXCEPTIONS 1 +# else +// For other compilers, we assume exceptions are disabled to be +// conservative. +# define GTEST_HAS_EXCEPTIONS 0 +# endif // defined(_MSC_VER) || defined(__BORLANDC__) +#endif // GTEST_HAS_EXCEPTIONS + +#ifndef GTEST_HAS_STD_WSTRING +// The user didn't tell us whether ::std::wstring is available, so we need +// to figure it out. +// Cygwin 1.7 and below doesn't support ::std::wstring. +// Solaris' libc++ doesn't support it either. Android has +// no support for it at least as recent as Froyo (2.2). +#define GTEST_HAS_STD_WSTRING \ + (!(GTEST_OS_LINUX_ANDROID || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ + GTEST_OS_HAIKU || GTEST_OS_ESP32 || GTEST_OS_ESP8266 || GTEST_OS_XTENSA)) + +#endif // GTEST_HAS_STD_WSTRING + +// Determines whether RTTI is available. +#ifndef GTEST_HAS_RTTI +// The user didn't tell us whether RTTI is enabled, so we need to +// figure it out. + +# ifdef _MSC_VER + +#ifdef _CPPRTTI // MSVC defines this macro if and only if RTTI is enabled. +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif + +// Starting with version 4.3.2, gcc defines __GXX_RTTI if and only if RTTI is +// enabled. +# elif defined(__GNUC__) + +# ifdef __GXX_RTTI +// When building against STLport with the Android NDK and with +// -frtti -fno-exceptions, the build fails at link time with undefined +// references to __cxa_bad_typeid. Note sure if STL or toolchain bug, +// so disable RTTI when detected. +# if GTEST_OS_LINUX_ANDROID && defined(_STLPORT_MAJOR) && \ + !defined(__EXCEPTIONS) +# define GTEST_HAS_RTTI 0 +# else +# define GTEST_HAS_RTTI 1 +# endif // GTEST_OS_LINUX_ANDROID && __STLPORT_MAJOR && !__EXCEPTIONS +# else +# define GTEST_HAS_RTTI 0 +# endif // __GXX_RTTI + +// Clang defines __GXX_RTTI starting with version 3.0, but its manual recommends +// using has_feature instead. has_feature(cxx_rtti) is supported since 2.7, the +// first version with C++ support. +# elif defined(__clang__) + +# define GTEST_HAS_RTTI __has_feature(cxx_rtti) + +// Starting with version 9.0 IBM Visual Age defines __RTTI_ALL__ to 1 if +// both the typeid and dynamic_cast features are present. +# elif defined(__IBMCPP__) && (__IBMCPP__ >= 900) + +# ifdef __RTTI_ALL__ +# define GTEST_HAS_RTTI 1 +# else +# define GTEST_HAS_RTTI 0 +# endif + +# else + +// For all other compilers, we assume RTTI is enabled. +# define GTEST_HAS_RTTI 1 + +# endif // _MSC_VER + +#endif // GTEST_HAS_RTTI + +// It's this header's responsibility to #include when RTTI +// is enabled. +#if GTEST_HAS_RTTI +# include +#endif + +// Determines whether Google Test can use the pthreads library. +#ifndef GTEST_HAS_PTHREAD +// The user didn't tell us explicitly, so we make reasonable assumptions about +// which platforms have pthreads support. +// +// To disable threading support in Google Test, add -DGTEST_HAS_PTHREAD=0 +// to your compiler flags. +#define GTEST_HAS_PTHREAD \ + (GTEST_OS_LINUX || GTEST_OS_MAC || GTEST_OS_HPUX || GTEST_OS_QNX || \ + GTEST_OS_FREEBSD || GTEST_OS_NACL || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ + GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_OPENBSD || \ + GTEST_OS_HAIKU) +#endif // GTEST_HAS_PTHREAD + +#if GTEST_HAS_PTHREAD +// gtest-port.h guarantees to #include when GTEST_HAS_PTHREAD is +// true. +# include // NOLINT + +// For timespec and nanosleep, used below. +# include // NOLINT +#endif + +// Determines whether clone(2) is supported. +// Usually it will only be available on Linux, excluding +// Linux on the Itanium architecture. +// Also see http://linux.die.net/man/2/clone. +#ifndef GTEST_HAS_CLONE +// The user didn't tell us, so we need to figure it out. + +# if GTEST_OS_LINUX && !defined(__ia64__) +# if GTEST_OS_LINUX_ANDROID +// On Android, clone() became available at different API levels for each 32-bit +// architecture. +# if defined(__LP64__) || \ + (defined(__arm__) && __ANDROID_API__ >= 9) || \ + (defined(__mips__) && __ANDROID_API__ >= 12) || \ + (defined(__i386__) && __ANDROID_API__ >= 17) +# define GTEST_HAS_CLONE 1 +# else +# define GTEST_HAS_CLONE 0 +# endif +# else +# define GTEST_HAS_CLONE 1 +# endif +# else +# define GTEST_HAS_CLONE 0 +# endif // GTEST_OS_LINUX && !defined(__ia64__) + +#endif // GTEST_HAS_CLONE + +// Determines whether to support stream redirection. This is used to test +// output correctness and to implement death tests. +#ifndef GTEST_HAS_STREAM_REDIRECTION +// By default, we assume that stream redirection is supported on all +// platforms except known mobile ones. +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ + GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA +# define GTEST_HAS_STREAM_REDIRECTION 0 +# else +# define GTEST_HAS_STREAM_REDIRECTION 1 +# endif // !GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_HAS_STREAM_REDIRECTION + +// Determines whether to support death tests. +// pops up a dialog window that cannot be suppressed programmatically. +#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \ + (GTEST_OS_MAC && !GTEST_OS_IOS) || \ + (GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || GTEST_OS_WINDOWS_MINGW || \ + GTEST_OS_AIX || GTEST_OS_HPUX || GTEST_OS_OPENBSD || GTEST_OS_QNX || \ + GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_FUCHSIA || \ + GTEST_OS_DRAGONFLY || GTEST_OS_GNU_KFREEBSD || GTEST_OS_HAIKU) +# define GTEST_HAS_DEATH_TEST 1 +#endif + +// Determines whether to support type-driven tests. + +// Typed tests need and variadic macros, which GCC, VC++ 8.0, +// Sun Pro CC, IBM Visual Age, and HP aCC support. +#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \ + defined(__IBMCPP__) || defined(__HP_aCC) +# define GTEST_HAS_TYPED_TEST 1 +# define GTEST_HAS_TYPED_TEST_P 1 +#endif + +// Determines whether the system compiler uses UTF-16 for encoding wide strings. +#define GTEST_WIDE_STRING_USES_UTF16_ \ + (GTEST_OS_WINDOWS || GTEST_OS_CYGWIN || GTEST_OS_AIX || GTEST_OS_OS2) + +// Determines whether test results can be streamed to a socket. +#if GTEST_OS_LINUX || GTEST_OS_GNU_KFREEBSD || GTEST_OS_DRAGONFLY || \ + GTEST_OS_FREEBSD || GTEST_OS_NETBSD || GTEST_OS_OPENBSD +# define GTEST_CAN_STREAM_RESULTS_ 1 +#endif + +// Defines some utility macros. + +// The GNU compiler emits a warning if nested "if" statements are followed by +// an "else" statement and braces are not used to explicitly disambiguate the +// "else" binding. This leads to problems with code like: +// +// if (gate) +// ASSERT_*(condition) << "Some message"; +// +// The "switch (0) case 0:" idiom is used to suppress this. +#ifdef __INTEL_COMPILER +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ +#else +# define GTEST_AMBIGUOUS_ELSE_BLOCKER_ switch (0) case 0: default: // NOLINT +#endif + +// Use this annotation at the end of a struct/class definition to +// prevent the compiler from optimizing away instances that are never +// used. This is useful when all interesting logic happens inside the +// c'tor and / or d'tor. Example: +// +// struct Foo { +// Foo() { ... } +// } GTEST_ATTRIBUTE_UNUSED_; +// +// Also use it after a variable or parameter declaration to tell the +// compiler the variable/parameter does not have to be used. +#if defined(__GNUC__) && !defined(COMPILER_ICC) +# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) +#elif defined(__clang__) +# if __has_attribute(unused) +# define GTEST_ATTRIBUTE_UNUSED_ __attribute__ ((unused)) +# endif +#endif +#ifndef GTEST_ATTRIBUTE_UNUSED_ +# define GTEST_ATTRIBUTE_UNUSED_ +#endif + +// Use this annotation before a function that takes a printf format string. +#if (defined(__GNUC__) || defined(__clang__)) && !defined(COMPILER_ICC) +# if defined(__MINGW_PRINTF_FORMAT) +// MinGW has two different printf implementations. Ensure the format macro +// matches the selected implementation. See +// https://sourceforge.net/p/mingw-w64/wiki2/gnu%20printf/. +# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((__format__(__MINGW_PRINTF_FORMAT, string_index, \ + first_to_check))) +# else +# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) \ + __attribute__((__format__(__printf__, string_index, first_to_check))) +# endif +#else +# define GTEST_ATTRIBUTE_PRINTF_(string_index, first_to_check) +#endif + + +// A macro to disallow copy operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_ASSIGN_(type) \ + type& operator=(type const &) = delete + +// A macro to disallow copy constructor and operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type) \ + type(type const&) = delete; \ + type& operator=(type const&) = delete + +// A macro to disallow move operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_MOVE_ASSIGN_(type) \ + type& operator=(type &&) noexcept = delete + +// A macro to disallow move constructor and operator= +// This should be used in the private: declarations for a class. +#define GTEST_DISALLOW_MOVE_AND_ASSIGN_(type) \ + type(type&&) noexcept = delete; \ + type& operator=(type&&) noexcept = delete + +// Tell the compiler to warn about unused return values for functions declared +// with this macro. The macro should be used on function declarations +// following the argument list: +// +// Sprocket* AllocateSprocket() GTEST_MUST_USE_RESULT_; +#if defined(__GNUC__) && !defined(COMPILER_ICC) +# define GTEST_MUST_USE_RESULT_ __attribute__ ((warn_unused_result)) +#else +# define GTEST_MUST_USE_RESULT_ +#endif // __GNUC__ && !COMPILER_ICC + +// MS C++ compiler emits warning when a conditional expression is compile time +// constant. In some contexts this warning is false positive and needs to be +// suppressed. Use the following two macros in such cases: +// +// GTEST_INTENTIONAL_CONST_COND_PUSH_() +// while (true) { +// GTEST_INTENTIONAL_CONST_COND_POP_() +// } +# define GTEST_INTENTIONAL_CONST_COND_PUSH_() \ + GTEST_DISABLE_MSC_WARNINGS_PUSH_(4127) +# define GTEST_INTENTIONAL_CONST_COND_POP_() \ + GTEST_DISABLE_MSC_WARNINGS_POP_() + +// Determine whether the compiler supports Microsoft's Structured Exception +// Handling. This is supported by several Windows compilers but generally +// does not exist on any other system. +#ifndef GTEST_HAS_SEH +// The user didn't tell us, so we need to figure it out. + +# if defined(_MSC_VER) || defined(__BORLANDC__) +// These two compilers are known to support SEH. +# define GTEST_HAS_SEH 1 +# else +// Assume no SEH. +# define GTEST_HAS_SEH 0 +# endif + +#endif // GTEST_HAS_SEH + +#ifndef GTEST_IS_THREADSAFE + +#define GTEST_IS_THREADSAFE \ + (GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ || \ + (GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT) || \ + GTEST_HAS_PTHREAD) + +#endif // GTEST_IS_THREADSAFE + +// GTEST_API_ qualifies all symbols that must be exported. The definitions below +// are guarded by #ifndef to give embedders a chance to define GTEST_API_ in +// gtest/internal/custom/gtest-port.h +#ifndef GTEST_API_ + +#ifdef _MSC_VER +# if GTEST_LINKED_AS_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllimport) +# elif GTEST_CREATE_SHARED_LIBRARY +# define GTEST_API_ __declspec(dllexport) +# endif +#elif __GNUC__ >= 4 || defined(__clang__) +# define GTEST_API_ __attribute__((visibility ("default"))) +#endif // _MSC_VER + +#endif // GTEST_API_ + +#ifndef GTEST_API_ +# define GTEST_API_ +#endif // GTEST_API_ + +#ifndef GTEST_DEFAULT_DEATH_TEST_STYLE +# define GTEST_DEFAULT_DEATH_TEST_STYLE "fast" +#endif // GTEST_DEFAULT_DEATH_TEST_STYLE + +#ifdef __GNUC__ +// Ask the compiler to never inline a given function. +# define GTEST_NO_INLINE_ __attribute__((noinline)) +#else +# define GTEST_NO_INLINE_ +#endif + +// _LIBCPP_VERSION is defined by the libc++ library from the LLVM project. +#if !defined(GTEST_HAS_CXXABI_H_) +# if defined(__GLIBCXX__) || (defined(_LIBCPP_VERSION) && !defined(_MSC_VER)) +# define GTEST_HAS_CXXABI_H_ 1 +# else +# define GTEST_HAS_CXXABI_H_ 0 +# endif +#endif + +// A function level attribute to disable checking for use of uninitialized +// memory when built with MemorySanitizer. +#if defined(__clang__) +# if __has_feature(memory_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ \ + __attribute__((no_sanitize_memory)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +# endif // __has_feature(memory_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_MEMORY_ +#endif // __clang__ + +// A function level attribute to disable AddressSanitizer instrumentation. +#if defined(__clang__) +# if __has_feature(address_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ \ + __attribute__((no_sanitize_address)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +# endif // __has_feature(address_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_ADDRESS_ +#endif // __clang__ + +// A function level attribute to disable HWAddressSanitizer instrumentation. +#if defined(__clang__) +# if __has_feature(hwaddress_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ \ + __attribute__((no_sanitize("hwaddress"))) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ +# endif // __has_feature(hwaddress_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_HWADDRESS_ +#endif // __clang__ + +// A function level attribute to disable ThreadSanitizer instrumentation. +#if defined(__clang__) +# if __has_feature(thread_sanitizer) +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ \ + __attribute__((no_sanitize_thread)) +# else +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +# endif // __has_feature(thread_sanitizer) +#else +# define GTEST_ATTRIBUTE_NO_SANITIZE_THREAD_ +#endif // __clang__ + +namespace testing { + +class Message; + +// Legacy imports for backwards compatibility. +// New code should use std:: names directly. +using std::get; +using std::make_tuple; +using std::tuple; +using std::tuple_element; +using std::tuple_size; + +namespace internal { + +// A secret type that Google Test users don't know about. It has no +// definition on purpose. Therefore it's impossible to create a +// Secret object, which is what we want. +class Secret; + +// The GTEST_COMPILE_ASSERT_ is a legacy macro used to verify that a compile +// time expression is true (in new code, use static_assert instead). For +// example, you could use it to verify the size of a static array: +// +// GTEST_COMPILE_ASSERT_(GTEST_ARRAY_SIZE_(names) == NUM_NAMES, +// names_incorrect_size); +// +// The second argument to the macro must be a valid C++ identifier. If the +// expression is false, compiler will issue an error containing this identifier. +#define GTEST_COMPILE_ASSERT_(expr, msg) static_assert(expr, #msg) + +// A helper for suppressing warnings on constant condition. It just +// returns 'condition'. +GTEST_API_ bool IsTrue(bool condition); + +// Defines RE. + +#if GTEST_USES_PCRE +// if used, PCRE is injected by custom/gtest-port.h +#elif GTEST_USES_POSIX_RE || GTEST_USES_SIMPLE_RE + +// A simple C++ wrapper for . It uses the POSIX Extended +// Regular Expression syntax. +class GTEST_API_ RE { + public: + // A copy constructor is required by the Standard to initialize object + // references from r-values. + RE(const RE& other) { Init(other.pattern()); } + + // Constructs an RE from a string. + RE(const ::std::string& regex) { Init(regex.c_str()); } // NOLINT + + RE(const char* regex) { Init(regex); } // NOLINT + ~RE(); + + // Returns the string representation of the regex. + const char* pattern() const { return pattern_; } + + // FullMatch(str, re) returns true if and only if regular expression re + // matches the entire str. + // PartialMatch(str, re) returns true if and only if regular expression re + // matches a substring of str (including str itself). + static bool FullMatch(const ::std::string& str, const RE& re) { + return FullMatch(str.c_str(), re); + } + static bool PartialMatch(const ::std::string& str, const RE& re) { + return PartialMatch(str.c_str(), re); + } + + static bool FullMatch(const char* str, const RE& re); + static bool PartialMatch(const char* str, const RE& re); + + private: + void Init(const char* regex); + const char* pattern_; + bool is_valid_; + +# if GTEST_USES_POSIX_RE + + regex_t full_regex_; // For FullMatch(). + regex_t partial_regex_; // For PartialMatch(). + +# else // GTEST_USES_SIMPLE_RE + + const char* full_pattern_; // For FullMatch(); + +# endif +}; + +#endif // GTEST_USES_PCRE + +// Formats a source file path and a line number as they would appear +// in an error message from the compiler used to compile this code. +GTEST_API_ ::std::string FormatFileLocation(const char* file, int line); + +// Formats a file location for compiler-independent XML output. +// Although this function is not platform dependent, we put it next to +// FormatFileLocation in order to contrast the two functions. +GTEST_API_ ::std::string FormatCompilerIndependentFileLocation(const char* file, + int line); + +// Defines logging utilities: +// GTEST_LOG_(severity) - logs messages at the specified severity level. The +// message itself is streamed into the macro. +// LogToStderr() - directs all log messages to stderr. +// FlushInfoLog() - flushes informational log messages. + +enum GTestLogSeverity { + GTEST_INFO, + GTEST_WARNING, + GTEST_ERROR, + GTEST_FATAL +}; + +// Formats log entry severity, provides a stream object for streaming the +// log message, and terminates the message with a newline when going out of +// scope. +class GTEST_API_ GTestLog { + public: + GTestLog(GTestLogSeverity severity, const char* file, int line); + + // Flushes the buffers and, if severity is GTEST_FATAL, aborts the program. + ~GTestLog(); + + ::std::ostream& GetStream() { return ::std::cerr; } + + private: + const GTestLogSeverity severity_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestLog); +}; + +#if !defined(GTEST_LOG_) + +# define GTEST_LOG_(severity) \ + ::testing::internal::GTestLog(::testing::internal::GTEST_##severity, \ + __FILE__, __LINE__).GetStream() + +inline void LogToStderr() {} +inline void FlushInfoLog() { fflush(nullptr); } + +#endif // !defined(GTEST_LOG_) + +#if !defined(GTEST_CHECK_) +// INTERNAL IMPLEMENTATION - DO NOT USE. +// +// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition +// is not satisfied. +// Synopsys: +// GTEST_CHECK_(boolean_condition); +// or +// GTEST_CHECK_(boolean_condition) << "Additional message"; +// +// This checks the condition and if the condition is not satisfied +// it prints message about the condition violation, including the +// condition itself, plus additional message streamed into it, if any, +// and then it aborts the program. It aborts the program irrespective of +// whether it is built in the debug mode or not. +# define GTEST_CHECK_(condition) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::IsTrue(condition)) \ + ; \ + else \ + GTEST_LOG_(FATAL) << "Condition " #condition " failed. " +#endif // !defined(GTEST_CHECK_) + +// An all-mode assert to verify that the given POSIX-style function +// call returns 0 (indicating success). Known limitation: this +// doesn't expand to a balanced 'if' statement, so enclose the macro +// in {} if you need to use it as the only statement in an 'if' +// branch. +#define GTEST_CHECK_POSIX_SUCCESS_(posix_call) \ + if (const int gtest_error = (posix_call)) \ + GTEST_LOG_(FATAL) << #posix_call << "failed with error " \ + << gtest_error + +// Transforms "T" into "const T&" according to standard reference collapsing +// rules (this is only needed as a backport for C++98 compilers that do not +// support reference collapsing). Specifically, it transforms: +// +// char ==> const char& +// const char ==> const char& +// char& ==> char& +// const char& ==> const char& +// +// Note that the non-const reference will not have "const" added. This is +// standard, and necessary so that "T" can always bind to "const T&". +template +struct ConstRef { typedef const T& type; }; +template +struct ConstRef { typedef T& type; }; + +// The argument T must depend on some template parameters. +#define GTEST_REFERENCE_TO_CONST_(T) \ + typename ::testing::internal::ConstRef::type + +// INTERNAL IMPLEMENTATION - DO NOT USE IN USER CODE. +// +// Use ImplicitCast_ as a safe version of static_cast for upcasting in +// the type hierarchy (e.g. casting a Foo* to a SuperclassOfFoo* or a +// const Foo*). When you use ImplicitCast_, the compiler checks that +// the cast is safe. Such explicit ImplicitCast_s are necessary in +// surprisingly many situations where C++ demands an exact type match +// instead of an argument type convertable to a target type. +// +// The syntax for using ImplicitCast_ is the same as for static_cast: +// +// ImplicitCast_(expr) +// +// ImplicitCast_ would have been part of the C++ standard library, +// but the proposal was submitted too late. It will probably make +// its way into the language in the future. +// +// This relatively ugly name is intentional. It prevents clashes with +// similar functions users may have (e.g., implicit_cast). The internal +// namespace alone is not enough because the function can be found by ADL. +template +inline To ImplicitCast_(To x) { return x; } + +// When you upcast (that is, cast a pointer from type Foo to type +// SuperclassOfFoo), it's fine to use ImplicitCast_<>, since upcasts +// always succeed. When you downcast (that is, cast a pointer from +// type Foo to type SubclassOfFoo), static_cast<> isn't safe, because +// how do you know the pointer is really of type SubclassOfFoo? It +// could be a bare Foo, or of type DifferentSubclassOfFoo. Thus, +// when you downcast, you should use this macro. In debug mode, we +// use dynamic_cast<> to double-check the downcast is legal (we die +// if it's not). In normal mode, we do the efficient static_cast<> +// instead. Thus, it's important to test in debug mode to make sure +// the cast is legal! +// This is the only place in the code we should use dynamic_cast<>. +// In particular, you SHOULDN'T be using dynamic_cast<> in order to +// do RTTI (eg code like this: +// if (dynamic_cast(foo)) HandleASubclass1Object(foo); +// if (dynamic_cast(foo)) HandleASubclass2Object(foo); +// You should design the code some other way not to need this. +// +// This relatively ugly name is intentional. It prevents clashes with +// similar functions users may have (e.g., down_cast). The internal +// namespace alone is not enough because the function can be found by ADL. +template // use like this: DownCast_(foo); +inline To DownCast_(From* f) { // so we only accept pointers + // Ensures that To is a sub-type of From *. This test is here only + // for compile-time type checking, and has no overhead in an + // optimized build at run-time, as it will be optimized away + // completely. + GTEST_INTENTIONAL_CONST_COND_PUSH_() + if (false) { + GTEST_INTENTIONAL_CONST_COND_POP_() + const To to = nullptr; + ::testing::internal::ImplicitCast_(to); + } + +#if GTEST_HAS_RTTI + // RTTI: debug mode only! + GTEST_CHECK_(f == nullptr || dynamic_cast(f) != nullptr); +#endif + return static_cast(f); +} + +// Downcasts the pointer of type Base to Derived. +// Derived must be a subclass of Base. The parameter MUST +// point to a class of type Derived, not any subclass of it. +// When RTTI is available, the function performs a runtime +// check to enforce this. +template +Derived* CheckedDowncastToActualType(Base* base) { +#if GTEST_HAS_RTTI + GTEST_CHECK_(typeid(*base) == typeid(Derived)); +#endif + +#if GTEST_HAS_DOWNCAST_ + return ::down_cast(base); +#elif GTEST_HAS_RTTI + return dynamic_cast(base); // NOLINT +#else + return static_cast(base); // Poor man's downcast. +#endif +} + +#if GTEST_HAS_STREAM_REDIRECTION + +// Defines the stderr capturer: +// CaptureStdout - starts capturing stdout. +// GetCapturedStdout - stops capturing stdout and returns the captured string. +// CaptureStderr - starts capturing stderr. +// GetCapturedStderr - stops capturing stderr and returns the captured string. +// +GTEST_API_ void CaptureStdout(); +GTEST_API_ std::string GetCapturedStdout(); +GTEST_API_ void CaptureStderr(); +GTEST_API_ std::string GetCapturedStderr(); + +#endif // GTEST_HAS_STREAM_REDIRECTION +// Returns the size (in bytes) of a file. +GTEST_API_ size_t GetFileSize(FILE* file); + +// Reads the entire content of a file as a string. +GTEST_API_ std::string ReadEntireFile(FILE* file); + +// All command line arguments. +GTEST_API_ std::vector GetArgvs(); + +#if GTEST_HAS_DEATH_TEST + +std::vector GetInjectableArgvs(); +// Deprecated: pass the args vector by value instead. +void SetInjectableArgvs(const std::vector* new_argvs); +void SetInjectableArgvs(const std::vector& new_argvs); +void ClearInjectableArgvs(); + +#endif // GTEST_HAS_DEATH_TEST + +// Defines synchronization primitives. +#if GTEST_IS_THREADSAFE +# if GTEST_HAS_PTHREAD +// Sleeps for (roughly) n milliseconds. This function is only for testing +// Google Test's own constructs. Don't use it in user tests, either +// directly or indirectly. +inline void SleepMilliseconds(int n) { + const timespec time = { + 0, // 0 seconds. + n * 1000L * 1000L, // And n ms. + }; + nanosleep(&time, nullptr); +} +# endif // GTEST_HAS_PTHREAD + +# if GTEST_HAS_NOTIFICATION_ +// Notification has already been imported into the namespace. +// Nothing to do here. + +# elif GTEST_HAS_PTHREAD +// Allows a controller thread to pause execution of newly created +// threads until notified. Instances of this class must be created +// and destroyed in the controller thread. +// +// This class is only for testing Google Test's own constructs. Do not +// use it in user tests, either directly or indirectly. +class Notification { + public: + Notification() : notified_(false) { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); + } + ~Notification() { + pthread_mutex_destroy(&mutex_); + } + + // Notifies all threads created with this notification to start. Must + // be called from the controller thread. + void Notify() { + pthread_mutex_lock(&mutex_); + notified_ = true; + pthread_mutex_unlock(&mutex_); + } + + // Blocks until the controller thread notifies. Must be called from a test + // thread. + void WaitForNotification() { + for (;;) { + pthread_mutex_lock(&mutex_); + const bool notified = notified_; + pthread_mutex_unlock(&mutex_); + if (notified) + break; + SleepMilliseconds(10); + } + } + + private: + pthread_mutex_t mutex_; + bool notified_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); +}; + +# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + +GTEST_API_ void SleepMilliseconds(int n); + +// Provides leak-safe Windows kernel handle ownership. +// Used in death tests and in threading support. +class GTEST_API_ AutoHandle { + public: + // Assume that Win32 HANDLE type is equivalent to void*. Doing so allows us to + // avoid including in this header file. Including is + // undesirable because it defines a lot of symbols and macros that tend to + // conflict with client code. This assumption is verified by + // WindowsTypesTest.HANDLEIsVoidStar. + typedef void* Handle; + AutoHandle(); + explicit AutoHandle(Handle handle); + + ~AutoHandle(); + + Handle Get() const; + void Reset(); + void Reset(Handle handle); + + private: + // Returns true if and only if the handle is a valid handle object that can be + // closed. + bool IsCloseable() const; + + Handle handle_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(AutoHandle); +}; + +// Allows a controller thread to pause execution of newly created +// threads until notified. Instances of this class must be created +// and destroyed in the controller thread. +// +// This class is only for testing Google Test's own constructs. Do not +// use it in user tests, either directly or indirectly. +class GTEST_API_ Notification { + public: + Notification(); + void Notify(); + void WaitForNotification(); + + private: + AutoHandle event_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Notification); +}; +# endif // GTEST_HAS_NOTIFICATION_ + +// On MinGW, we can have both GTEST_OS_WINDOWS and GTEST_HAS_PTHREAD +// defined, but we don't want to use MinGW's pthreads implementation, which +// has conformance problems with some versions of the POSIX standard. +# if GTEST_HAS_PTHREAD && !GTEST_OS_WINDOWS_MINGW + +// As a C-function, ThreadFuncWithCLinkage cannot be templated itself. +// Consequently, it cannot select a correct instantiation of ThreadWithParam +// in order to call its Run(). Introducing ThreadWithParamBase as a +// non-templated base class for ThreadWithParam allows us to bypass this +// problem. +class ThreadWithParamBase { + public: + virtual ~ThreadWithParamBase() {} + virtual void Run() = 0; +}; + +// pthread_create() accepts a pointer to a function type with the C linkage. +// According to the Standard (7.5/1), function types with different linkages +// are different even if they are otherwise identical. Some compilers (for +// example, SunStudio) treat them as different types. Since class methods +// cannot be defined with C-linkage we need to define a free C-function to +// pass into pthread_create(). +extern "C" inline void* ThreadFuncWithCLinkage(void* thread) { + static_cast(thread)->Run(); + return nullptr; +} + +// Helper class for testing Google Test's multi-threading constructs. +// To use it, write: +// +// void ThreadFunc(int param) { /* Do things with param */ } +// Notification thread_can_start; +// ... +// // The thread_can_start parameter is optional; you can supply NULL. +// ThreadWithParam thread(&ThreadFunc, 5, &thread_can_start); +// thread_can_start.Notify(); +// +// These classes are only for testing Google Test's own constructs. Do +// not use them in user tests, either directly or indirectly. +template +class ThreadWithParam : public ThreadWithParamBase { + public: + typedef void UserThreadFunc(T); + + ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) + : func_(func), + param_(param), + thread_can_start_(thread_can_start), + finished_(false) { + ThreadWithParamBase* const base = this; + // The thread can be created only after all fields except thread_ + // have been initialized. + GTEST_CHECK_POSIX_SUCCESS_( + pthread_create(&thread_, nullptr, &ThreadFuncWithCLinkage, base)); + } + ~ThreadWithParam() override { Join(); } + + void Join() { + if (!finished_) { + GTEST_CHECK_POSIX_SUCCESS_(pthread_join(thread_, nullptr)); + finished_ = true; + } + } + + void Run() override { + if (thread_can_start_ != nullptr) thread_can_start_->WaitForNotification(); + func_(param_); + } + + private: + UserThreadFunc* const func_; // User-supplied thread function. + const T param_; // User-supplied parameter to the thread function. + // When non-NULL, used to block execution until the controller thread + // notifies. + Notification* const thread_can_start_; + bool finished_; // true if and only if we know that the thread function has + // finished. + pthread_t thread_; // The native thread object. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); +}; +# endif // !GTEST_OS_WINDOWS && GTEST_HAS_PTHREAD || + // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ + +# if GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ +// Mutex and ThreadLocal have already been imported into the namespace. +// Nothing to do here. + +# elif GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_PHONE && !GTEST_OS_WINDOWS_RT + +// Mutex implements mutex on Windows platforms. It is used in conjunction +// with class MutexLock: +// +// Mutex mutex; +// ... +// MutexLock lock(&mutex); // Acquires the mutex and releases it at the +// // end of the current scope. +// +// A static Mutex *must* be defined or declared using one of the following +// macros: +// GTEST_DEFINE_STATIC_MUTEX_(g_some_mutex); +// GTEST_DECLARE_STATIC_MUTEX_(g_some_mutex); +// +// (A non-static Mutex is defined/declared in the usual way). +class GTEST_API_ Mutex { + public: + enum MutexType { kStatic = 0, kDynamic = 1 }; + // We rely on kStaticMutex being 0 as it is to what the linker initializes + // type_ in static mutexes. critical_section_ will be initialized lazily + // in ThreadSafeLazyInit(). + enum StaticConstructorSelector { kStaticMutex = 0 }; + + // This constructor intentionally does nothing. It relies on type_ being + // statically initialized to 0 (effectively setting it to kStatic) and on + // ThreadSafeLazyInit() to lazily initialize the rest of the members. + explicit Mutex(StaticConstructorSelector /*dummy*/) {} + + Mutex(); + ~Mutex(); + + void Lock(); + + void Unlock(); + + // Does nothing if the current thread holds the mutex. Otherwise, crashes + // with high probability. + void AssertHeld(); + + private: + // Initializes owner_thread_id_ and critical_section_ in static mutexes. + void ThreadSafeLazyInit(); + + // Per https://blogs.msdn.microsoft.com/oldnewthing/20040223-00/?p=40503, + // we assume that 0 is an invalid value for thread IDs. + unsigned int owner_thread_id_; + + // For static mutexes, we rely on these members being initialized to zeros + // by the linker. + MutexType type_; + long critical_section_init_phase_; // NOLINT + GTEST_CRITICAL_SECTION* critical_section_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); +}; + +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::Mutex mutex + +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ + ::testing::internal::Mutex mutex(::testing::internal::Mutex::kStaticMutex) + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(Mutex* mutex) + : mutex_(mutex) { mutex_->Lock(); } + + ~GTestMutexLock() { mutex_->Unlock(); } + + private: + Mutex* const mutex_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); +}; + +typedef GTestMutexLock MutexLock; + +// Base class for ValueHolder. Allows a caller to hold and delete a value +// without knowing its type. +class ThreadLocalValueHolderBase { + public: + virtual ~ThreadLocalValueHolderBase() {} +}; + +// Provides a way for a thread to send notifications to a ThreadLocal +// regardless of its parameter type. +class ThreadLocalBase { + public: + // Creates a new ValueHolder object holding a default value passed to + // this ThreadLocal's constructor and returns it. It is the caller's + // responsibility not to call this when the ThreadLocal instance already + // has a value on the current thread. + virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const = 0; + + protected: + ThreadLocalBase() {} + virtual ~ThreadLocalBase() {} + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocalBase); +}; + +// Maps a thread to a set of ThreadLocals that have values instantiated on that +// thread and notifies them when the thread exits. A ThreadLocal instance is +// expected to persist until all threads it has values on have terminated. +class GTEST_API_ ThreadLocalRegistry { + public: + // Registers thread_local_instance as having value on the current thread. + // Returns a value that can be used to identify the thread from other threads. + static ThreadLocalValueHolderBase* GetValueOnCurrentThread( + const ThreadLocalBase* thread_local_instance); + + // Invoked when a ThreadLocal instance is destroyed. + static void OnThreadLocalDestroyed( + const ThreadLocalBase* thread_local_instance); +}; + +class GTEST_API_ ThreadWithParamBase { + public: + void Join(); + + protected: + class Runnable { + public: + virtual ~Runnable() {} + virtual void Run() = 0; + }; + + ThreadWithParamBase(Runnable *runnable, Notification* thread_can_start); + virtual ~ThreadWithParamBase(); + + private: + AutoHandle thread_; +}; + +// Helper class for testing Google Test's multi-threading constructs. +template +class ThreadWithParam : public ThreadWithParamBase { + public: + typedef void UserThreadFunc(T); + + ThreadWithParam(UserThreadFunc* func, T param, Notification* thread_can_start) + : ThreadWithParamBase(new RunnableImpl(func, param), thread_can_start) { + } + virtual ~ThreadWithParam() {} + + private: + class RunnableImpl : public Runnable { + public: + RunnableImpl(UserThreadFunc* func, T param) + : func_(func), + param_(param) { + } + virtual ~RunnableImpl() {} + virtual void Run() { + func_(param_); + } + + private: + UserThreadFunc* const func_; + const T param_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(RunnableImpl); + }; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadWithParam); +}; + +// Implements thread-local storage on Windows systems. +// +// // Thread 1 +// ThreadLocal tl(100); // 100 is the default value for each thread. +// +// // Thread 2 +// tl.set(150); // Changes the value for thread 2 only. +// EXPECT_EQ(150, tl.get()); +// +// // Thread 1 +// EXPECT_EQ(100, tl.get()); // In thread 1, tl has the original value. +// tl.set(200); +// EXPECT_EQ(200, tl.get()); +// +// The template type argument T must have a public copy constructor. +// In addition, the default ThreadLocal constructor requires T to have +// a public default constructor. +// +// The users of a TheadLocal instance have to make sure that all but one +// threads (including the main one) using that instance have exited before +// destroying it. Otherwise, the per-thread objects managed for them by the +// ThreadLocal instance are not guaranteed to be destroyed on all platforms. +// +// Google Test only uses global ThreadLocal objects. That means they +// will die after main() has returned. Therefore, no per-thread +// object managed by Google Test will be leaked as long as all threads +// using Google Test have exited when main() returns. +template +class ThreadLocal : public ThreadLocalBase { + public: + ThreadLocal() : default_factory_(new DefaultValueHolderFactory()) {} + explicit ThreadLocal(const T& value) + : default_factory_(new InstanceValueHolderFactory(value)) {} + + ~ThreadLocal() { ThreadLocalRegistry::OnThreadLocalDestroyed(this); } + + T* pointer() { return GetOrCreateValue(); } + const T* pointer() const { return GetOrCreateValue(); } + const T& get() const { return *pointer(); } + void set(const T& value) { *pointer() = value; } + + private: + // Holds a value of T. Can be deleted via its base class without the caller + // knowing the type of T. + class ValueHolder : public ThreadLocalValueHolderBase { + public: + ValueHolder() : value_() {} + explicit ValueHolder(const T& value) : value_(value) {} + + T* pointer() { return &value_; } + + private: + T value_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + }; + + + T* GetOrCreateValue() const { + return static_cast( + ThreadLocalRegistry::GetValueOnCurrentThread(this))->pointer(); + } + + virtual ThreadLocalValueHolderBase* NewValueForCurrentThread() const { + return default_factory_->MakeNewHolder(); + } + + class ValueHolderFactory { + public: + ValueHolderFactory() {} + virtual ~ValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const = 0; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + }; + + class DefaultValueHolderFactory : public ValueHolderFactory { + public: + DefaultValueHolderFactory() {} + ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + }; + + class InstanceValueHolderFactory : public ValueHolderFactory { + public: + explicit InstanceValueHolderFactory(const T& value) : value_(value) {} + ValueHolder* MakeNewHolder() const override { + return new ValueHolder(value_); + } + + private: + const T value_; // The value for each thread. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + }; + + std::unique_ptr default_factory_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); +}; + +# elif GTEST_HAS_PTHREAD + +// MutexBase and Mutex implement mutex on pthreads-based platforms. +class MutexBase { + public: + // Acquires this mutex. + void Lock() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_lock(&mutex_)); + owner_ = pthread_self(); + has_owner_ = true; + } + + // Releases this mutex. + void Unlock() { + // Since the lock is being released the owner_ field should no longer be + // considered valid. We don't protect writing to has_owner_ here, as it's + // the caller's responsibility to ensure that the current thread holds the + // mutex when this is called. + has_owner_ = false; + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_unlock(&mutex_)); + } + + // Does nothing if the current thread holds the mutex. Otherwise, crashes + // with high probability. + void AssertHeld() const { + GTEST_CHECK_(has_owner_ && pthread_equal(owner_, pthread_self())) + << "The current thread is not holding the mutex @" << this; + } + + // A static mutex may be used before main() is entered. It may even + // be used before the dynamic initialization stage. Therefore we + // must be able to initialize a static mutex object at link time. + // This means MutexBase has to be a POD and its member variables + // have to be public. + public: + pthread_mutex_t mutex_; // The underlying pthread mutex. + // has_owner_ indicates whether the owner_ field below contains a valid thread + // ID and is therefore safe to inspect (e.g., to use in pthread_equal()). All + // accesses to the owner_ field should be protected by a check of this field. + // An alternative might be to memset() owner_ to all zeros, but there's no + // guarantee that a zero'd pthread_t is necessarily invalid or even different + // from pthread_self(). + bool has_owner_; + pthread_t owner_; // The thread holding the mutex. +}; + +// Forward-declares a static mutex. +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::MutexBase mutex + +// Defines and statically (i.e. at link time) initializes a static mutex. +// The initialization list here does not explicitly initialize each field, +// instead relying on default initialization for the unspecified fields. In +// particular, the owner_ field (a pthread_t) is not explicitly initialized. +// This allows initialization to work whether pthread_t is a scalar or struct. +// The flag -Wmissing-field-initializers must not be specified for this to work. +#define GTEST_DEFINE_STATIC_MUTEX_(mutex) \ + ::testing::internal::MutexBase mutex = {PTHREAD_MUTEX_INITIALIZER, false, 0} + +// The Mutex class can only be used for mutexes created at runtime. It +// shares its API with MutexBase otherwise. +class Mutex : public MutexBase { + public: + Mutex() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_init(&mutex_, nullptr)); + has_owner_ = false; + } + ~Mutex() { + GTEST_CHECK_POSIX_SUCCESS_(pthread_mutex_destroy(&mutex_)); + } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(Mutex); +}; + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(MutexBase* mutex) + : mutex_(mutex) { mutex_->Lock(); } + + ~GTestMutexLock() { mutex_->Unlock(); } + + private: + MutexBase* const mutex_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(GTestMutexLock); +}; + +typedef GTestMutexLock MutexLock; + +// Helpers for ThreadLocal. + +// pthread_key_create() requires DeleteThreadLocalValue() to have +// C-linkage. Therefore it cannot be templatized to access +// ThreadLocal. Hence the need for class +// ThreadLocalValueHolderBase. +class ThreadLocalValueHolderBase { + public: + virtual ~ThreadLocalValueHolderBase() {} +}; + +// Called by pthread to delete thread-local data stored by +// pthread_setspecific(). +extern "C" inline void DeleteThreadLocalValue(void* value_holder) { + delete static_cast(value_holder); +} + +// Implements thread-local storage on pthreads-based systems. +template +class GTEST_API_ ThreadLocal { + public: + ThreadLocal() + : key_(CreateKey()), default_factory_(new DefaultValueHolderFactory()) {} + explicit ThreadLocal(const T& value) + : key_(CreateKey()), + default_factory_(new InstanceValueHolderFactory(value)) {} + + ~ThreadLocal() { + // Destroys the managed object for the current thread, if any. + DeleteThreadLocalValue(pthread_getspecific(key_)); + + // Releases resources associated with the key. This will *not* + // delete managed objects for other threads. + GTEST_CHECK_POSIX_SUCCESS_(pthread_key_delete(key_)); + } + + T* pointer() { return GetOrCreateValue(); } + const T* pointer() const { return GetOrCreateValue(); } + const T& get() const { return *pointer(); } + void set(const T& value) { *pointer() = value; } + + private: + // Holds a value of type T. + class ValueHolder : public ThreadLocalValueHolderBase { + public: + ValueHolder() : value_() {} + explicit ValueHolder(const T& value) : value_(value) {} + + T* pointer() { return &value_; } + + private: + T value_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolder); + }; + + static pthread_key_t CreateKey() { + pthread_key_t key; + // When a thread exits, DeleteThreadLocalValue() will be called on + // the object managed for that thread. + GTEST_CHECK_POSIX_SUCCESS_( + pthread_key_create(&key, &DeleteThreadLocalValue)); + return key; + } + + T* GetOrCreateValue() const { + ThreadLocalValueHolderBase* const holder = + static_cast(pthread_getspecific(key_)); + if (holder != nullptr) { + return CheckedDowncastToActualType(holder)->pointer(); + } + + ValueHolder* const new_holder = default_factory_->MakeNewHolder(); + ThreadLocalValueHolderBase* const holder_base = new_holder; + GTEST_CHECK_POSIX_SUCCESS_(pthread_setspecific(key_, holder_base)); + return new_holder->pointer(); + } + + class ValueHolderFactory { + public: + ValueHolderFactory() {} + virtual ~ValueHolderFactory() {} + virtual ValueHolder* MakeNewHolder() const = 0; + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(ValueHolderFactory); + }; + + class DefaultValueHolderFactory : public ValueHolderFactory { + public: + DefaultValueHolderFactory() {} + ValueHolder* MakeNewHolder() const override { return new ValueHolder(); } + + private: + GTEST_DISALLOW_COPY_AND_ASSIGN_(DefaultValueHolderFactory); + }; + + class InstanceValueHolderFactory : public ValueHolderFactory { + public: + explicit InstanceValueHolderFactory(const T& value) : value_(value) {} + ValueHolder* MakeNewHolder() const override { + return new ValueHolder(value_); + } + + private: + const T value_; // The value for each thread. + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InstanceValueHolderFactory); + }; + + // A key pthreads uses for looking up per-thread values. + const pthread_key_t key_; + std::unique_ptr default_factory_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(ThreadLocal); +}; + +# endif // GTEST_HAS_MUTEX_AND_THREAD_LOCAL_ + +#else // GTEST_IS_THREADSAFE + +// A dummy implementation of synchronization primitives (mutex, lock, +// and thread-local variable). Necessary for compiling Google Test where +// mutex is not supported - using Google Test in multiple threads is not +// supported on such platforms. + +class Mutex { + public: + Mutex() {} + void Lock() {} + void Unlock() {} + void AssertHeld() const {} +}; + +# define GTEST_DECLARE_STATIC_MUTEX_(mutex) \ + extern ::testing::internal::Mutex mutex + +# define GTEST_DEFINE_STATIC_MUTEX_(mutex) ::testing::internal::Mutex mutex + +// We cannot name this class MutexLock because the ctor declaration would +// conflict with a macro named MutexLock, which is defined on some +// platforms. That macro is used as a defensive measure to prevent against +// inadvertent misuses of MutexLock like "MutexLock(&mu)" rather than +// "MutexLock l(&mu)". Hence the typedef trick below. +class GTestMutexLock { + public: + explicit GTestMutexLock(Mutex*) {} // NOLINT +}; + +typedef GTestMutexLock MutexLock; + +template +class GTEST_API_ ThreadLocal { + public: + ThreadLocal() : value_() {} + explicit ThreadLocal(const T& value) : value_(value) {} + T* pointer() { return &value_; } + const T* pointer() const { return &value_; } + const T& get() const { return value_; } + void set(const T& value) { value_ = value; } + private: + T value_; +}; + +#endif // GTEST_IS_THREADSAFE + +// Returns the number of threads running in the process, or 0 to indicate that +// we cannot detect it. +GTEST_API_ size_t GetThreadCount(); + +#if GTEST_OS_WINDOWS +# define GTEST_PATH_SEP_ "\\" +# define GTEST_HAS_ALT_PATH_SEP_ 1 +#else +# define GTEST_PATH_SEP_ "/" +# define GTEST_HAS_ALT_PATH_SEP_ 0 +#endif // GTEST_OS_WINDOWS + +// Utilities for char. + +// isspace(int ch) and friends accept an unsigned char or EOF. char +// may be signed, depending on the compiler (or compiler flags). +// Therefore we need to cast a char to unsigned char before calling +// isspace(), etc. + +inline bool IsAlpha(char ch) { + return isalpha(static_cast(ch)) != 0; +} +inline bool IsAlNum(char ch) { + return isalnum(static_cast(ch)) != 0; +} +inline bool IsDigit(char ch) { + return isdigit(static_cast(ch)) != 0; +} +inline bool IsLower(char ch) { + return islower(static_cast(ch)) != 0; +} +inline bool IsSpace(char ch) { + return isspace(static_cast(ch)) != 0; +} +inline bool IsUpper(char ch) { + return isupper(static_cast(ch)) != 0; +} +inline bool IsXDigit(char ch) { + return isxdigit(static_cast(ch)) != 0; +} +#ifdef __cpp_char8_t +inline bool IsXDigit(char8_t ch) { + return isxdigit(static_cast(ch)) != 0; +} +#endif +inline bool IsXDigit(char16_t ch) { + const unsigned char low_byte = static_cast(ch); + return ch == low_byte && isxdigit(low_byte) != 0; +} +inline bool IsXDigit(char32_t ch) { + const unsigned char low_byte = static_cast(ch); + return ch == low_byte && isxdigit(low_byte) != 0; +} +inline bool IsXDigit(wchar_t ch) { + const unsigned char low_byte = static_cast(ch); + return ch == low_byte && isxdigit(low_byte) != 0; +} + +inline char ToLower(char ch) { + return static_cast(tolower(static_cast(ch))); +} +inline char ToUpper(char ch) { + return static_cast(toupper(static_cast(ch))); +} + +inline std::string StripTrailingSpaces(std::string str) { + std::string::iterator it = str.end(); + while (it != str.begin() && IsSpace(*--it)) + it = str.erase(it); + return str; +} + +// The testing::internal::posix namespace holds wrappers for common +// POSIX functions. These wrappers hide the differences between +// Windows/MSVC and POSIX systems. Since some compilers define these +// standard functions as macros, the wrapper cannot have the same name +// as the wrapped function. + +namespace posix { + +// Functions with a different name on Windows. + +#if GTEST_OS_WINDOWS + +typedef struct _stat StatStruct; + +# ifdef __BORLANDC__ +inline int DoIsATTY(int fd) { return isatty(fd); } +inline int StrCaseCmp(const char* s1, const char* s2) { + return stricmp(s1, s2); +} +inline char* StrDup(const char* src) { return strdup(src); } +# else // !__BORLANDC__ +# if GTEST_OS_WINDOWS_MOBILE +inline int DoIsATTY(int /* fd */) { return 0; } +# else +inline int DoIsATTY(int fd) { return _isatty(fd); } +# endif // GTEST_OS_WINDOWS_MOBILE +inline int StrCaseCmp(const char* s1, const char* s2) { + return _stricmp(s1, s2); +} +inline char* StrDup(const char* src) { return _strdup(src); } +# endif // __BORLANDC__ + +# if GTEST_OS_WINDOWS_MOBILE +inline int FileNo(FILE* file) { return reinterpret_cast(_fileno(file)); } +// Stat(), RmDir(), and IsDir() are not needed on Windows CE at this +// time and thus not defined there. +# else +inline int FileNo(FILE* file) { return _fileno(file); } +inline int Stat(const char* path, StatStruct* buf) { return _stat(path, buf); } +inline int RmDir(const char* dir) { return _rmdir(dir); } +inline bool IsDir(const StatStruct& st) { + return (_S_IFDIR & st.st_mode) != 0; +} +# endif // GTEST_OS_WINDOWS_MOBILE + +#elif GTEST_OS_ESP8266 +typedef struct stat StatStruct; + +inline int FileNo(FILE* file) { return fileno(file); } +inline int DoIsATTY(int fd) { return isatty(fd); } +inline int Stat(const char* path, StatStruct* buf) { + // stat function not implemented on ESP8266 + return 0; +} +inline int StrCaseCmp(const char* s1, const char* s2) { + return strcasecmp(s1, s2); +} +inline char* StrDup(const char* src) { return strdup(src); } +inline int RmDir(const char* dir) { return rmdir(dir); } +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } + +#else + +typedef struct stat StatStruct; + +inline int FileNo(FILE* file) { return fileno(file); } +inline int DoIsATTY(int fd) { return isatty(fd); } +inline int Stat(const char* path, StatStruct* buf) { return stat(path, buf); } +inline int StrCaseCmp(const char* s1, const char* s2) { + return strcasecmp(s1, s2); +} +inline char* StrDup(const char* src) { return strdup(src); } +inline int RmDir(const char* dir) { return rmdir(dir); } +inline bool IsDir(const StatStruct& st) { return S_ISDIR(st.st_mode); } + +#endif // GTEST_OS_WINDOWS + +inline int IsATTY(int fd) { + // DoIsATTY might change errno (for example ENOTTY in case you redirect stdout + // to a file on Linux), which is unexpected, so save the previous value, and + // restore it after the call. + int savedErrno = errno; + int isAttyValue = DoIsATTY(fd); + errno = savedErrno; + + return isAttyValue; +} + +// Functions deprecated by MSVC 8.0. + +GTEST_DISABLE_MSC_DEPRECATED_PUSH_() + +// ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and +// StrError() aren't needed on Windows CE at this time and thus not +// defined there. + +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_WINDOWS_PHONE && \ + !GTEST_OS_WINDOWS_RT && !GTEST_OS_ESP8266 && !GTEST_OS_XTENSA +inline int ChDir(const char* dir) { return chdir(dir); } +#endif +inline FILE* FOpen(const char* path, const char* mode) { +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW + struct wchar_codecvt : public std::codecvt {}; + std::wstring_convert converter; + std::wstring wide_path = converter.from_bytes(path); + std::wstring wide_mode = converter.from_bytes(mode); + return _wfopen(wide_path.c_str(), wide_mode.c_str()); +#else // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW + return fopen(path, mode); +#endif // GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW +} +#if !GTEST_OS_WINDOWS_MOBILE +inline FILE *FReopen(const char* path, const char* mode, FILE* stream) { + return freopen(path, mode, stream); +} +inline FILE* FDOpen(int fd, const char* mode) { return fdopen(fd, mode); } +#endif +inline int FClose(FILE* fp) { return fclose(fp); } +#if !GTEST_OS_WINDOWS_MOBILE +inline int Read(int fd, void* buf, unsigned int count) { + return static_cast(read(fd, buf, count)); +} +inline int Write(int fd, const void* buf, unsigned int count) { + return static_cast(write(fd, buf, count)); +} +inline int Close(int fd) { return close(fd); } +inline const char* StrError(int errnum) { return strerror(errnum); } +#endif +inline const char* GetEnv(const char* name) { +#if GTEST_OS_WINDOWS_MOBILE || GTEST_OS_WINDOWS_PHONE || \ + GTEST_OS_WINDOWS_RT || GTEST_OS_ESP8266 || GTEST_OS_XTENSA + // We are on an embedded platform, which has no environment variables. + static_cast(name); // To prevent 'unused argument' warning. + return nullptr; +#elif defined(__BORLANDC__) || defined(__SunOS_5_8) || defined(__SunOS_5_9) + // Environment variables which we programmatically clear will be set to the + // empty string rather than unset (NULL). Handle that case. + const char* const env = getenv(name); + return (env != nullptr && env[0] != '\0') ? env : nullptr; +#else + return getenv(name); +#endif +} + +GTEST_DISABLE_MSC_DEPRECATED_POP_() + +#if GTEST_OS_WINDOWS_MOBILE +// Windows CE has no C library. The abort() function is used in +// several places in Google Test. This implementation provides a reasonable +// imitation of standard behaviour. +[[noreturn]] void Abort(); +#else +[[noreturn]] inline void Abort() { abort(); } +#endif // GTEST_OS_WINDOWS_MOBILE + +} // namespace posix + +// MSVC "deprecates" snprintf and issues warnings wherever it is used. In +// order to avoid these warnings, we need to use _snprintf or _snprintf_s on +// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate +// function in order to achieve that. We use macro definition here because +// snprintf is a variadic function. +#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE +// MSVC 2005 and above support variadic macros. +# define GTEST_SNPRINTF_(buffer, size, format, ...) \ + _snprintf_s(buffer, size, size, format, __VA_ARGS__) +#elif defined(_MSC_VER) +// Windows CE does not define _snprintf_s +# define GTEST_SNPRINTF_ _snprintf +#else +# define GTEST_SNPRINTF_ snprintf +#endif + +// The biggest signed integer type the compiler supports. +// +// long long is guaranteed to be at least 64-bits in C++11. +using BiggestInt = long long; // NOLINT + +// The maximum number a BiggestInt can represent. +constexpr BiggestInt kMaxBiggestInt = (std::numeric_limits::max)(); + +// This template class serves as a compile-time function from size to +// type. It maps a size in bytes to a primitive type with that +// size. e.g. +// +// TypeWithSize<4>::UInt +// +// is typedef-ed to be unsigned int (unsigned integer made up of 4 +// bytes). +// +// Such functionality should belong to STL, but I cannot find it +// there. +// +// Google Test uses this class in the implementation of floating-point +// comparison. +// +// For now it only handles UInt (unsigned int) as that's all Google Test +// needs. Other types can be easily added in the future if need +// arises. +template +class TypeWithSize { + public: + // This prevents the user from using TypeWithSize with incorrect + // values of N. + using UInt = void; +}; + +// The specialization for size 4. +template <> +class TypeWithSize<4> { + public: + using Int = std::int32_t; + using UInt = std::uint32_t; +}; + +// The specialization for size 8. +template <> +class TypeWithSize<8> { + public: + using Int = std::int64_t; + using UInt = std::uint64_t; +}; + +// Integer types of known sizes. +using TimeInMillis = int64_t; // Represents time in milliseconds. + +// Utilities for command line flags and environment variables. + +// Macro for referencing flags. +#if !defined(GTEST_FLAG) +# define GTEST_FLAG(name) FLAGS_gtest_##name +#endif // !defined(GTEST_FLAG) + +#if !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) +# define GTEST_USE_OWN_FLAGFILE_FLAG_ 1 +#endif // !defined(GTEST_USE_OWN_FLAGFILE_FLAG_) + +#if !defined(GTEST_DECLARE_bool_) +# define GTEST_FLAG_SAVER_ ::testing::internal::GTestFlagSaver + +// Macros for declaring flags. +# define GTEST_DECLARE_bool_(name) GTEST_API_ extern bool GTEST_FLAG(name) +# define GTEST_DECLARE_int32_(name) \ + GTEST_API_ extern std::int32_t GTEST_FLAG(name) +# define GTEST_DECLARE_string_(name) \ + GTEST_API_ extern ::std::string GTEST_FLAG(name) + +// Macros for defining flags. +# define GTEST_DEFINE_bool_(name, default_val, doc) \ + GTEST_API_ bool GTEST_FLAG(name) = (default_val) +# define GTEST_DEFINE_int32_(name, default_val, doc) \ + GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val) +# define GTEST_DEFINE_string_(name, default_val, doc) \ + GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val) + +#endif // !defined(GTEST_DECLARE_bool_) + +// Thread annotations +#if !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) +# define GTEST_EXCLUSIVE_LOCK_REQUIRED_(locks) +# define GTEST_LOCK_EXCLUDED_(locks) +#endif // !defined(GTEST_EXCLUSIVE_LOCK_REQUIRED_) + +// Parses 'str' for a 32-bit signed integer. If successful, writes the result +// to *value and returns true; otherwise leaves *value unchanged and returns +// false. +GTEST_API_ bool ParseInt32(const Message& src_text, const char* str, + int32_t* value); + +// Parses a bool/int32_t/string from the environment variable +// corresponding to the given Google Test flag. +bool BoolFromGTestEnv(const char* flag, bool default_val); +GTEST_API_ int32_t Int32FromGTestEnv(const char* flag, int32_t default_val); +std::string OutputFlagAlsoCheckEnvVar(); +const char* StringFromGTestEnv(const char* flag, const char* default_val); + +} // namespace internal +} // namespace testing + +#if !defined(GTEST_INTERNAL_DEPRECATED) + +// Internal Macro to mark an API deprecated, for googletest usage only +// Usage: class GTEST_INTERNAL_DEPRECATED(message) MyClass or +// GTEST_INTERNAL_DEPRECATED(message) myFunction(); Every usage of +// a deprecated entity will trigger a warning when compiled with +// `-Wdeprecated-declarations` option (clang, gcc, any __GNUC__ compiler). +// For msvc /W3 option will need to be used +// Note that for 'other' compilers this macro evaluates to nothing to prevent +// compilations errors. +#if defined(_MSC_VER) +#define GTEST_INTERNAL_DEPRECATED(message) __declspec(deprecated(message)) +#elif defined(__GNUC__) +#define GTEST_INTERNAL_DEPRECATED(message) __attribute__((deprecated(message))) +#else +#define GTEST_INTERNAL_DEPRECATED(message) +#endif + +#endif // !defined(GTEST_INTERNAL_DEPRECATED) + +#if GTEST_HAS_ABSL +// Always use absl::any for UniversalPrinter<> specializations if googletest +// is built with absl support. +#define GTEST_INTERNAL_HAS_ANY 1 +#include "absl/types/any.h" +namespace testing { +namespace internal { +using Any = ::absl::any; +} // namespace internal +} // namespace testing +#else +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +// Otherwise for C++17 and higher use std::any for UniversalPrinter<> +// specializations. +#define GTEST_INTERNAL_HAS_ANY 1 +#include +namespace testing { +namespace internal { +using Any = ::std::any; +} // namespace internal +} // namespace testing +// The case where absl is configured NOT to alias std::any is not +// supported. +#endif // __has_include() && __cplusplus >= 201703L +#endif // __has_include +#endif // GTEST_HAS_ABSL + +#if GTEST_HAS_ABSL +// Always use absl::optional for UniversalPrinter<> specializations if +// googletest is built with absl support. +#define GTEST_INTERNAL_HAS_OPTIONAL 1 +#include "absl/types/optional.h" +namespace testing { +namespace internal { +template +using Optional = ::absl::optional; +} // namespace internal +} // namespace testing +#else +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +// Otherwise for C++17 and higher use std::optional for UniversalPrinter<> +// specializations. +#define GTEST_INTERNAL_HAS_OPTIONAL 1 +#include +namespace testing { +namespace internal { +template +using Optional = ::std::optional; +} // namespace internal +} // namespace testing +// The case where absl is configured NOT to alias std::optional is not +// supported. +#endif // __has_include() && __cplusplus >= 201703L +#endif // __has_include +#endif // GTEST_HAS_ABSL + +#if GTEST_HAS_ABSL +// Always use absl::string_view for Matcher<> specializations if googletest +// is built with absl support. +# define GTEST_INTERNAL_HAS_STRING_VIEW 1 +#include "absl/strings/string_view.h" +namespace testing { +namespace internal { +using StringView = ::absl::string_view; +} // namespace internal +} // namespace testing +#else +# ifdef __has_include +# if __has_include() && __cplusplus >= 201703L +// Otherwise for C++17 and higher use std::string_view for Matcher<> +// specializations. +# define GTEST_INTERNAL_HAS_STRING_VIEW 1 +#include +namespace testing { +namespace internal { +using StringView = ::std::string_view; +} // namespace internal +} // namespace testing +// The case where absl is configured NOT to alias std::string_view is not +// supported. +# endif // __has_include() && __cplusplus >= 201703L +# endif // __has_include +#endif // GTEST_HAS_ABSL + +#if GTEST_HAS_ABSL +// Always use absl::variant for UniversalPrinter<> specializations if googletest +// is built with absl support. +#define GTEST_INTERNAL_HAS_VARIANT 1 +#include "absl/types/variant.h" +namespace testing { +namespace internal { +template +using Variant = ::absl::variant; +} // namespace internal +} // namespace testing +#else +#ifdef __has_include +#if __has_include() && __cplusplus >= 201703L +// Otherwise for C++17 and higher use std::variant for UniversalPrinter<> +// specializations. +#define GTEST_INTERNAL_HAS_VARIANT 1 +#include +namespace testing { +namespace internal { +template +using Variant = ::std::variant; +} // namespace internal +} // namespace testing +// The case where absl is configured NOT to alias std::variant is not supported. +#endif // __has_include() && __cplusplus >= 201703L +#endif // __has_include +#endif // GTEST_HAS_ABSL + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_PORT_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-string.h b/data/miniconda3/include/gtest/internal/gtest-string.h new file mode 100644 index 0000000000000000000000000000000000000000..10f774f96606e5b9b87ba34ec7c52ba475ad85c5 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-string.h @@ -0,0 +1,175 @@ +// Copyright 2005, Google Inc. +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. +// +// The Google C++ Testing and Mocking Framework (Google Test) +// +// This header file declares the String class and functions used internally by +// Google Test. They are subject to change without notice. They should not used +// by code external to Google Test. +// +// This header file is #included by gtest-internal.h. +// It should not be #included by other files. + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ + +#ifdef __BORLANDC__ +// string.h is not guaranteed to provide strcpy on C++ Builder. +# include +#endif + +#include +#include +#include + +#include "gtest/internal/gtest-port.h" + +namespace testing { +namespace internal { + +// String - an abstract class holding static string utilities. +class GTEST_API_ String { + public: + // Static utility methods + + // Clones a 0-terminated C string, allocating memory using new. The + // caller is responsible for deleting the return value using + // delete[]. Returns the cloned string, or NULL if the input is + // NULL. + // + // This is different from strdup() in string.h, which allocates + // memory using malloc(). + static const char* CloneCString(const char* c_str); + +#if GTEST_OS_WINDOWS_MOBILE + // Windows CE does not have the 'ANSI' versions of Win32 APIs. To be + // able to pass strings to Win32 APIs on CE we need to convert them + // to 'Unicode', UTF-16. + + // Creates a UTF-16 wide string from the given ANSI string, allocating + // memory using new. The caller is responsible for deleting the return + // value using delete[]. Returns the wide string, or NULL if the + // input is NULL. + // + // The wide string is created using the ANSI codepage (CP_ACP) to + // match the behaviour of the ANSI versions of Win32 calls and the + // C runtime. + static LPCWSTR AnsiToUtf16(const char* c_str); + + // Creates an ANSI string from the given wide string, allocating + // memory using new. The caller is responsible for deleting the return + // value using delete[]. Returns the ANSI string, or NULL if the + // input is NULL. + // + // The returned string is created using the ANSI codepage (CP_ACP) to + // match the behaviour of the ANSI versions of Win32 calls and the + // C runtime. + static const char* Utf16ToAnsi(LPCWSTR utf16_str); +#endif + + // Compares two C strings. Returns true if and only if they have the same + // content. + // + // Unlike strcmp(), this function can handle NULL argument(s). A + // NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool CStringEquals(const char* lhs, const char* rhs); + + // Converts a wide C string to a String using the UTF-8 encoding. + // NULL will be converted to "(null)". If an error occurred during + // the conversion, "(failed to convert from wide string)" is + // returned. + static std::string ShowWideCString(const wchar_t* wide_c_str); + + // Compares two wide C strings. Returns true if and only if they have the + // same content. + // + // Unlike wcscmp(), this function can handle NULL argument(s). A + // NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool WideCStringEquals(const wchar_t* lhs, const wchar_t* rhs); + + // Compares two C strings, ignoring case. Returns true if and only if + // they have the same content. + // + // Unlike strcasecmp(), this function can handle NULL argument(s). + // A NULL C string is considered different to any non-NULL C string, + // including the empty string. + static bool CaseInsensitiveCStringEquals(const char* lhs, + const char* rhs); + + // Compares two wide C strings, ignoring case. Returns true if and only if + // they have the same content. + // + // Unlike wcscasecmp(), this function can handle NULL argument(s). + // A NULL C string is considered different to any non-NULL wide C string, + // including the empty string. + // NB: The implementations on different platforms slightly differ. + // On windows, this method uses _wcsicmp which compares according to LC_CTYPE + // environment variable. On GNU platform this method uses wcscasecmp + // which compares according to LC_CTYPE category of the current locale. + // On MacOS X, it uses towlower, which also uses LC_CTYPE category of the + // current locale. + static bool CaseInsensitiveWideCStringEquals(const wchar_t* lhs, + const wchar_t* rhs); + + // Returns true if and only if the given string ends with the given suffix, + // ignoring case. Any string is considered to end with an empty suffix. + static bool EndsWithCaseInsensitive( + const std::string& str, const std::string& suffix); + + // Formats an int value as "%02d". + static std::string FormatIntWidth2(int value); // "%02d" for width == 2 + + // Formats an int value to given width with leading zeros. + static std::string FormatIntWidthN(int value, int width); + + // Formats an int value as "%X". + static std::string FormatHexInt(int value); + + // Formats an int value as "%X". + static std::string FormatHexUInt32(uint32_t value); + + // Formats a byte as "%02X". + static std::string FormatByte(unsigned char value); + + private: + String(); // Not meant to be instantiated. +}; // class String + +// Gets the content of the stringstream's buffer as an std::string. Each '\0' +// character in the buffer is replaced with "\\0". +GTEST_API_ std::string StringStreamToString(::std::stringstream* stream); + +} // namespace internal +} // namespace testing + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_STRING_H_ diff --git a/data/miniconda3/include/gtest/internal/gtest-type-util.h b/data/miniconda3/include/gtest/internal/gtest-type-util.h new file mode 100644 index 0000000000000000000000000000000000000000..b87a2e2cace33b8cf1d42a2b3bdb44cbb90dc267 --- /dev/null +++ b/data/miniconda3/include/gtest/internal/gtest-type-util.h @@ -0,0 +1,183 @@ +// Copyright 2008 Google Inc. +// All Rights Reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * 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. +// * Neither the name of Google Inc. 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 THE COPYRIGHT HOLDERS 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 THE COPYRIGHT +// OWNER 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. + +// Type utilities needed for implementing typed and type-parameterized +// tests. + +// GOOGLETEST_CM0001 DO NOT DELETE + +#ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ +#define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ + +#include "gtest/internal/gtest-port.h" + +// #ifdef __GNUC__ is too general here. It is possible to use gcc without using +// libstdc++ (which is where cxxabi.h comes from). +# if GTEST_HAS_CXXABI_H_ +# include +# elif defined(__HP_aCC) +# include +# endif // GTEST_HASH_CXXABI_H_ + +namespace testing { +namespace internal { + +// Canonicalizes a given name with respect to the Standard C++ Library. +// This handles removing the inline namespace within `std` that is +// used by various standard libraries (e.g., `std::__1`). Names outside +// of namespace std are returned unmodified. +inline std::string CanonicalizeForStdLibVersioning(std::string s) { + static const char prefix[] = "std::__"; + if (s.compare(0, strlen(prefix), prefix) == 0) { + std::string::size_type end = s.find("::", strlen(prefix)); + if (end != s.npos) { + // Erase everything between the initial `std` and the second `::`. + s.erase(strlen("std"), end - strlen("std")); + } + } + return s; +} + +#if GTEST_HAS_RTTI +// GetTypeName(const std::type_info&) returns a human-readable name of type T. +inline std::string GetTypeName(const std::type_info& type) { + const char* const name = type.name(); +#if GTEST_HAS_CXXABI_H_ || defined(__HP_aCC) + int status = 0; + // gcc's implementation of typeid(T).name() mangles the type name, + // so we have to demangle it. +#if GTEST_HAS_CXXABI_H_ + using abi::__cxa_demangle; +#endif // GTEST_HAS_CXXABI_H_ + char* const readable_name = __cxa_demangle(name, nullptr, nullptr, &status); + const std::string name_str(status == 0 ? readable_name : name); + free(readable_name); + return CanonicalizeForStdLibVersioning(name_str); +#else + return name; +#endif // GTEST_HAS_CXXABI_H_ || __HP_aCC +} +#endif // GTEST_HAS_RTTI + +// GetTypeName() returns a human-readable name of type T if and only if +// RTTI is enabled, otherwise it returns a dummy type name. +// NB: This function is also used in Google Mock, so don't move it inside of +// the typed-test-only section below. +template +std::string GetTypeName() { +#if GTEST_HAS_RTTI + return GetTypeName(typeid(T)); +#else + return ""; +#endif // GTEST_HAS_RTTI +} + +// A unique type indicating an empty node +struct None {}; + +# define GTEST_TEMPLATE_ template class + +// The template "selector" struct TemplateSel is used to +// represent Tmpl, which must be a class template with one type +// parameter, as a type. TemplateSel::Bind::type is defined +// as the type Tmpl. This allows us to actually instantiate the +// template "selected" by TemplateSel. +// +// This trick is necessary for simulating typedef for class templates, +// which C++ doesn't support directly. +template +struct TemplateSel { + template + struct Bind { + typedef Tmpl type; + }; +}; + +# define GTEST_BIND_(TmplSel, T) \ + TmplSel::template Bind::type + +template +struct Templates { + using Head = TemplateSel; + using Tail = Templates; +}; + +template +struct Templates { + using Head = TemplateSel; + using Tail = None; +}; + +// Tuple-like type lists +template +struct Types { + using Head = Head_; + using Tail = Types; +}; + +template +struct Types { + using Head = Head_; + using Tail = None; +}; + +// Helper metafunctions to tell apart a single type from types +// generated by ::testing::Types +template +struct ProxyTypeList { + using type = Types; +}; + +template +struct is_proxy_type_list : std::false_type {}; + +template +struct is_proxy_type_list> : std::true_type {}; + +// Generator which conditionally creates type lists. +// It recognizes if a requested type list should be created +// and prevents creating a new type list nested within another one. +template +struct GenerateTypeList { + private: + using proxy = typename std::conditional::value, T, + ProxyTypeList>::type; + + public: + using type = typename proxy::type; +}; + +} // namespace internal + +template +using Types = internal::ProxyTypeList; + +} // namespace testing + +#endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_TYPE_UTIL_H_ diff --git a/data/miniconda3/include/mamba/core/activation.hpp b/data/miniconda3/include/mamba/core/activation.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e2ad98ab20b76557228c7e86e00e381108006ba1 --- /dev/null +++ b/data/miniconda3/include/mamba/core/activation.hpp @@ -0,0 +1,263 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_ACTIVATION_HPP +#define MAMBA_CORE_ACTIVATION_HPP + +#include +#include +#include +#include + +#include "mamba/fs/filesystem.hpp" + +// TODO write a map that keeps insertion order + +namespace mamba +{ + class Context; + + enum class ActivationType + { + ACTIVATE, + DEACTIVATE, + REACTIVATE + }; + + struct EnvironmentTransform + { + std::string export_path; + std::vector unset_vars; + std::vector> set_vars; + std::vector> export_vars; + std::vector activate_scripts; + std::vector deactivate_scripts; + }; + + class Activator + { + public: + + virtual ~Activator() = default; + + Activator(const Activator&) = delete; + Activator& operator=(const Activator&) = delete; + Activator(Activator&&) = delete; + Activator& operator=(Activator&&) = delete; + + virtual std::string script(const EnvironmentTransform& env) = 0; + virtual std::pair + update_prompt(const std::string& conda_prompt_modifier) = 0; + virtual std::string shell_extension() = 0; + virtual std::string shell() = 0; + + std::vector get_activate_scripts(const fs::u8path& prefix); + std::vector get_deactivate_scripts(const fs::u8path& prefix); + + std::string get_default_env(const fs::u8path& prefix); + std::vector> + get_environment_vars(const fs::u8path& prefix); + + std::string get_prompt_modifier( + const fs::u8path& prefix, + const std::string& conda_default_env, + int old_conda_shlvl + ); + + std::vector get_PATH(); + + std::string add_prefix_to_path(const fs::u8path& prefix, int old_conda_shlvl); + std::string + replace_prefix_in_path(const fs::u8path& old_prefix, const fs::u8path& new_prefix); + std::string remove_prefix_from_path(const fs::u8path& prefix); + + void get_export_unset_vars( + EnvironmentTransform& envt, + const std::vector>& to_export + ); + + EnvironmentTransform build_reactivate(); + EnvironmentTransform build_deactivate(); + EnvironmentTransform build_activate(const fs::u8path& prefix); + + std::string activate(const fs::u8path& prefix, bool stack); + std::string reactivate(); + std::string deactivate(); + + virtual std::string hook_preamble() = 0; + virtual std::string hook_postamble() = 0; + virtual fs::u8path hook_source_path() = 0; + + std::string hook(const std::string& shell_type); + + protected: + + explicit Activator(const Context& context); + + const Context& m_context; + bool m_stack = false; + ActivationType m_action; + + std::unordered_map m_env; + }; + + class PosixActivator : public Activator + { + public: + + explicit PosixActivator(const Context& context) + : Activator(context) + { + } + + virtual ~PosixActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class CshActivator : public Activator + { + public: + + explicit CshActivator(const Context& context) + : Activator(context) + { + } + + virtual ~CshActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class CmdExeActivator : public Activator + { + public: + + explicit CmdExeActivator(const Context& context) + : Activator(context) + { + } + + virtual ~CmdExeActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class PowerShellActivator : public Activator + { + public: + + explicit PowerShellActivator(const Context& context) + : Activator(context) + { + } + + virtual ~PowerShellActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class XonshActivator : public Activator + { + public: + + explicit XonshActivator(const Context& context) + : Activator(context) + { + } + + virtual ~XonshActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class FishActivator : public Activator + { + public: + + explicit FishActivator(const Context& context) + : Activator(context) + { + } + + virtual ~FishActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + + class NuActivator : public Activator + { + public: + + explicit NuActivator(const Context& context) + : Activator(context) + { + } + + virtual ~NuActivator() = default; + + std::string script(const EnvironmentTransform& env_transform) override; + std::pair + update_prompt(const std::string& conda_prompt_modifier) override; + std::string shell_extension() override; + std::string shell() override; + + std::string hook_preamble() override; + std::string hook_postamble() override; + fs::u8path hook_source_path() override; + }; + +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/channel_context.hpp b/data/miniconda3/include/mamba/core/channel_context.hpp new file mode 100644 index 0000000000000000000000000000000000000000..98c0fdbef646c4b96ff42b71df87e9669857c3b5 --- /dev/null +++ b/data/miniconda3/include/mamba/core/channel_context.hpp @@ -0,0 +1,73 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_CHANNEL_HPP +#define MAMBA_CORE_CHANNEL_HPP + +#include +#include + +#include "mamba/specs/channel.hpp" + +namespace mamba +{ + class Context; + + class ChannelContext + { + public: + + using ChannelResolveParams = specs::ChannelResolveParams; + using Channel = specs::Channel; + using channel_list = ChannelResolveParams::channel_list; + + /** + * Create a ChannelContext with a simple parsing of the context options. + * + * No hardcoded names are added. + * Custom channels are treated as aliases rather than the Conda way (the name is not + * added at the end of the URL if absent). + */ + [[nodiscard]] static auto make_simple(const Context& ctx) -> ChannelContext; + + /** + * Create a ChannelContext while applying all of Conda context options. + * + * If not defined, the Conda custom channels "pkgs/main", "pkgs/r", "pkgs/pro", + * and "pkgs/msys2" (Windows only) will be added. + * If not defined, the Conda custom mutlit channels "defaults" and "local" will + * be added. + * The function will ensure custom channels names are added at the end of the URLs. + */ + [[nodiscard]] static auto make_conda_compatible(const Context& ctx) -> ChannelContext; + + /** + * Initialize channel with the parameters as they are. + * + * The Context is not parsed. + */ + ChannelContext(ChannelResolveParams params, std::vector has_zst); + + [[nodiscard]] auto make_channel(specs::UnresolvedChannel uc) -> const channel_list&; + [[nodiscard]] auto make_channel(std::string_view name) -> const channel_list&; + [[nodiscard]] auto + make_channel(std::string_view name, const std::vector& mirrors) + -> const channel_list&; + + [[nodiscard]] auto params() const -> const specs::ChannelResolveParams&; + + [[nodiscard]] auto has_zst(const Channel& chan) const -> bool; + + private: + + using ChannelCache = std::unordered_map; + + ChannelResolveParams m_channel_params; + ChannelCache m_channel_cache; + std::vector m_has_zst; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/core/common_types.hpp b/data/miniconda3/include/mamba/core/common_types.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3c0c29f381b718743d7455c31d5b8be24c683fa4 --- /dev/null +++ b/data/miniconda3/include/mamba/core/common_types.hpp @@ -0,0 +1,24 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_COMMON_TYPES_HPP +#define MAMBA_CORE_COMMON_TYPES_HPP + +namespace mamba +{ + enum class log_level + { + trace, + debug, + info, + warn, + err, + critical, + off + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/context.hpp b/data/miniconda3/include/mamba/core/context.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fd65a645494fd4b621e8095656a9103271b22f5a --- /dev/null +++ b/data/miniconda3/include/mamba/core/context.hpp @@ -0,0 +1,317 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_CONTEXT_HPP +#define MAMBA_CORE_CONTEXT_HPP + +#include +#include +#include +#include + +#include "mamba/core/common_types.hpp" +#include "mamba/core/context_params.hpp" +#include "mamba/core/palette.hpp" +#include "mamba/core/subdir_parameters.hpp" +#include "mamba/core/tasksync.hpp" +#include "mamba/download/mirror_map.hpp" +#include "mamba/download/parameters.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/solver/libsolv/parameters.hpp" +#include "mamba/solver/request.hpp" +#include "mamba/specs/authentication_info.hpp" +#include "mamba/specs/platform.hpp" +#include "mamba/version.hpp" + +#define ROOT_ENV_NAME "base" + +namespace mamba +{ + enum class VerificationLevel + { + Disabled, + Warn, + Enabled + }; + + struct ValidationParams + { + VerificationLevel safety_checks = VerificationLevel::Warn; + bool extra_safety_checks = false; + bool verify_artifacts = false; + + // TODO Uncomment `conda-forge` or whatever trusted_channels when possible + // (i.e server side package signing ready) + // Remove "http://127.0.0.1:8000/get/channel0" + // (should only be used in integration tests, + // this one is for testing with quetz) + std::vector trusted_channels = { + /*"conda-forge", */ "http://127.0.0.1:8000/get/channel0" + }; + }; + + enum class ChannelPriority + { + Disabled, + Flexible, + Strict + }; + + + class Logger; + class Context; + + struct ContextOptions + { + bool enable_logging = false; + bool enable_signal_handling = false; + }; + + // Context singleton class + class Context + { + public: + + static void use_default_signal_handler(bool val); + + struct OutputParams + { + int verbosity{ 0 }; + log_level logging_level{ log_level::warn }; + + bool json{ false }; + bool quiet{ false }; + + std::string log_pattern{ "%^%-9!l%-8n%$ %v" }; + std::size_t log_backtrace{ 0 }; + }; + + struct GraphicsParams + { + bool no_progress_bars{ false }; + Palette palette; + }; + + struct SrcParams + { + bool no_rc{ false }; + bool no_env{ false }; + }; + + // Configurable + bool experimental = false; + bool experimental_repodata_parsing = true; + bool experimental_matchspec_parsing = false; + bool debug = false; + bool use_uv = false; + + // TODO check writable and add other potential dirs + std::vector envs_dirs; + std::vector pkgs_dirs; + std::optional env_lockfile; + + bool use_index_cache = false; + std::size_t local_repodata_ttl = 1; // take from header + bool offline = false; + + ChannelPriority channel_priority = ChannelPriority::Flexible; + bool auto_activate_base = false; + + bool extract_sparse = false; + + bool dry_run = false; + bool download_only = false; + bool always_yes = false; + + bool register_envs = true; + + bool show_anaconda_channel_warnings = true; + + // solver options + solver::Request::Flags solver_flags = {}; + + // add start menu shortcuts on Windows (not implemented on Linux / macOS) + bool shortcuts = true; + + // debug helpers + bool keep_temp_files = false; + bool keep_temp_directories = false; + + bool change_ps1 = true; + std::string env_prompt = "({default_env}) "; + bool ascii_only = false; + // micromamba only + bool shell_completion = true; + + OutputParams output_params; + GraphicsParams graphics_params; + SrcParams src_params; + CommandParams command_params; + ThreadsParams threads_params; + PrefixParams prefix_params; + ValidationParams validation_params; + LinkParams link_params; + + download::RemoteFetchParams remote_fetch_params = { + .ssl_verify = { "" }, + .ssl_no_revoke = false, + .curl_initialized = false, + .user_agent = { "mamba/" LIBMAMBA_VERSION_STRING }, + .connect_timeout_secs = 10., + .retry_timeout = 2, + .retry_backoff = 3, + .max_retries = 3, + .proxy_servers = {}, + }; + + download::Options download_options() const + { + return { + .download_threads = this->threads_params.download_threads, + .fail_fast = false, + .sort = true, + .verbose = this->output_params.verbosity >= 2, + }; + } + + SubdirParams subdir_params() const + { + const auto get_local_repodata_ttl = [&]() -> std::optional + { + // Force the use of index cache by setting TTL to 0 + if (this->use_index_cache) + { + return { 0 }; + } + // This is legacy where from where 1 meant to read from header + if (this->local_repodata_ttl == 1) + { + return std::nullopt; + } + return { this->local_repodata_ttl }; + }; + + return { + .local_repodata_ttl_s = get_local_repodata_ttl(), + .offline = this->offline, + .repodata_force_use_zst = false // Must override based on ChannelContext + }; + } + + SubdirDownloadParams subdir_download_params() const + { + return { + .offline = this->offline, + .repodata_check_zst = this->repodata_use_zst, + }; + } + + TransactionParams transaction_params() const + { + return { + .is_mamba_exe = command_params.is_mamba_exe, + .json_output = output_params.json, + .verbosity = output_params.verbosity, + .shortcuts = shortcuts, + .envs_dirs = envs_dirs, + .platform = platform, + .prefix_params = prefix_params, + .link_params = link_params, + .threads_params = threads_params, + }; + } + + std::size_t lock_timeout = 0; + bool use_lockfiles = true; + + // Conda compat + bool add_pip_as_python_dependency = true; + + std::string host_platform = std::string(specs::build_platform_name()); + std::string platform = std::string(specs::build_platform_name()); + std::vector platforms() const; + + std::vector channels = { "conda-forge" }; + std::map custom_channels; + std::map> custom_multichannels; + + std::vector default_channels = { +#ifdef _WIN32 + "https://repo.anaconda.com/pkgs/main", + "https://repo.anaconda.com/pkgs/r", + "https://repo.anaconda.com/pkgs/msys2" +#else + "https://repo.anaconda.com/pkgs/main", + "https://repo.anaconda.com/pkgs/r" +#endif + }; + + std::map> mirrored_channels; + std::string channel_alias = "https://conda.anaconda.org"; + specs::AuthenticationDataBase& authentication_info(); + const specs::AuthenticationDataBase& authentication_info() const; + std::vector token_locations{ "~/.continuum/anaconda-client/tokens" }; + + bool override_channels_enabled = true; + + std::vector pinned_packages = {}; + + bool use_only_tar_bz2 = false; + + bool repodata_use_zst = true; + std::vector repodata_has_zst = { "https://conda.anaconda.org/conda-forge" }; + + // FIXME: Should not be stored here + // Notice that we cannot build this map directly from mirrored_channels, + // since we need to add a single "mirror" for non mirrored channels + download::mirror_map mirrors; + + Context(const Context&) = delete; + Context& operator=(const Context&) = delete; + + Context(Context&&) = delete; + Context& operator=(Context&&) = delete; + + void debug_print() const; + void dump_backtrace_no_guards(); + + void set_verbosity(int lvl); + void set_log_level(log_level level); + + Context(const ContextOptions& options = {}); + ~Context(); + + private: + + // Used internally + bool on_ci = false; + + void load_authentication_info(); + specs::AuthenticationDataBase m_authentication_info; + bool m_authentication_infos_loaded = false; + + class ScopedLogger; + std::vector loggers; + + std::shared_ptr main_logger(); + void add_logger(std::shared_ptr); + + TaskSynchronizer tasksync; + + + // Enables the provided context setup signal handling. + // This function must be called only for one Context in the lifetime of the program. + void enable_signal_handling(); + + // Enables the provided context to drive the logging system. + // This function must be called only for one Context in the lifetime of the program. + void enable_logging(); + }; + + +} // namespace mamba + +#endif // MAMBA_CONTEXT_HPP diff --git a/data/miniconda3/include/mamba/core/context_params.hpp b/data/miniconda3/include/mamba/core/context_params.hpp new file mode 100644 index 0000000000000000000000000000000000000000..136ebcfe620b92da158cf3fc75ed8b52d39f40aa --- /dev/null +++ b/data/miniconda3/include/mamba/core/context_params.hpp @@ -0,0 +1,62 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#pragma once + +#include +#include + +#include "mamba/fs/filesystem.hpp" + +// TODO move these structures back to Context.hpp or rename this file +// with a better name when the Context is fully refactored. +namespace mamba +{ + struct CommandParams + { + std::string caller_version{ "" }; + std::string conda_version{ "3.8.0" }; + std::string current_command{ "mamba" }; + /** Is the Context used in a mamba or mamba executable (instead of a lib). */ + bool is_mamba_exe{ false }; + }; + + struct PrefixParams + { + fs::u8path target_prefix; + fs::u8path root_prefix; + fs::u8path conda_prefix; + fs::u8path relocate_prefix; + }; + + struct LinkParams + { + bool allow_softlinks = false; + bool always_copy = false; + bool always_softlink = false; + bool compile_pyc = true; + }; + + struct ThreadsParams + { + std::size_t download_threads{ 5 }; + int extract_threads{ 0 }; + }; + + struct TransactionParams + { + bool is_mamba_exe; + bool json_output; + int verbosity; + bool shortcuts; + std::vector envs_dirs; + std::string platform; + + PrefixParams prefix_params; + LinkParams link_params; + ThreadsParams threads_params; + }; +} diff --git a/data/miniconda3/include/mamba/core/download_progress_bar.hpp b/data/miniconda3/include/mamba/core/download_progress_bar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9dbae146f34db2a1ca734e2403d66cd8dc3189cb --- /dev/null +++ b/data/miniconda3/include/mamba/core/download_progress_bar.hpp @@ -0,0 +1,113 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_DOWNLOAD_PROGRESS_BAR_HPP +#define MAMBA_CORE_DOWNLOAD_PROGRESS_BAR_HPP + +#include +#include +#include + +#include "mamba/core/context.hpp" +#include "mamba/core/package_fetcher.hpp" +#include "mamba/download/downloader.hpp" + +namespace mamba +{ + struct MonitorOptions + { + bool checking_download = false; + bool no_clear_progress_bar = false; + }; + + class SubdirIndexMonitor : public download::Monitor + { + public: + + static bool can_monitor(const Context& context); + + explicit SubdirIndexMonitor(MonitorOptions options = {}); + virtual ~SubdirIndexMonitor() = default; + + SubdirIndexMonitor(const SubdirIndexMonitor&) = delete; + SubdirIndexMonitor& operator=(const SubdirIndexMonitor&) = delete; + + SubdirIndexMonitor(SubdirIndexMonitor&&) = delete; + SubdirIndexMonitor& operator=(SubdirIndexMonitor&&) = delete; + + void reset_options(MonitorOptions options); + + private: + + void observe_impl(download::MultiRequest& requests, download::Options& options) override; + void on_done_impl() override; + void on_unexpected_termination_impl() override; + + void update_progress_bar(std::size_t index, const download::Event& event); + void update_progress_bar(std::size_t index, const download::Progress& progress); + void update_progress_bar(std::size_t index, const download::Error& error); + void update_progress_bar(std::size_t index, const download::Success& success); + + void complete_checking_progress_bar(std::size_t index); + + using time_point = std::chrono::steady_clock::time_point; + std::vector m_throttle_time; + std::vector m_progress_bar; + MonitorOptions m_options; + }; + + class PackageDownloadMonitor : public download::Monitor + { + public: + + static bool can_monitor(const Context& context); + + PackageDownloadMonitor() = default; + virtual ~PackageDownloadMonitor(); + + PackageDownloadMonitor(const PackageDownloadMonitor&) = delete; + PackageDownloadMonitor& operator=(const PackageDownloadMonitor&) = delete; + + PackageDownloadMonitor(PackageDownloadMonitor&&) = delete; + PackageDownloadMonitor& operator=(PackageDownloadMonitor&&) = delete; + + // Requires extract_tasks.size() >= requests.size() + // Requires for i in [0, dl_requests.size()), extract_tasks[i].needs_download() + void observe( + download::MultiRequest& dl_requests, + std::vector& extract_tasks, + download::Options& options + ); + + void end_monitoring(); + + private: + + void init_extract_bar(ProgressProxy& extract_bar); + void init_download_bar(ProgressProxy& download_bar); + void init_aggregated_extract(); + void init_aggregated_download(); + + void update_extract_bar(std::size_t index, PackageExtractEvent event); + + void observe_impl(download::MultiRequest& requests, download::Options& options) override; + void on_done_impl() override; + void on_unexpected_termination_impl() override; + + void update_progress_bar(std::size_t index, const download::Event& event); + void update_progress_bar(std::size_t index, const download::Progress& progress); + void update_progress_bar(std::size_t index, const download::Error& error); + void update_progress_bar(std::size_t index, const download::Success& success); + + std::vector m_extract_bar; + + using time_point = std::chrono::steady_clock::time_point; + std::vector m_throttle_time; + std::vector m_download_bar; + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/env_lockfile.hpp b/data/miniconda3/include/mamba/core/env_lockfile.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8b4abc001fbb573191efcdcfd75d73f39423a2d2 --- /dev/null +++ b/data/miniconda3/include/mamba/core/env_lockfile.hpp @@ -0,0 +1,124 @@ +// Copyright (c) 2022, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + + +#ifndef MAMBA_CORE_ENVIRONMENT_LOCKFILE_HPP +#define MAMBA_CORE_ENVIRONMENT_LOCKFILE_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/core/error_handling.hpp" +#include "mamba/core/fsutil.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + class Context; + class ChannelContext; + + enum class file_parsing_error_code + { + unknown_failure, /// Something failed while parsing but we can't identify what. + unsupported_version, /// The version of the file does not matched supported ver. + parsing_failure, /// The content of the file doesnt match the expected format/language + /// structure or constraints. + invalid_data, /// The structure of the data in the file is fine but some fields have + /// invalid values for our purpose. + }; + + struct EnvLockFileError + { + file_parsing_error_code parsing_error_code = file_parsing_error_code::unknown_failure; + std::optional yaml_error_type{}; + + static const EnvLockFileError& get_details(const mamba_error& error) + { + return std::any_cast(error.data()); + } + + template + static mamba_error make_error( + file_parsing_error_code error_code, + StringT&& msg, + std::optional yaml_error_type = std::nullopt + ) + { + return mamba_error{ std::forward(msg), + mamba_error_code::env_lockfile_parsing_failed, + EnvLockFileError{ error_code, yaml_error_type } }; + } + }; + + class EnvironmentLockFile + { + public: + + struct Channel + { + std::string url; + std::vector used_env_vars; + }; + + struct Meta + { + std::unordered_map content_hash; + std::vector channels; + std::vector platforms; + std::vector sources; + }; + + struct Package + { + specs::PackageInfo info; + bool is_optional = false; + std::string category; + std::string manager; + std::string platform; + }; + + EnvironmentLockFile(Meta metadata, std::vector packages) + : m_metadata(std::move(metadata)) + , m_packages(std::move(packages)) + { + } + + std::vector + get_packages_for(std::string_view category, std::string_view platform, std::string_view manager) + const; + + const std::vector& get_all_packages() const + { + return m_packages; + } + + const Meta& get_metadata() const + { + return m_metadata; + } + + private: + + Meta m_metadata; + std::vector m_packages; + }; + + /// Read an environment lock YAML file and returns it's structured content or an error if + /// failed. + tl::expected + read_environment_lockfile(const mamba::fs::u8path& lockfile_location); + + + /// Returns `true` if the filename matches names of files which should be interpreted as conda + /// environment lockfile. NOTE: this does not check if the file exists. + bool is_env_lockfile_name(std::string_view filename); +} +#endif diff --git a/data/miniconda3/include/mamba/core/environments_manager.hpp b/data/miniconda3/include/mamba/core/environments_manager.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9c8339346cf7ef1fa1840fc1749292d17996b042 --- /dev/null +++ b/data/miniconda3/include/mamba/core/environments_manager.hpp @@ -0,0 +1,50 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_ENVIRONMENT_MANAGER +#define MAMBA_CORE_ENVIRONMENT_MANAGER + +#include +#include +#include + +#include "fsutil.hpp" + +namespace mamba +{ + class Context; + + const char PREFIX_MAGIC_FILE[] = "conda-meta/history"; + + bool is_conda_environment(const fs::u8path& prefix); + + std::string env_name( + const std::vector& envs_dirs, + const fs::u8path& root_prefix, + const fs::u8path& prefix + ); + + class EnvironmentsManager + { + public: + + explicit EnvironmentsManager(const Context& context); + + void register_env(const fs::u8path& location); + void unregister_env(const fs::u8path& location); + std::set list_all_known_prefixes(); + + private: + + const Context& m_context; + std::set + clean_environments_txt(const fs::u8path& env_txt_file, const fs::u8path& location); + std::string remove_trailing_slash(std::string p); + fs::u8path get_environments_txt_file(const fs::u8path& home) const; + }; +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/error_handling.hpp b/data/miniconda3/include/mamba/core/error_handling.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3be2e24f4ff27d9de9f64337e574110353436b14 --- /dev/null +++ b/data/miniconda3/include/mamba/core/error_handling.hpp @@ -0,0 +1,349 @@ +#ifndef MAMBA_ERROR_HANDLING_HPP +#define MAMBA_ERROR_HANDLING_HPP + +#include +#include +#include +#include + +#include "tl/expected.hpp" + +namespace mamba +{ + + /********************* + * Mamba exceptions * + *********************/ + + enum class mamba_error_code + { + unknown, + aggregated, + prefix_data_not_loaded, + subdirdata_not_loaded, + cache_not_loaded, + repodata_not_loaded, + configurable_bad_cast, + env_lockfile_parsing_failed, + openssl_failed, + internal_failure, + lockfile_failure, + selfupdate_failure, + satisfiablitity_error, + user_interrupted, + incorrect_usage, + invalid_spec, + download_content + }; + + class mamba_error : public std::runtime_error + { + public: + + using base_type = std::runtime_error; + + mamba_error(const std::string& msg, mamba_error_code ec); + mamba_error(const char* msg, mamba_error_code ec); + mamba_error(const std::string& msg, mamba_error_code ec, std::any&& data); + mamba_error(const char* msg, mamba_error_code ec, std::any&& data); + + mamba_error_code error_code() const noexcept; + const std::any& data() const noexcept; + + private: + + mamba_error_code m_error_code; + std::any m_data; + }; + + class mamba_aggregated_error : public mamba_error + { + public: + + using base_type = mamba_error; + using error_list_t = std::vector; + + explicit mamba_aggregated_error(error_list_t&& error_list); + + const char* what() const noexcept override; + + private: + + error_list_t m_error_list; + mutable std::string m_aggregated_message; + static constexpr const char* m_base_message = "Multiple errors occurred:\n"; + }; + + /******************************** + * wrappers around tl::expected * + ********************************/ + + template + class expected_ref_wrapper : private tl::expected, E> + { + public: + + using value_type = T; + using self_type = expected_ref_wrapper; + using reference = std::reference_wrapper; + using base_type = tl::expected; + + using base_type::base_type; + using base_type::operator=; + using base_type::emplace; + using base_type::error; + using base_type::operator bool; + using base_type::has_value; + + constexpr void swap(self_type& rhs) noexcept; + + constexpr const T* operator->() const noexcept; + constexpr T* operator->() noexcept; + constexpr const T& operator*() const& noexcept; + constexpr T& operator*() & noexcept; + constexpr const T&& operator*() const&& noexcept; + constexpr T&& operator*() && noexcept; + + constexpr T& value() &; + constexpr const T&& value() const&&; + constexpr T&& value() &&; + + template + constexpr T value_or(U&&) const&; + template + constexpr T value_or(U&&) &&; + + template + friend constexpr bool operator==(const self_type& x, const expected_ref_wrapper& y); + + template + friend constexpr bool operator==(const self_type&, const T2&); + + template + friend constexpr bool operator==(const self_type&, const tl::unexpected&); + }; + + namespace detail + { + template + struct get_expected + { + using type = tl::expected; + }; + + template + struct get_expected + { + using type = expected_ref_wrapper; + }; + } + + template + using expected_t = typename detail::get_expected::type; + + /******************** + * helper functions * + ********************/ + + tl::unexpected make_unexpected(const char* msg, mamba_error_code ec); + + tl::unexpected make_unexpected(const std::string& msg, mamba_error_code sc); + + tl::unexpected make_unexpected(std::vector&& error_list); + + template + tl::unexpected forward_error(const tl::expected& exp); + + template + tl::unexpected forward_error(const expected_ref_wrapper& exp); + + template + T& extract(tl::expected& exp); + + template + const T& extract(const tl::expected& exp); + + template + T&& extract(tl::expected&& exp); + + template + T& extract(expected_ref_wrapper& exp); + + template + const T& extract(const expected_ref_wrapper& exp); + + template + T&& extract(expected_ref_wrapper&& exp); + + /*************************************** + * expected_ref_wrapper implementation * + ***************************************/ + + template + constexpr void expected_ref_wrapper::swap(self_type& rhs) noexcept + { + base_type::swap(rhs); + } + + template + constexpr const T* expected_ref_wrapper::operator->() const noexcept + { + return &(base_type::operator->()->get()); + } + + template + constexpr T* expected_ref_wrapper::operator->() noexcept + { + return &(base_type::operator->()->get()); + } + + template + constexpr const T& expected_ref_wrapper::operator*() const& noexcept + { + return base_type::operator*().get(); + } + + template + constexpr T& expected_ref_wrapper::operator*() & noexcept + { + return base_type::operator*().get(); + } + + template + constexpr const T&& expected_ref_wrapper::operator*() const&& noexcept + { + return std::move(base_type::operator*().get()); + } + + template + constexpr T&& expected_ref_wrapper::operator*() && noexcept + { + return std::move(base_type::operator*().get()); + } + + template + constexpr T& expected_ref_wrapper::value() & + { + return base_type::value().get(); + } + + template + constexpr const T&& expected_ref_wrapper::value() const&& + { + return std::move(base_type::value().get()); + } + + template + constexpr T&& expected_ref_wrapper::value() && + { + return std::move(base_type::value().get()); + } + + template + template + constexpr T expected_ref_wrapper::value_or(U&& u) const& + { + return base_type::value_or(std::move(u)).get(); + } + + template + template + constexpr T expected_ref_wrapper::value_or(U&& u) && + { + return base_type::value_or(std::move(u)).get(); + } + + template + constexpr bool + operator==(const expected_ref_wrapper& x, const expected_ref_wrapper& y) + { + using base_type1 = typename expected_ref_wrapper::base_type; + using base_type2 = typename expected_ref_wrapper::base_type; + return operator==(static_cast(x), static_cast(y)); + } + + template + constexpr bool operator==(const expected_ref_wrapper& x, const T2& y) + { + using base_type1 = typename expected_ref_wrapper::base_type; + return operator==(static_cast(x), y); + } + + template + constexpr bool operator==(const expected_ref_wrapper& x, const tl::unexpected& y) + { + using base_type1 = typename expected_ref_wrapper::base_type; + return operator==(static_cast(x), y); + } + + /*********************************** + * helper functions implementation * + ***********************************/ + + template + tl::unexpected forward_error(const tl::expected& exp) + { + return tl::make_unexpected(exp.error()); + } + + template + tl::unexpected forward_error(const expected_ref_wrapper& exp) + { + return tl::make_unexpected(exp.error()); + } + + namespace detail + { + template + decltype(auto) extract_impl(T&& exp) + { + if (exp) + { + return std::forward(exp).value(); + } + else + { + throw exp.error(); + } + } + } + + template + T& extract(tl::expected& exp) + { + return detail::extract_impl(exp); + } + + template + const T& extract(const tl::expected& exp) + { + return detail::extract_impl(exp); + } + + template + T&& extract(tl::expected&& exp) + { + return detail::extract_impl(std::move(exp)); + } + + template + T& extract(expected_ref_wrapper& exp) + { + return detail::extract_impl(exp); + } + + template + const T& extract(const expected_ref_wrapper& exp) + { + return detail::extract_impl(exp); + } + + template + T&& extract(expected_ref_wrapper&& exp) + { + return detail::extract_impl(std::move(exp)); + } + +} + +#endif diff --git a/data/miniconda3/include/mamba/core/execution.hpp b/data/miniconda3/include/mamba/core/execution.hpp new file mode 100644 index 0000000000000000000000000000000000000000..fda57dc987ae5f6e8eee2e38afd7f3e077ca8daa --- /dev/null +++ b/data/miniconda3/include/mamba/core/execution.hpp @@ -0,0 +1,158 @@ +// Copyright (c) 2022, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_EXECUTION_HPP +#define MAMBA_CORE_EXECUTION_HPP + +#include +#include +#include +#include +#include + +#include "mamba/core/error_handling.hpp" +#include "mamba/util/synchronized_value.hpp" + +namespace mamba +{ + struct MainExecutorError : public mamba_error + { + using mamba_error::mamba_error; + }; + + // Main execution resource (for example threads) handler for this library. + // Allows scoping the lifetime of threads being used by the library. + // The user code can either create an instance of this type to determine + // itself the lifetime of the threads, or it can just use `MainExecutor::instance()` + // to obtain a global static instance. In this last case, `MainExecutor::instance().close()` + // have to be called before the end of `main()` to avoid undefined behaviors. + // WARNING: this is a temporary solution designed to evolve, the current implementation + // uses threads directly, a future implementation will use a thread-pool or other similar + // mechanisms. + class MainExecutor + { + public: + + // Set itself as the main executor. + // Throws `MainExecutorError` if another instance already exists. + MainExecutor(); + + // Closes (see `close()`) and unregister itself as the main executor. + // Blocks until all scheduled tasks are done and all resources are released (threads + // joined). + ~MainExecutor(); + + // Returns a reference to the current main executor. + // If no main executor have been set previously to this call, + // a global one is created and returned. In this case the user must + // call `MainExecutor::instance().close()` before the end of `main()` to avoid + // undefined behaviors. + static MainExecutor& instance(); + + // If the default (global) main executor is being used, close and destroy it. + // Do nothing otherwise. + // This is mostly used for testing and libraries using the default main executor. + static void stop_default(); + + // Schedules a task for execution. + // The task must be a callable which takes either the provided arguments or none. + // If this executor is open, the task is scheduled for execution and will be called + // as soon as execution resources are available. The call to the task is not guaranteed + // to have been done at the end of the execution of this function, nor before. + // If this executor is closed, the task is ignored and no code will be executed nor the task + // be called. + template + void schedule(Task&& task, Args&&... args) + { + if (!is_open) + { + return; + } + + auto synched_threads = threads.synchronize(); + if (is_open) // Double check necessary for correctness + { + synched_threads->emplace_back(std::forward(task), std::forward(args)...); + } + } + + // Moves ownership of a thread into this executor. + // This is used in case a thread needs to be manipulated in a particular way, + // but we still want to avoid having to use `std::thread::detach()`. By + // transferring the ownership of the thread to this executor, we are guaranteed that + // the thread will be joined before the end of the lifetime of this executor. + // If this executor is closed, no code will be executed and the thread will be destroyed, + // resulting in a call to `std::terminate()` if the thread is not already joined. + void take_ownership(std::thread thread) + { + if (!thread.joinable() || !is_open) + { + return; + } + + auto synched_threads = threads.synchronize(); + if (is_open) // Double check necessary for correctness + { + synched_threads->push_back(std::move(thread)); + } + } + + // Closes this executor: + // Only returns once all tasks scheduled before this call are finished + // and all owned execution resources (aka threads) are released. + // Note that if any task never ends, this function will never end either. + // Once called this function makes all other functions no-op, even before returning, to + // prevent running tasks from scheduling more tasks to run. This is should be used to + // manually determine the lifetime of the executor's resources. + void close() + { + bool expected = true; + if (!is_open.compare_exchange_strong(expected, false)) + { + return; + } + + invoke_close_handlers(); + + auto synched_threads = threads.synchronize(); + for (auto&& t : *synched_threads) + { + t.join(); + } + synched_threads->clear(); + } + + using on_close_handler = std::function; + + void on_close(on_close_handler handler) + { + if (!is_open) + { + return; + } + + auto handlers = close_handlers.synchronize(); + if (is_open) // Double check needed to avoid adding new handles while closing. + { + handlers->push_back(std::move(handler)); + } + } + + private: + + std::atomic is_open{ true }; + using Threads = std::vector; + using CloseHandlers = std::vector; + util::synchronized_value threads; + util::synchronized_value close_handlers; + + void invoke_close_handlers(); + }; + + +} + +#endif diff --git a/data/miniconda3/include/mamba/core/fsutil.hpp b/data/miniconda3/include/mamba/core/fsutil.hpp new file mode 100644 index 0000000000000000000000000000000000000000..51df18879399dabb827eabddfafbe4e9d2c30e93 --- /dev/null +++ b/data/miniconda3/include/mamba/core/fsutil.hpp @@ -0,0 +1,49 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_FS_UTIL +#define MAMBA_CORE_FS_UTIL + +#include + +namespace mamba +{ + namespace fs + { + class u8path; + } + + namespace path + { + bool starts_with_home(const fs::u8path& p); + + void create_directories_sudo_safe(const fs::u8path& path); + bool touch(const fs::u8path& path, bool mkdir = false, bool sudo_safe = false); + + /** + * Returns `true` only if the provided path is either: + * - a file we are able to open for writing; + * - a directory we are able to create a file in for writing; + * - a file name that does not exist but the parent directory in the path exists and we + * are able to create a file with that name in that directory for writing. + * Returns `false` otherwise. + */ + bool is_writable(const fs::u8path& path) noexcept; + } + + namespace mamba_fs + { + /** Like std::rename, but works across file systems by moving the file instead + * if the rename fails. + * if both rename and move fail, the error code is set to the error code of the + * copy_file operation and the `to` file is removed. You will have to handle removal + * of the `from` file yourself. + */ + void rename_or_move(const fs::u8path& from, const fs::u8path& to, std::error_code& ec); + + } +} +#endif diff --git a/data/miniconda3/include/mamba/core/history.hpp b/data/miniconda3/include/mamba/core/history.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5aa79b85c146e83a6a20e0c2fa51750a89a6452a --- /dev/null +++ b/data/miniconda3/include/mamba/core/history.hpp @@ -0,0 +1,97 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_HISTORY +#define MAMBA_CORE_HISTORY + +#include +#include +#include + +#include "mamba/core/channel_context.hpp" +#include "mamba/core/context_params.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/specs/match_spec.hpp" +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + class History + { + public: + + History(const fs::u8path& prefix, ChannelContext& channel_context); + + struct ParseResult + { + std::string head_line; + std::vector diff; + std::vector comments; + }; + + struct UserRequest + { + static UserRequest prefilled(const CommandParams& command_params); + + std::string date; + std::size_t revision_num = 0; + std::string cmd; + std::string conda_version; + + std::vector unlink_dists; + std::vector link_dists; + + std::vector update; + std::vector remove; + std::vector neutered; + }; + + std::vector parse(); + bool parse_comment_line(const std::string& line, UserRequest& req); + std::vector get_user_requests(); + std::unordered_map get_requested_specs_map(); + void add_entry(const History::UserRequest& entry); + + fs::u8path m_prefix; + fs::u8path m_history_file_path; + ChannelContext& m_channel_context; + }; + + /** PackageDiff contains two maps of packages and their package info, one being for the + * installed packages, the other for the removed ones. This is used while looping on + * revisions to get the diff between the target revision and the current one. + */ + struct PackageDiff + { + using package_diff_map = std::unordered_map; + package_diff_map removed_pkg_diff; + package_diff_map installed_pkg_diff; + + [[nodiscard]] static PackageDiff + from_revision(const std::vector& user_requests, std::size_t target_revision); + }; + + /** The following function parses the different formats that can be found in the history + * file. + * + * conda/mamba1 format: + * + * installed: +conda-forge/linux-64::xtl-0.8.0-h84d6215_0 + * removed: -conda-forge/linux-64::xtl-0.8.0-h84d6215_0 + * + * mamba2 broken format: + * + * installed: +conda-forge::xtl-0.8.0-h84d6215_0 + * removed: -https://conda.anaconda.org/conda-forge/linux-64::xtl-0.8.0-h84d6215_0 + * + * mamba2 new format: + * installed: +https://conda.anaconda.org/conda-forge/linux-64::xtl-0.8.0-h84d6215_0 + * removed: -https://conda.anaconda.org/conda-forge/linux-64::xtl-0.8.0-h84d6215_0 + */ + specs::PackageInfo read_history_url_entry(const std::string& s); +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/invoke.hpp b/data/miniconda3/include/mamba/core/invoke.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c8724425bd67e29cd3f408571c7304a344c44c98 --- /dev/null +++ b/data/miniconda3/include/mamba/core/invoke.hpp @@ -0,0 +1,51 @@ +#ifndef MAMBA_INVOKE_HPP +#define MAMBA_INVOKE_HPP + +#include + +#include "mamba/core/error_handling.hpp" + +namespace mamba +{ + + template + auto safe_invoke(Func&& func, Args&&... args) + -> tl::expected(func), std::forward(args)...)), mamba_error> + { + try + { + // If the callable is passed by being moved-in (r-value reference/temporary etc.) + // we make sure that the lifetime of that callable doesnt go beyond this block. + auto call = [&, callable = std::forward(func)] + { return std::invoke(callable, std::forward(args)...); }; + using Result = decltype(call()); + + if constexpr (std::is_void::value) + { + call(); + return {}; + } + else + { + return call(); + } + } + catch (const std::runtime_error& err) + { + return make_unexpected( + std::string("callback invocation failed : ") + err.what(), + mamba_error_code::unknown + ); + } + catch (...) + { + return make_unexpected( + "callback invocation failed : unknown error", + mamba_error_code::unknown + ); + } + } + +} + +#endif diff --git a/data/miniconda3/include/mamba/core/menuinst.hpp b/data/miniconda3/include/mamba/core/menuinst.hpp new file mode 100644 index 0000000000000000000000000000000000000000..21268562a13e96e5556e02cba006563e9c6a3b7c --- /dev/null +++ b/data/miniconda3/include/mamba/core/menuinst.hpp @@ -0,0 +1,20 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +namespace mamba +{ + class TransactionContext; + + namespace fs + { + class u8path; + } + + void + remove_menu_from_json(const fs::u8path& json_file, const TransactionContext& transaction_context); + void + create_menu_from_json(const fs::u8path& json_file, const TransactionContext& transaction_context); +} diff --git a/data/miniconda3/include/mamba/core/output.hpp b/data/miniconda3/include/mamba/core/output.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ae13e430723208f03ba5591f09cda0a69b6fb3d3 --- /dev/null +++ b/data/miniconda3/include/mamba/core/output.hpp @@ -0,0 +1,208 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_OUTPUT_HPP +#define MAMBA_CORE_OUTPUT_HPP + +#include +#include +#include +#include +#include + +#include +#include + +#include "mamba/core/common_types.hpp" +#include "mamba/core/progress_bar.hpp" + +namespace mamba +{ + class Context; + + std::string cut_repo_name(std::string_view reponame); + + namespace printers + { + struct FormattedString + { + std::string s; + fmt::text_style style = {}; + + FormattedString() = default; + + inline FormattedString(const std::string& i) + : s(i) + { + } + + inline FormattedString(const std::string_view i) + : s(i) + { + } + + inline FormattedString(const char* i) + : s(i) + { + } + + inline std::size_t size() const + { + return s.size(); + } + }; + + enum class alignment + { + left, + right, + }; + + constexpr auto alignmentMarker(alignment a) -> std::string_view + { + switch (a) + { + case alignment::right: + return "alignment_right"; + case alignment::left: + return "alignment_right"; + default: + assert(false); + return ""; + } + } + + class Table + { + public: + + Table(const std::vector& header); + + void set_alignment(const std::vector& a); + void set_padding(const std::vector& p); + void add_row(const std::vector& r); + void + add_rows(const std::string& header, const std::vector>& rs); + + std::ostream& print(std::ostream& out); + + private: + + std::vector m_header; + std::vector m_align; + std::vector m_padding; + std::vector> m_table; + }; + + std::ostringstream table_like(const std::vector& data, std::size_t max_width); + } // namespace printers + + // Todo: replace public inheritance with + // private one + using directives + class ConsoleStream : public std::stringstream + { + public: + + ConsoleStream() = default; + ~ConsoleStream(); + }; + + class ProgressBarManager; + class ConsoleData; + + class Console + { + public: + + Console(const Console&) = delete; + Console& operator=(const Console&) = delete; + + Console(Console&&) = delete; + Console& operator=(Console&&) = delete; + + static Console& instance(); + static bool is_available(); + static ConsoleStream stream(); + static bool prompt(std::string_view message, char fallback = '_'); + static bool prompt(std::string_view message, char fallback, std::istream& input_stream); + + ProgressProxy add_progress_bar(const std::string& name, size_t expected_total = 0); + void clear_progress_bars(); + ProgressBarManager& init_progress_bar_manager(ProgressBarMode mode = ProgressBarMode::multi); + void terminate_progress_bar_manager(); + ProgressBarManager& progress_bar_manager(); + + static std::string hide_secrets(std::string_view str); + + void print(std::string_view str, bool force_print = false); + void json_write(const nlohmann::json& j); + void json_append(const std::string& value); + void json_append(const nlohmann::json& j); + void json_down(const std::string& key); + void json_up(); + + static void print_buffer(std::ostream& ostream); + + void cancel_json_print(); + + const Context& context() const; + + Console(const Context& context); + ~Console(); + + private: + + void json_print(); + void deactivate_progress_bar(std::size_t idx, std::string_view msg = ""); + + std::unique_ptr p_data; + + friend class ProgressProxy; + + static void set_singleton(Console& console); + static void clear_singleton(); + }; + + class MessageLogger + { + public: + + MessageLogger(log_level level); + ~MessageLogger(); + + std::stringstream& stream(); + + static void activate_buffer(); + static void deactivate_buffer(); + static void print_buffer(std::ostream& ostream); + + private: + + log_level m_level; + std::stringstream m_stream; + + static void emit(const std::string& msg, const log_level& level); + }; + +} // namespace mamba + +#undef LOG +#undef LOG_TRACE +#undef LOG_DEBUG +#undef LOG_INFO +#undef LOG_WARNING +#undef LOG_ERROR +#undef LOG_CRITICAL + +#define LOG(severity) mamba::MessageLogger(severity).stream() +#define LOG_TRACE LOG(mamba::log_level::trace) +#define LOG_DEBUG LOG(mamba::log_level::debug) +#define LOG_INFO LOG(mamba::log_level::info) +#define LOG_WARNING LOG(mamba::log_level::warn) +#define LOG_ERROR LOG(mamba::log_level::err) +#define LOG_CRITICAL LOG(mamba::log_level::critical) + +#endif // MAMBA_CORE_OUTPUT_HPP diff --git a/data/miniconda3/include/mamba/core/package_cache.hpp b/data/miniconda3/include/mamba/core/package_cache.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ba1c7ad7ca3d2324e1d48f3ce38fa7b745d32441 --- /dev/null +++ b/data/miniconda3/include/mamba/core/package_cache.hpp @@ -0,0 +1,84 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PACKAGE_CACHE +#define MAMBA_CORE_PACKAGE_CACHE + +#include +#include +#include + +#include "mamba/core/fsutil.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/specs/package_info.hpp" + +#define PACKAGE_CACHE_MAGIC_FILE "urls.txt" + +namespace mamba +{ + struct ValidationParams; + + enum class Writable + { + UNKNOWN, + WRITABLE, + NOT_WRITABLE, + DIR_DOES_NOT_EXIST + }; + + // TODO layered package caches + class PackageCacheData + { + public: + + explicit PackageCacheData(const fs::u8path& path); + + bool create_directory(); + void set_writable(Writable writable); + Writable is_writable(); + fs::u8path path() const; + void clear_query_cache(const specs::PackageInfo& s); + + bool has_valid_tarball(const specs::PackageInfo& s, const ValidationParams& params); + bool has_valid_extracted_dir(const specs::PackageInfo& s, const ValidationParams& params); + + private: + + void check_writable(); + + std::map m_valid_tarballs; + std::map m_valid_extracted_dir; + Writable m_writable = Writable::UNKNOWN; + fs::u8path m_path; + }; + + class MultiPackageCache + { + public: + + MultiPackageCache(const std::vector& pkgs_dirs, const ValidationParams& params); + + std::vector paths() const; + + fs::u8path get_tarball_path(const specs::PackageInfo& s, bool return_empty = true); + fs::u8path get_extracted_dir_path(const specs::PackageInfo& s, bool return_empty = true); + + fs::u8path first_writable_path(); + PackageCacheData& first_writable_cache(bool create = false); + std::vector writable_caches(); + + void clear_query_cache(const specs::PackageInfo& s); + + private: + + std::vector m_caches; + std::map m_cached_tarballs; + std::map m_cached_extracted_dirs; + const ValidationParams& m_params; + }; +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/package_database_loader.hpp b/data/miniconda3/include/mamba/core/package_database_loader.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d1df00ecdb587ab266668daf0ca0b91c739c3748 --- /dev/null +++ b/data/miniconda3/include/mamba/core/package_database_loader.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PACKAGE_DATABASE_LOADER_HPP +#define MAMBA_CORE_PACKAGE_DATABASE_LOADER_HPP + +#include "mamba/core/error_handling.hpp" +#include "mamba/solver/libsolv/repo_info.hpp" +#include "mamba/specs/channel.hpp" + +namespace mamba +{ + class Context; + class PrefixData; + class SubdirIndexLoader; + + namespace solver::libsolv + { + class Database; + } + + void add_spdlog_logger_to_database(solver::libsolv::Database& database); + + auto load_subdir_in_database( // + const Context& ctx, + solver::libsolv::Database& database, + const SubdirIndexLoader& subdir + ) -> expected_t; + + auto load_installed_packages_in_database( + const Context& ctx, + solver::libsolv::Database& database, + const PrefixData& prefix + ) -> solver::libsolv::RepoInfo; +} +#endif diff --git a/data/miniconda3/include/mamba/core/package_fetcher.hpp b/data/miniconda3/include/mamba/core/package_fetcher.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e9974b1814dbcb53c72ddf2a5f8c67a24fa5964 --- /dev/null +++ b/data/miniconda3/include/mamba/core/package_fetcher.hpp @@ -0,0 +1,147 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PACKAGE_FETCHER_HPP +#define MAMBA_CORE_PACKAGE_FETCHER_HPP + +#include + +#include "mamba/core/package_cache.hpp" +#include "mamba/core/package_handling.hpp" +#include "mamba/core/thread_utils.hpp" +#include "mamba/download/downloader.hpp" +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + + class PackageFetcher; + + enum class PackageExtractEvent + { + validate_update, + validate_success, + validate_failure, + extract_update, + extract_success, + extract_failure + }; + + class PackageExtractTask + { + public: + + struct Result + { + bool valid; + bool extracted; + }; + + using progress_callback_t = std::function; + + PackageExtractTask(PackageFetcher* fetcher, ExtractOptions options); + + const std::string& name() const; + bool needs_download() const; + + void set_progress_callback(progress_callback_t cb); + + Result run(); + Result run(std::size_t downloaded_size); + + private: + + progress_callback_t* get_progress_callback(); + + PackageFetcher* p_fetcher; + ExtractOptions m_options; + std::optional m_progress_callback = std::nullopt; + }; + + class PackageFetcher + { + public: + + enum class ValidationResult + { + UNDEFINED = 0, + VALID = 1, + SHA256_ERROR, + MD5SUM_ERROR, + SIZE_ERROR, + EXTRACT_ERROR + }; + + using post_download_success_t = std::function; + using progress_callback_t = std::function; + + PackageFetcher(const specs::PackageInfo& pkg_info, MultiPackageCache& caches); + + const std::string& name() const; + + bool needs_download() const; + bool needs_extract() const; + + download::Request + build_download_request(std::optional callback = std::nullopt); + ValidationResult + validate(std::size_t downloaded_size, progress_callback_t* cb = nullptr) const; + bool extract(const ExtractOptions& options, progress_callback_t* cb = nullptr); + + // The PackageFetcher object should be stable in memory (i.e. not moved) after this + // method has been called, until the PackageExtractTask has been completed. + PackageExtractTask build_extract_task(ExtractOptions options); + + void clear_cache() const; + + private: + + struct CheckSumParams; + + bool use_oci() const; + bool use_auth() const; + const std::string& filename() const; + std::string channel() const; + std::string url_path() const; + const std::string& url() const; + const std::string& sha256() const; + const std::string& md5() const; + std::size_t expected_size() const; + + ValidationResult validate_size(std::size_t downloaded_size) const; + ValidationResult validate_checksum(const CheckSumParams& params) const; + + void write_repodata_record(const fs::u8path& base_path) const; + void update_urls_txt() const; + + void update_monitor(progress_callback_t* cb, PackageExtractEvent event) const; + + specs::PackageInfo m_package_info; + + fs::u8path m_tarball_path; + fs::u8path m_cache_path; + + bool m_needs_download = false; + std::string m_downloaded_url = {}; + bool m_needs_extract = false; + }; + + class PackageFetcherSemaphore + { + public: + + static std::ptrdiff_t get_max(); + static void set_max(int value); + + private: + + static counting_semaphore semaphore; + + friend class PackageFetcher; + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/package_handling.hpp b/data/miniconda3/include/mamba/core/package_handling.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b1522d413c67f629b4497e519c4ae5a2d7a5c294 --- /dev/null +++ b/data/miniconda3/include/mamba/core/package_handling.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PACKAGE_HANDLING_HPP +#define MAMBA_CORE_PACKAGE_HANDLING_HPP + +#include +#include +#include + +#include "mamba/fs/filesystem.hpp" + +namespace mamba +{ + struct ValidationParams; + class Context; + + // Determine the kind of command line to run to extract subprocesses. + enum class extract_subproc_mode + { + /** An external binary packaged with `libmamba` to launch as a subprocess. */ + mamba_package, + /** The mamba or micromamba executable calling itself. */ + mamba_exe, + }; + + struct ExtractOptions + { + bool sparse = false; + extract_subproc_mode subproc_mode; + static ExtractOptions from_context(const Context&); + }; + + enum compression_algorithm + { + none, + bzip2, + zip, + zstd + }; + + void create_archive( + const fs::u8path& directory, + const fs::u8path& destination, + compression_algorithm, + int compression_level, + int compression_threads, + bool (*filter)(const fs::u8path&) + ); + void create_package( + const fs::u8path& directory, + const fs::u8path& out_file, + int compression_threads, + int compression_level + ); + + void + extract_archive(const fs::u8path& file, const fs::u8path& destination, const ExtractOptions& options); + void extract_conda( + const fs::u8path& file, + const fs::u8path& dest_dir, + const ExtractOptions& options, + const std::vector& parts = { "info", "pkg" } + ); + void + extract(const fs::u8path& file, const fs::u8path& destination, const ExtractOptions& options); + fs::u8path extract(const fs::u8path& file, const ExtractOptions& options); + + + void + extract_subproc(const fs::u8path& file, const fs::u8path& dest, const ExtractOptions& options); + + bool transmute( + const fs::u8path& pkg_file, + const fs::u8path& target, + int compression_level, + int compression_threads, + const ExtractOptions& options + ); + + bool validate(const fs::u8path& pkg_folder, const ValidationParams& params); + +} // namespace mamba + +#endif // MAMBA_PACKAGE_HANDLING_HPP diff --git a/data/miniconda3/include/mamba/core/package_paths.hpp b/data/miniconda3/include/mamba/core/package_paths.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ceb247949a0d46aa4472aa4eae9f59e973db576d --- /dev/null +++ b/data/miniconda3/include/mamba/core/package_paths.hpp @@ -0,0 +1,70 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_READ_PATHS_HPP +#define MAMBA_CORE_READ_PATHS_HPP + +#include +#include +#include +#include + +#include "util.hpp" + +const char PREFIX_PLACEHOLDER_1[] = "/opt/anaconda1anaconda2"; +// this is intentionally split into parts, such that running +// this program on itself will leave it unchanged +const char PREFIX_PLACEHOLDER_2[] = "anaconda3"; + +namespace mamba +{ + struct PrefixFileParse + { + std::string placeholder; + std::string file_mode; + std::string file_path; + }; + + enum class PathType + { + UNDEFINED, + HARDLINK, + SOFTLINK, + DIRECTORY, + + // These should not occur in a package, only after installation + LINKED_PACKAGE_RECORD, + PYC_FILE, + UNIX_PYTHON_ENTRY_POINT, + WINDOWS_PYTHON_ENTRY_POINT_SCRIPT, + WINDOWS_PYTHON_ENTRY_POINT_EXE + }; + + enum class FileMode + { + UNDEFINED, + BINARY, + TEXT + }; + + struct PathData + { + std::string path; + PathType path_type = PathType::UNDEFINED; + std::string sha256; + std::size_t size_in_bytes = 0; + + std::string prefix_placeholder; + FileMode file_mode = FileMode::TEXT; + bool no_link = false; + }; + + std::map read_has_prefix(const fs::u8path& path); + std::set read_no_link(const fs::u8path& info_dir); + std::vector read_paths(const fs::u8path& directory); +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/palette.hpp b/data/miniconda3/include/mamba/core/palette.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1eec8c2f13258b95d95ca4d962598b11936e7431 --- /dev/null +++ b/data/miniconda3/include/mamba/core/palette.hpp @@ -0,0 +1,80 @@ +// Copyright (c) 2022, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PALETTE_HPP +#define MAMBA_CORE_PALETTE_HPP + +#include + +namespace mamba +{ + struct Palette + { + /** Something that is possible or exists. */ + fmt::text_style success; + /** Something that is impossible or does not exist. */ + fmt::text_style failure; + /** Refers to external ecosystem. */ + fmt::text_style external; + /** Information that was already shown (for. */ + fmt::text_style shown; + /** Some action is safe or trusted. */ + fmt::text_style safe; + /** Some action is unsafe or not trusted. */ + fmt::text_style unsafe; + + /** Reference to some input from the user. */ + fmt::text_style user; + /** Input from the user was ignored or has no effect. */ + fmt::text_style ignored; + /** Something was added due to user input. */ + fmt::text_style addition; + /** Something was removed due to user input. */ + fmt::text_style deletion; + + /** The color of an empty progress bar. */ + fmt::text_style progress_bar_none; + /** The color of the downloaded items in the progress bar. */ + fmt::text_style progress_bar_downloaded; + /** The color of the extracted items in the progress bar. */ + fmt::text_style progress_bar_extracted; + + /** A Palette with no colors at all. */ + static constexpr auto no_color() -> Palette; + /** A Palette with terminal 4 bit colors. */ + static constexpr auto terminal() -> Palette; + }; + + /******************************* + * Implementation of Palette * + *******************************/ + + inline constexpr auto Palette::no_color() -> Palette + { + return {}; + } + + inline constexpr auto Palette::terminal() -> Palette + { + return { + /* .success= */ fmt::fg(fmt::terminal_color::green), + /* .failure= */ fmt::fg(fmt::terminal_color::red), + /* .external= */ fmt::fg(fmt::terminal_color::cyan), + /* .shown= */ fmt::fg(fmt::terminal_color::bright_black), + /* .safe= */ fmt::fg(fmt::terminal_color::green), + /* .unsafe= */ fmt::fg(fmt::terminal_color::red), + /* .user= */ fmt::fg(fmt::terminal_color::blue) | fmt::emphasis::bold, + /* .ignored= */ fmt::fg(fmt::terminal_color::yellow), + /* .addition= */ fmt::fg(fmt::terminal_color::green), + /* .deletion= */ fmt::fg(fmt::terminal_color::red), + /* .progress_bar_none= */ fmt::fg(fmt::terminal_color::bright_black), + /* .progress_bar_downloaded= */ fmt::fg(fmt::terminal_color::yellow), + /* .progress_bar_extracted= */ {}, + }; + } + +} +#endif diff --git a/data/miniconda3/include/mamba/core/pinning.hpp b/data/miniconda3/include/mamba/core/pinning.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9c121f30eb2a9cd98feab0bf0de12e32614b5b4d --- /dev/null +++ b/data/miniconda3/include/mamba/core/pinning.hpp @@ -0,0 +1,29 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PINNING_HPP +#define MAMBA_CORE_PINNING_HPP + +#include +#include + +namespace mamba +{ + class Context; + class ChannelContext; + class PrefixData; + + namespace fs + { + class u8path; + } + + std::string python_pin(PrefixData& prefix_data, const std::vector& specs); + + std::vector file_pins(const fs::u8path& file); +} + +#endif diff --git a/data/miniconda3/include/mamba/core/prefix_data.hpp b/data/miniconda3/include/mamba/core/prefix_data.hpp new file mode 100644 index 0000000000000000000000000000000000000000..15e796de4c9a4105b868c2c53ce8871b95a019d2 --- /dev/null +++ b/data/miniconda3/include/mamba/core/prefix_data.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PREFIX_DATA_HPP +#define MAMBA_CORE_PREFIX_DATA_HPP + +#include +#include + +#include "mamba/core/error_handling.hpp" +#include "mamba/core/history.hpp" +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + class ChannelContext; + + class PrefixData + { + public: + + using package_map = std::map; + + static expected_t + create(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip = false); + + void add_packages(const std::vector& packages); + void load_single_record(const fs::u8path& path); + + const package_map& records() const; + const package_map& pip_records() const; + package_map all_pkg_mgr_records() const; + + History& history(); + const fs::u8path& path() const; + std::vector sorted_records() const; + + ChannelContext& channel_context() const + { + return m_channel_context; + } + + private: + + PrefixData(const fs::u8path& prefix_path, ChannelContext& channel_context, bool no_pip); + + void load_site_packages(); + + History m_history; + package_map m_package_records; + package_map m_pip_package_records; + fs::u8path m_prefix_path; + + ChannelContext& m_channel_context; + }; +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/progress_bar.hpp b/data/miniconda3/include/mamba/core/progress_bar.hpp new file mode 100644 index 0000000000000000000000000000000000000000..c32524a8fe567a25157e39d1afc528958b79882c --- /dev/null +++ b/data/miniconda3/include/mamba/core/progress_bar.hpp @@ -0,0 +1,100 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PROGRESS_BAR_HPP +#define MAMBA_CORE_PROGRESS_BAR_HPP + +#include +#include +#include +#include + +namespace mamba +{ + class ProgressBar; + struct ProgressBarOptions; + // TODO: find a way to define it here without + // impoorting spdlog and modst of the STL. + class ProgressBarRepr; + + enum ProgressBarMode + { + multi, + aggregated + }; + + class ProgressProxy + { + public: + + ProgressProxy() = default; + ProgressProxy(ProgressBar* ptr); + ~ProgressProxy() = default; + + ProgressProxy(const ProgressProxy&) = default; + ProgressProxy& operator=(const ProgressProxy&) = default; + ProgressProxy(ProgressProxy&&) = default; + ProgressProxy& operator=(ProgressProxy&&) = default; + + bool defined() const; + operator bool() const; + ProgressProxy& set_bar(ProgressBar* ptr); + + ProgressProxy& set_progress(std::size_t current, std::size_t total); + ProgressProxy& update_progress(std::size_t current, std::size_t total); + ProgressProxy& set_progress(double progress); + ProgressProxy& set_current(std::size_t current); + ProgressProxy& set_in_progress(std::size_t in_progress); + ProgressProxy& update_current(std::size_t current); + ProgressProxy& set_total(std::size_t total); + ProgressProxy& set_speed(std::size_t speed); + ProgressProxy& set_full(); + ProgressProxy& activate_spinner(); + ProgressProxy& deactivate_spinner(); + + std::size_t current() const; + std::size_t in_progress() const; + std::size_t total() const; + std::size_t speed() const; + std::size_t + avg_speed(const std::chrono::milliseconds& ref_duration = std::chrono::milliseconds::max()); + double progress() const; + bool completed() const; + + ProgressProxy& set_prefix(const std::string& text); + ProgressProxy& set_postfix(const std::string& text); + ProgressProxy& set_repr_hook(std::function f); + ProgressProxy& set_progress_hook(std::function f); + ProgressProxy& + mark_as_completed(const std::chrono::milliseconds& delay = std::chrono::milliseconds::zero()); + + std::string elapsed_time_to_str() const; + std::string prefix() const; + + ProgressBarRepr& update_repr(bool compute_progress = true); + const ProgressBarRepr& repr() const; + ProgressBarRepr& repr(); + ProgressProxy& print(std::ostream& stream, std::size_t width = 0, bool with_endl = true); + + ProgressProxy& start(); + ProgressProxy& pause(); + ProgressProxy& resume(); + ProgressProxy& stop(); + + bool started() const; + + int width() const; + const ProgressBarOptions& options() const; + + private: + + ProgressBar* p_bar = nullptr; + + friend class ProgressBarManager; + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/query.hpp b/data/miniconda3/include/mamba/core/query.hpp new file mode 100644 index 0000000000000000000000000000000000000000..171b0432863383cf202085441ccb44056085512d --- /dev/null +++ b/data/miniconda3/include/mamba/core/query.hpp @@ -0,0 +1,125 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_QUERY_HPP +#define MAMBA_CORE_QUERY_HPP + +#include +#include +#include +#include +#include + +#include "mamba/core/context.hpp" +#include "mamba/specs/package_info.hpp" +#include "mamba/util/graph.hpp" + +namespace mamba +{ + namespace solver::libsolv + { + class Database; + } + + enum class QueryType + { + Search, + Depends, + WhoNeeds + }; + + constexpr auto enum_name(QueryType t) -> std::string_view; + + auto query_type_parse(std::string_view name) -> QueryType; + + class QueryResult + { + public: + + using GraphicsParams = Context::GraphicsParams; + using dependency_graph = util::DiGraph; + + QueryResult(QueryType type, std::string query, dependency_graph dep_graph); + QueryResult(const QueryResult&) = default; + QueryResult(QueryResult&&) = default; + + ~QueryResult() = default; + + auto operator=(const QueryResult&) -> QueryResult& = default; + auto operator=(QueryResult&&) -> QueryResult& = default; + + [[nodiscard]] auto type() const -> QueryType; + [[nodiscard]] auto query() const -> const std::string&; + [[nodiscard]] auto empty() const -> bool; + + auto sort(std::string_view field) -> QueryResult&; + + auto groupby(std::string_view field) -> QueryResult&; + + auto reset() -> QueryResult&; + + auto table(std::ostream&) const -> std::ostream&; + auto table(std::ostream&, const std::vector& fmt) const -> std::ostream&; + [[nodiscard]] auto table_to_str() const -> std::string; + + auto tree(std::ostream&, const GraphicsParams& graphics) const -> std::ostream&; + [[nodiscard]] auto tree_to_str(const GraphicsParams& graphics) const -> std::string; + + [[nodiscard]] auto json() const -> nlohmann::json; + + auto pretty(std::ostream&, bool show_all_builds) const -> std::ostream&; + [[nodiscard]] auto pretty_to_str(bool show_all_builds) const -> std::string; + + private: + + using node_id = dependency_graph::node_id; + using package_id_list = std::vector; + using ordered_package_list = std::map; + + void reset_pkg_view_list(); + + QueryType m_type; + std::string m_query; + dependency_graph m_dep_graph; + package_id_list m_pkg_id_list = {}; + ordered_package_list m_ordered_pkg_id_list = {}; + }; + + class Query + { + public: + + using Database = solver::libsolv::Database; + + [[nodiscard]] static auto find(Database& database, const std::vector& queries) + -> QueryResult; + + [[nodiscard]] static auto whoneeds(Database& database, std::string query, bool tree) + -> QueryResult; + + [[nodiscard]] static auto depends(Database& database, std::string query, bool tree) + -> QueryResult; + }; + + /******************** + * Implementation * + ********************/ + + constexpr auto enum_name(QueryType t) -> std::string_view + { + switch (t) + { + case QueryType::Search: + return "Search"; + case QueryType::WhoNeeds: + return "WhoNeeds"; + case QueryType::Depends: + return "Depends"; + } + throw std::invalid_argument("Invalid enum value"); + } +} +#endif diff --git a/data/miniconda3/include/mamba/core/repo_checker_store.hpp b/data/miniconda3/include/mamba/core/repo_checker_store.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6fe603e305a11d95cd46842a955b3921d7816e38 --- /dev/null +++ b/data/miniconda3/include/mamba/core/repo_checker_store.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2024, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_REPO_CHECKER_STORE_HPP +#define MAMBA_CORE_REPO_CHECKER_STORE_HPP + +#include +#include + +#include "mamba/specs/channel.hpp" +#include "mamba/validation/repo_checker.hpp" + +namespace mamba +{ + class Context; + class ChannelContext; + class MultiPackageCache; + + class RepoCheckerStore + { + public: + + using Channel = specs::Channel; + using RepoChecker = validation::RepoChecker; + using repo_checker_list = std::vector>; + + [[nodiscard]] static auto + make(const Context& ctx, ChannelContext& cc, MultiPackageCache& caches) -> RepoCheckerStore; + + explicit RepoCheckerStore(repo_checker_list checkers); + + [[nodiscard]] auto find_checker(const Channel& chan) -> RepoChecker*; + + [[nodiscard]] auto contains_checker(const Channel& chan) -> bool; + + [[nodiscard]] auto at_checker(const Channel& chan) -> RepoChecker&; + + private: + + repo_checker_list m_repo_checkers = {}; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/core/run.hpp b/data/miniconda3/include/mamba/core/run.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1af3c1fc2124dd0928358d4c4ebffe0c91e2361e --- /dev/null +++ b/data/miniconda3/include/mamba/core/run.hpp @@ -0,0 +1,66 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#include +#include + +#include + +#include "mamba/core/util.hpp" +#include "mamba/fs/filesystem.hpp" + +namespace mamba +{ + class Context; + + bool is_process_name_running(const std::string& name); + std::string generate_unique_process_name(std::string_view program_name); + const fs::u8path& proc_dir(); + LockFile lock_proc_dir(); + + void daemonize(); + + class ScopedProcFile + { + const fs::u8path location; + + public: + + ScopedProcFile( + const Context& context, + const std::string& name, + const std::vector& command, + LockFile proc_dir_lock = lock_proc_dir() + ); + ~ScopedProcFile(); + }; + + enum class STREAM_OPTIONS : int + { + ALL_STREAMS = 0, + SINKOUT = 1, + SINKERR = 1 << 1, + SINKIN = 1 << 2, + }; + + int run_in_environment( + const Context& context, + const fs::u8path& prefix, + std::vector command, + const std::string& cwd, + int stream_options, + bool clean_env, + bool detach, + const std::vector& env_vars, + const std::string& specific_process_name + ); + + nlohmann::json get_all_running_processes_info( + const std::function& filter = std::function< + bool(const nlohmann::json&)>() + ); + bool is_process_name_running(const std::string& name); +} diff --git a/data/miniconda3/include/mamba/core/shell_init.hpp b/data/miniconda3/include/mamba/core/shell_init.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f8b15b7fccd23e2444c8b86410ed9d096db09630 --- /dev/null +++ b/data/miniconda3/include/mamba/core/shell_init.hpp @@ -0,0 +1,90 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_SHELL_INIT +#define MAMBA_CORE_SHELL_INIT + +#include +#include +#include + +#include "mamba/fs/filesystem.hpp" + +extern const char data_mamba_sh[]; +extern const char data_mamba_csh[]; +extern const char data_mamba_bat[]; +extern const char data_activate_bat[]; +extern const char data__mamba_activate_bat[]; +extern const char data_mamba_hook_bat[]; +extern const char data_mamba_hook_ps1[]; +extern const char data_Mamba_psm1[]; +extern const char data_mamba_xsh[]; +extern const char data_mamba_fish[]; +extern const char data_mamba_completion_posix[]; + +namespace mamba +{ + class Context; + + std::string guess_shell(); + +#ifdef _WIN32 + void init_cmd_exe_registry( + const Context& context, + const std::wstring& reg_path, + const fs::u8path& conda_prefix + ); +#endif + + std::string get_hook_contents(const Context& context, const std::string& shell); + + // this function calls cygpath to convert win path to unix + std::string native_path_to_unix(const std::string& path, bool is_a_path_env = false); + + std::string + rcfile_content(const fs::u8path& env_prefix, std::string_view shell, const fs::u8path& mamba_exe); + + std::string + xonsh_content(const fs::u8path& env_prefix, const std::string& shell, const fs::u8path& mamba_exe); + + void modify_rc_file( + const Context& context, + const fs::u8path& file_path, + const fs::u8path& conda_prefix, + const std::string& shell, + const fs::u8path& mamba_exe + ); + + void reset_rc_file( + const Context& context, + const fs::u8path& file_path, + const std::string& shell, + const fs::u8path& mamba_exe + ); + + // we need this function during linking... + void init_root_prefix_cmdexe(const fs::u8path& root_prefix); + void deinit_root_prefix_cmdexe(const Context& context, const fs::u8path& root_prefix); + void init_root_prefix(Context& context, const std::string& shell, const fs::u8path& root_prefix); + void + deinit_root_prefix(Context& context, const std::string& shell, const fs::u8path& root_prefix); + + std::string powershell_contents(const fs::u8path& conda_prefix); + void + init_powershell(const Context& context, const fs::u8path& profile_path, const fs::u8path& conda_prefix); + void deinit_powershell( + const Context& context, + const fs::u8path& profile_path, + const fs::u8path& conda_prefix + ); + + void init_shell(Context& context, const std::string& shell, const fs::u8path& conda_prefix); + void deinit_shell(Context& context, const std::string& shell, const fs::u8path& conda_prefix); + std::vector find_initialized_shells(); + +} + +#endif diff --git a/data/miniconda3/include/mamba/core/subdir_index.hpp b/data/miniconda3/include/mamba/core/subdir_index.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4bf9f54a9c0dbf0e4d5d81aaf82babe19a933c13 --- /dev/null +++ b/data/miniconda3/include/mamba/core/subdir_index.hpp @@ -0,0 +1,418 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_SUBDIRDATA_HPP +#define MAMBA_CORE_SUBDIRDATA_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/core/error_handling.hpp" +#include "mamba/core/package_cache.hpp" +#include "mamba/core/subdir_parameters.hpp" +#include "mamba/download/downloader.hpp" +#include "mamba/download/parameters.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/specs/channel.hpp" +#include "mamba/specs/conda_url.hpp" +#include "mamba/specs/platform.hpp" + +namespace mamba +{ + namespace specs + { + class Channel; + } + + /** + * Handling of a subdirectory metadata. + * + * These metadata are used and stored to check if a subdirectory index is up to date, + * where it comes from, and what protocols are supported to fetch it. + */ + class SubdirMetadata + { + public: + + struct HttpMetadata + { + std::string url; + std::string etag; + std::string last_modified; + std::string cache_control; + }; + + using expected_subdir_metadata = tl::expected; + + /** Read the metadata from a lightweight file containing only these metadata. */ + static auto read_state_file( // + const fs::u8path& state_file, + const fs::u8path& repodata_file + ) -> expected_subdir_metadata; + + /** Read the metadata from the ``repodata.json`` header. */ + static auto read_from_repodata_json(const fs::u8path& json) -> expected_subdir_metadata; + + /** Read from any of state file or ``repodata.json`` depending on extension. */ + static auto read(const fs::u8path& file) -> expected_subdir_metadata; + + [[nodiscard]] auto is_valid_metadata(const fs::u8path& file) const -> bool; + [[nodiscard]] auto url() const -> const std::string&; + [[nodiscard]] auto etag() const -> const std::string&; + [[nodiscard]] auto last_modified() const -> const std::string&; + [[nodiscard]] auto cache_control() const -> const std::string&; + + /** Check if zst is available and freshly checked. */ + [[nodiscard]] auto has_up_to_date_zst() const -> bool; + + void set_http_metadata(HttpMetadata data); + void set_zst(bool value); + void store_file_metadata(const fs::u8path& file); + + /** Write the metadata to a lightweight file. */ + void write_state_file(const fs::u8path& file); + + friend void to_json(nlohmann::json& j, const SubdirMetadata& data); + friend void from_json(const nlohmann::json& j, SubdirMetadata& data); + + private: + +#ifdef _WIN32 + using time_type = std::chrono::system_clock::time_point; +#else + using time_type = fs::file_time_type; +#endif + + struct CheckedAt + { + bool value; + std::time_t last_checked; + + bool has_expired() const; + }; + + HttpMetadata m_http; + std::optional m_has_zst; + time_type m_stored_mtime; + std::size_t m_stored_file_size; + + friend void to_json(nlohmann::json& j, const CheckedAt& ca); + friend void from_json(const nlohmann::json& j, CheckedAt& ca); + }; + + /** + * Channel sub-directory (i.e. a platform) packages index. + * + * Handles downloading of the index from the server and cache generation. + * This only handles traditional ``repodata.json`` full indexes. + * This abstraction does not load the index in memory, with is done by the @ref Database. + * + * Upon creation, the caches are checked for a valid and up to date index. + * This can be inspected with @ref valid_cache_found. + * The created subdirs are typically used with @ref SubdirIndexLoader::download_required_indexes + * which will download the missing, invalid, or outdated indexes as needed. + */ + class SubdirIndexLoader + { + public: + + /** + * Download the missing, invalid, or outdated indexes as needed in parallel. + * + * It first creates check requests to update some metadata, then download the indexes. + * The result can be inspected with the input subdirs methods, such as + * @ref valid_cache_found, @ref valid_json_cache_path etc. + */ + template + [[nodiscard]] static auto download_required_indexes( + SubdirIter1 subdirs_first, + SubdirIter2 subdirs_last, + const SubdirDownloadParams& subdir_params, + const specs::AuthenticationDataBase& auth_info, + const download::mirror_map& mirrors, + const download::Options& download_options, + const download::RemoteFetchParams& remote_fetch_params, + download::Monitor* check_monitor = nullptr, + download::Monitor* download_monitor = nullptr + ) -> expected_t; + template + [[nodiscard]] static auto download_required_indexes( + Subdirs& subdirs, + const SubdirDownloadParams& subdir_params, + const specs::AuthenticationDataBase& auth_info, + const download::mirror_map& mirrors, + const download::Options& download_options, + const download::RemoteFetchParams& remote_fetch_params, + download::Monitor* check_monitor = nullptr, + download::Monitor* download_monitor = nullptr + ) -> expected_t; + + /** Check existing caches for a valid index validity and freshness. */ + static auto create( + const SubdirParams& params, + specs::Channel channel, + specs::DynamicPlatform platform, + MultiPackageCache& caches, + std::string repodata_filename = "repodata.json" + ) -> expected_t; + + [[nodiscard]] auto is_noarch() const -> bool; + [[nodiscard]] auto is_local() const -> bool; + [[nodiscard]] auto channel() const -> const specs::Channel&; + [[nodiscard]] auto name() const -> std::string; + [[nodiscard]] auto channel_id() const -> const std::string&; + [[nodiscard]] auto platform() const -> const specs::DynamicPlatform&; + [[nodiscard]] auto metadata() const -> const SubdirMetadata&; + [[nodiscard]] auto repodata_url() const -> specs::CondaURL; + + [[nodiscard]] auto caching_is_forbidden() const -> bool; + [[nodiscard]] auto valid_cache_found() const -> bool; + [[nodiscard]] auto valid_libsolv_cache_path() const -> expected_t; + [[nodiscard]] auto writable_libsolv_cache_path() const -> fs::u8path; + [[nodiscard]] auto valid_json_cache_path() const -> expected_t; + + void clear_valid_cache_files(); + + private: + + // This paths are pointing to what is found when iterating over the cache directories. + // The expired found is the first one, which could be improved by keeping the freshest one. + // This could improve caching in some HTTP 304 cases. + // A possible improvement would be to keep all path, metadatas, and writable status in a + // single vector and sort them by recency. + // This would also give a public option for `clear`-ing all writable caches, not just the + // valid one. + SubdirMetadata m_metadata; + specs::Channel m_channel; + fs::u8path m_valid_cache_path; + std::optional m_expired_cache_path; + fs::u8path m_writable_pkgs_dir; + specs::DynamicPlatform m_platform; + std::string m_repodata_filename; + std::string m_json_filename; + std::string m_solv_filename; + bool m_valid_cache_found = false; + bool m_json_cache_valid = false; + bool m_solv_cache_valid = false; + + SubdirIndexLoader( + const SubdirParams& params, + specs::Channel channel, + std::string platform, + MultiPackageCache& caches, + std::string repodata_fn = "repodata.json" + ); + + [[nodiscard]] auto repodata_url_path() const -> std::string; + [[nodiscard]] auto valid_json_cache_path_unchecked() const -> fs::u8path; + [[nodiscard]] auto valid_state_file_path_unchecked() const -> fs::u8path; + [[nodiscard]] auto valid_libsolv_cache_path_unchecked() const -> fs::u8path; + + /********************************************************* + * Implementation details of SubdirIndexLoader::create * + *********************************************************/ + + void load(const MultiPackageCache& caches, const SubdirParams& params); + void load_cache(const MultiPackageCache& caches, const SubdirParams& params); + + /**************************************************************************** + * Implementation details of SubdirIndexLoader::download_required_indexes * + ****************************************************************************/ + + auto use_existing_cache() -> expected_t; + auto finalize_transfer(SubdirMetadata::HttpMetadata http_data, const fs::u8path& artifact) + -> expected_t; + void refresh_last_write_time(const fs::u8path& json_file, const fs::u8path& solv_file); + + template + static auto + build_all_check_requests(First subdirs_first, End subdirs_last, const SubdirDownloadParams& params) + -> download::MultiRequest; + auto build_check_requests(const SubdirDownloadParams& params) -> download::MultiRequest; + + template + static auto + build_all_index_requests(First subdirs_first, End subdirs_last, const SubdirDownloadParams& params) + -> download::MultiRequest; + auto build_index_request(const SubdirDownloadParams& params) + -> std::optional; + + [[nodiscard]] static auto download_requests( + download::MultiRequest index_requests, + const specs::AuthenticationDataBase& auth_info, + const download::mirror_map& mirrors, + const download::Options& download_options, + const download::RemoteFetchParams& remote_fetch_params, + download::Monitor* download_monitor + ) -> expected_t; + }; + + /** + * Compute an id from a URL. + * + * This is intended to keep unique, filesystem-safe, cache entries in the cache directory. + * @see cache_filename_from_url + */ + [[nodiscard]] auto cache_name_from_url(std::string url) -> std::string; + + /** + * Compute a filename from a URL. + * + * This is intended to keep unique, filesystem-safe, cache entries in the cache directory. + * Contrary to conda original function, this one expects a full url (that is + * channel url + / + repodata_fn). + * It is not the responsibility of this function to decide whether it should concatenate base + * url and repodata depending on repodata value and old behavior support. + */ + [[nodiscard]] auto cache_filename_from_url(std::string url) -> std::string; + + /** + * Create cache directory with correct permissions + * + * @return The path to the directory created + */ + auto create_cache_dir(const fs::u8path& cache_path) -> std::string; + + /***************************************** + * Implementation of SubdirIndexLoader * + *****************************************/ + + template + auto SubdirIndexLoader::download_required_indexes( + SubdirIter1 subdirs_first, + SubdirIter2 subdirs_last, + const SubdirDownloadParams& subdir_params, + const specs::AuthenticationDataBase& auth_info, + const download::mirror_map& mirrors, + const download::Options& download_options, + const download::RemoteFetchParams& remote_fetch_params, + download::Monitor* check_monitor, + download::Monitor* download_monitor + ) -> expected_t + { + auto result = download_requests( + build_all_check_requests(subdirs_first, subdirs_last, subdir_params), + auth_info, + mirrors, + download_options, + remote_fetch_params, + check_monitor + ); + + // Allow to continue if failed checks, unless asked to stop. + constexpr auto is_interrupted = [](const auto& e) + { return e.error_code() == mamba_error_code::user_interrupted; }; + + if (!result.has_value() && result.map_error(is_interrupted).error()) + { + return result; + } + + return download_requests( + build_all_index_requests(subdirs_first, subdirs_last, subdir_params), + auth_info, + mirrors, + download_options, + remote_fetch_params, + download_monitor + ); + } + + template + auto SubdirIndexLoader::download_required_indexes( + Subdirs& subdirs, + const SubdirDownloadParams& subdir_params, + const specs::AuthenticationDataBase& auth_info, + const download::mirror_map& mirrors, + const download::Options& download_options, + const download::RemoteFetchParams& remote_fetch_params, + download::Monitor* check_monitor, + download::Monitor* download_monitor + ) -> expected_t + { + return download_required_indexes( + subdirs.begin(), + subdirs.end(), + subdir_params, + auth_info, + mirrors, + download_options, + remote_fetch_params, + check_monitor, + download_monitor + ); + } + + template + auto SubdirIndexLoader::build_all_check_requests( + First subdirs_first, + End subdirs_last, + const SubdirDownloadParams& params + ) -> download::MultiRequest + { + download::MultiRequest requests; + for (; subdirs_first != subdirs_last; ++subdirs_first) + { + // TODO(C++23): We make a special handling of iterators of pointers due to the + // difficulty and necessity to create a range of references from Python objects. + SubdirIndexLoader* p_subdir = nullptr; + if constexpr (std::is_pointer_v>) + { + p_subdir = *subdirs_first; + } + else + { + p_subdir = &(*subdirs_first); + } + + if (p_subdir != nullptr && !p_subdir->valid_cache_found()) + { + auto check_list = p_subdir->build_check_requests(params); + std::move(check_list.begin(), check_list.end(), std::back_inserter(requests)); + } + } + return requests; + } + + template + auto SubdirIndexLoader::build_all_index_requests( + First subdirs_first, + End subdirs_last, + const SubdirDownloadParams& params + ) -> download::MultiRequest + { + download::MultiRequest requests; + for (; subdirs_first != subdirs_last; ++subdirs_first) + { + // TODO(C++23): We make a special handling of iterators of pointers due to the + // difficulty and necessity to create a range of references from Python objects. + SubdirIndexLoader* p_subdir = nullptr; + if constexpr (std::is_pointer_v>) + { + p_subdir = *subdirs_first; + } + else + { + p_subdir = &(*subdirs_first); + } + + if (!p_subdir->valid_cache_found()) + { + if (auto request = p_subdir->build_index_request(params)) + { + requests.push_back(*std::move(request)); + } + } + } + return requests; + } + +} +#endif diff --git a/data/miniconda3/include/mamba/core/subdir_parameters.hpp b/data/miniconda3/include/mamba/core/subdir_parameters.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f2ccb2972090e4117edd7b7301d4f9350c05eb3a --- /dev/null +++ b/data/miniconda3/include/mamba/core/subdir_parameters.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2025, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_SUBDIR_PARAMETERS_HPP +#define MAMBA_CORE_SUBDIR_PARAMETERS_HPP + +#include + +namespace mamba +{ + struct SubdirParams + { + /** + * Repodata cache time to live in seconds. + * + * If not specified, then it is read from server headers. + */ + std::optional local_repodata_ttl_s = std::nullopt; + bool offline = false; + /** Force the use of zst for this subdir without checking. */ + bool repodata_force_use_zst = false; + }; + + struct SubdirDownloadParams + { + bool offline = false; + /** Make a request to check the use of zst compression format. */ + bool repodata_check_zst = true; + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/tasksync.hpp b/data/miniconda3/include/mamba/core/tasksync.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dcb5224a64f07d52b258baed73623a074529bbc1 --- /dev/null +++ b/data/miniconda3/include/mamba/core/tasksync.hpp @@ -0,0 +1,225 @@ +// Copyright (c) 2022, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "mamba/core/util_scope.hpp" + +namespace mamba +{ + + // WARNING: this file will be moved to xtl as soon as possible, do not rely on it's existence + // here! + + /** Synchronize tasks execution in multiple threads with this object's lifetime. + + A synchronized callable will never execute outside the lifetime of this object. + To achieve this, the callable must be wrapped into a callable with the same + features that will guarantee that + - if this object have been destroyed and then the synchronized callable is invoked, + the callable will not execute it's code; + - if this object is being joined and/or destroyed, it will block until any already started + tasks are ended; + + WARNING: When used as a member of a type to synchronized tasks of the `this` instance, it is + best to set the TaskSynchronizer as the last member so that it is the first one to be + destroyed; alternatively, `.join_tasks()` can be called manually in the destructor too. + + Example: + + class MonSystem + { + public: + + // Whatever "scheduler" or "other_sys" is.... + MonSystem(Scheduler scheduler, OtherSystem other_sys) : scheduler(sccheduler) + { + // This callback will do nothing if this object is destroyed. + other_sys.on_something(synchronized.synchronized([this]{ ok(); })); + } + + void ok(); + + void launch_work() + { + // This task will do nothing if this object is destroyed. + scheduler.push(task_sync.synchronized([this]{ + ... + })); + } + + private: + + Scheduler scheduler; + BigData data; + + task_synchronizer task_sync; // When this object is destroyed, join tasks. + }; + + */ + class TaskSynchronizer + { + auto make_remote_status() + { + return std::weak_ptr{ m_status }; + } + + public: + + TaskSynchronizer() = default; + + /** Destructor, joining tasks synchronized with this object. + @see join_tasks() + */ + ~TaskSynchronizer() + { + join_tasks(); + } + + TaskSynchronizer(const TaskSynchronizer&) = delete; + TaskSynchronizer& operator=(const TaskSynchronizer&) = delete; + + TaskSynchronizer(TaskSynchronizer&& other) noexcept = delete; + TaskSynchronizer& operator=(TaskSynchronizer&& other) noexcept = delete; + + /** Wrap the provided callable into a similar but synchronized callable. + + The wrapper guarantees that if the resulting callable is invoked: + - if the joining function of this synchronizer have been called, skip execution; + - if the joining function of this synchronizer is called while the callback is + invoked, it will block until the end of the body of the original callable; + - if no joining function have been called yet, notify the synchronizer that the + execution begins, then execute the body; + + @param work Any callable object with no arguments. The return value will be ignored. + @return A wrapped version of the provided callable object, adding checks + preventing execution of the original callable body if any joining function + of this synchronizer was called. + */ + template + auto synchronized(Work&& work) + { + return [this, + new_work = std::forward(work), + remote_status = make_remote_status()](auto&&... args) mutable + { + // If status is alive then we know the TaskSynchronizer is alive too. + auto status = remote_status.lock(); + if (status && !status->join_requested) // Don't add running tasks while join was + // requested. + { // We can use 'this' safely in this scope. + notify_begin_execution(); + on_scope_exit _{ [&, this] + { + status.reset(); // Make sure we are not keeping the + // TaskSynchronizer waiting + notify_end_execution(); + } }; + std::invoke(new_work, std::forward(args)...); + } + }; + } + + /** Notify all synchronized tasks and blocks until all already started synchronized tasks + are done. + + This is a joining function: once it is called, no synchronized task body will be + executed again. Synchronized tasks which body is being executed will notify this + synchronizer once done. + + Only returns once all the executing tasks have finished finishes. + + After calling this, is_joined() will return true. + */ + void join_tasks() + { + wait_all_running_tasks(); + assert(is_joined()); + } + + /** Join synchronized tasks and reset this object's state to be reusable like if it was just + constructed. + + Similar to calling join_tasks() but is_joined() will return false after calling this. + + @see join_tasks() + */ + void reset() + { + join_tasks(); + m_status = std::make_shared(); + assert(!is_joined()); + } + + /** @return true if all synchronized tasks have been joined, false otherwise. @see + * join_tasks(), reset()*/ + bool is_joined() const + { + return !m_status && m_running_tasks == 0; + } + + /** @return Number of synchronized tasks which are currently being executed. */ + int64_t running_tasks() const + { + return m_running_tasks; + } + + private: + + struct Status + { + std::atomic join_requested{ false }; + }; + + std::atomic m_running_tasks{ 0 }; + + std::shared_ptr m_status = std::make_shared(); + + std::mutex m_mutex; + std::condition_variable m_task_end_condition; + + void notify_begin_execution() + { + ++m_running_tasks; + } + + void notify_end_execution() + { + { + std::unique_lock exit_lock{ m_mutex }; + --m_running_tasks; + } + m_task_end_condition.notify_one(); + } + + void wait_all_running_tasks() + { + if (!m_status) + { + return; + } + + std::unique_lock exit_lock{ m_mutex }; + + auto remote_status = make_remote_status(); + m_status->join_requested = true; + m_status.reset(); + + m_task_end_condition.wait( + exit_lock, + [&] { return m_running_tasks == 0 && remote_status.expired(); } + ); + } + }; + +} diff --git a/data/miniconda3/include/mamba/core/thread_utils.hpp b/data/miniconda3/include/mamba/core/thread_utils.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f915c9aad62efbfcf3034f2d617adf7b93879474 --- /dev/null +++ b/data/miniconda3/include/mamba/core/thread_utils.hpp @@ -0,0 +1,232 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_THREAD_UTILS_HPP +#define MAMBA_CORE_THREAD_UTILS_HPP + +#include +#include +#include +#include +#include +#include +#include + +namespace mamba +{ + + /*********************** + * thread interruption * + ***********************/ + + + using signal_handler_t = void (*)(int); + +#ifndef _WIN32 + void set_signal_handler(const std::function& handler); + + int stop_receiver_thread(); + int kill_receiver_thread(); + void reset_sig_interrupted(); +#endif + + void set_default_signal_handler(); + void restore_previous_signal_handler(); + signal_handler_t previous_signal_handler(); + bool is_sig_interrupted() noexcept; + void set_sig_interrupted() noexcept; + + void interruption_point(); + + class thread_interrupted : public std::exception + { + public: + + thread_interrupted() = default; + + const char* what() const throw() + { + return "Thread interrupted"; + } + }; + + /**************** + * thread count * + ****************/ + + void increase_thread_count(); + void decrease_thread_count(); + int get_thread_count(); + + // Waits until all other threads have finished + // Must be called by the cleaning thread to ensure + // it won't free resources that could be required + // by threads still active. + void wait_for_all_threads(); + + /********** + * thread * + **********/ + + // Thread that increases the threads count upon + // creation and decreases it upon deletion. Use it + // when you need to ensure all threads have exited + class thread + { + public: + + thread() = default; + ~thread() = default; + + thread(const thread&) = delete; + thread& operator=(const thread&) = delete; + + thread(thread&&) noexcept = default; + thread& operator=(thread&&) = default; + + template + explicit thread(Function&& func, Args&&... args); + + bool joinable() const noexcept; + std::thread::id get_id() const noexcept; + + void join(); + void detach(); + std::thread::native_handle_type native_handle(); + + std::thread extract() + { + return std::move(m_thread); + } + + private: + + std::thread m_thread; + }; + + template + inline thread::thread(Function&& func, Args&&... args) + { + increase_thread_count(); + auto f = std::bind(std::forward(func), std::forward(args)...); + m_thread = std::thread( + [f]() + { + try + { + f(); + } + catch (thread_interrupted&) + { + errno = EINTR; + } + decrease_thread_count(); + } + ); + } + + /********************** + * interruption_guard * + **********************/ + + class interruption_guard + { + public: + + template + interruption_guard(Function&& func, Args&&... args); + ~interruption_guard(); + + interruption_guard(const interruption_guard&) = delete; + interruption_guard& operator=(const interruption_guard&) = delete; + + interruption_guard(interruption_guard&&) = delete; + interruption_guard& operator=(interruption_guard&&) = delete; + + private: + + static std::function m_cleanup_function; + }; + + template + inline interruption_guard::interruption_guard(Function&& func, Args&&... args) + { + m_cleanup_function = std::bind(std::forward(func), std::forward(args)...); + } + + class counting_semaphore + { + public: + + inline counting_semaphore(std::ptrdiff_t max = 0); + inline void lock(); + inline void unlock(); + inline std::ptrdiff_t get_max(); + inline void set_max(std::ptrdiff_t value); + + private: + + std::ptrdiff_t m_value, m_max; + std::mutex m_access_mutex; + std::condition_variable m_cv; + }; + + /************************************* + * counting_semaphore implementation * + *************************************/ + + inline counting_semaphore::counting_semaphore(std::ptrdiff_t max) + { + set_max(max); + m_value = m_max; + } + + inline void counting_semaphore::lock() + { + std::unique_lock lock{ m_access_mutex }; + m_cv.wait(lock, [&]() { return m_value > 0; }); + --m_value; + } + + inline void counting_semaphore::unlock() + { + { + std::unique_lock lock{ m_access_mutex }; + if (++m_value <= 0) + { + return; + } + } + m_cv.notify_all(); + } + + inline std::ptrdiff_t counting_semaphore::get_max() + { + return m_max; + } + + inline void counting_semaphore::set_max(std::ptrdiff_t value) + { + std::ptrdiff_t new_max; + if (value == 0) + { + new_max = std::thread::hardware_concurrency(); + } + else if (value < 0) + { + new_max = std::thread::hardware_concurrency() + value; + } + else + { + new_max = value; + } + + m_value += new_max - m_max; + m_max = new_max; + } +} // namespace mamba + +#endif diff --git a/data/miniconda3/include/mamba/core/timeref.hpp b/data/miniconda3/include/mamba/core/timeref.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1019e42f75dbc470267a07a45520ee7568cd41e0 --- /dev/null +++ b/data/miniconda3/include/mamba/core/timeref.hpp @@ -0,0 +1,33 @@ +#ifndef MAMBA_CORE_TIMEREF_HPP +#define MAMBA_CORE_TIMEREF_HPP + +#include +#include + +namespace mamba::validation +{ + + /** Define a time reference. + * TUF 5.1 'Record fixed update start time' + * https://theupdateframework.github.io/specification/latest/#fix-time + */ + class TimeRef + { + public: + + void set(const std::time_t& time); + void set_now(); + std::string timestamp() const; + + TimeRef(const std::time_t& time); + TimeRef(); + ~TimeRef() = default; + + private: + + std::time_t m_time_ref; + }; + +} + +#endif diff --git a/data/miniconda3/include/mamba/core/transaction.hpp b/data/miniconda3/include/mamba/core/transaction.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f6bf5d13738ad57625b28bd94fbefc3fdd58934b --- /dev/null +++ b/data/miniconda3/include/mamba/core/transaction.hpp @@ -0,0 +1,119 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_TRANSACTION_HPP +#define MAMBA_CORE_TRANSACTION_HPP + +#include +#include +#include + +#include "mamba/api/install.hpp" +#include "mamba/core/package_cache.hpp" +#include "mamba/core/prefix_data.hpp" +#include "mamba/fs/filesystem.hpp" +#include "mamba/solver/libsolv/database.hpp" +#include "mamba/solver/solution.hpp" +#include "mamba/specs/match_spec.hpp" +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + namespace solver + { + struct Request; + } + + class ChannelContext; + class Context; + + class MTransaction + { + public: + + MTransaction( + const Context& ctx, + solver::libsolv::Database& database, + std::vector pkgs_to_remove, + std::vector pkgs_to_install, + MultiPackageCache& caches + ); + + MTransaction( + const Context& ctx, + solver::libsolv::Database& database, + const solver::Request& request, + solver::Solution solution, + MultiPackageCache& caches + ); + + // Only use if the packages have been solved previously already. + MTransaction( + const Context& ctx, + solver::libsolv::Database& database, + std::vector packages, + MultiPackageCache& caches + ); + + MTransaction(const MTransaction&) = delete; + MTransaction(MTransaction&&) = delete; + MTransaction& operator=(const MTransaction&) = delete; + MTransaction& operator=(MTransaction&&) = delete; + + using to_install_type = std::vector>; + using to_remove_type = std::vector>; + using to_specs_type = std::tuple, std::vector>; + using to_conda_type = std::tuple; + + to_conda_type to_conda(); + void log_json(); + bool fetch_extract_packages(const Context& ctx, ChannelContext& channel_context); + bool empty(); + bool prompt(const Context& ctx, ChannelContext& channel_context); + void print(const Context& ctx, ChannelContext& channel_context); + bool execute(const Context& ctx, ChannelContext& channel_context, PrefixData& prefix); + + private: + + MultiPackageCache m_multi_cache; + History::UserRequest m_history_entry; + solver::Solution m_solution; + + /** Pair of current Python version, and potential update. */ + std::pair m_py_versions; + /** + * The potential "python_site_package" entry. + * + * Found in the the new or installed python interpreter. + * Key is added as part of CEP-17. + * https://conda.org/learn/ceps/cep-0017 + */ + std::string m_python_site_packages_path; + std::vector m_requested_specs; + + MTransaction(const CommandParams& command_params, MultiPackageCache&); + }; + + MTransaction create_explicit_transaction_from_urls( + const Context& ctx, + solver::libsolv::Database& database, + const std::vector& urls, + MultiPackageCache& package_caches, + std::vector& other_specs + ); + + MTransaction create_explicit_transaction_from_lockfile( + const Context& ctx, + solver::libsolv::Database& database, + const fs::u8path& env_lockfile_path, + const std::vector& categories, + MultiPackageCache& package_caches, + std::vector& other_specs + ); + +} // namespace mamba + +#endif // MAMBA_TRANSACTION_HPP diff --git a/data/miniconda3/include/mamba/core/util_os.hpp b/data/miniconda3/include/mamba/core/util_os.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8be943d5e075fc8cef8441b27d0a11d3b3c4d6a4 --- /dev/null +++ b/data/miniconda3/include/mamba/core/util_os.hpp @@ -0,0 +1,61 @@ +// Copyright (c) 2019-2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_UTIL_OS_HPP +#define MAMBA_CORE_UTIL_OS_HPP + +#include +#include + +#include "mamba/core/fsutil.hpp" +#include "mamba/core/palette.hpp" + +namespace mamba +{ +#ifdef _WIN32 + // Intention is to avoid including `Windows.h`, while still using the basic Windows API types. + using DWORD = unsigned long; +#endif + + bool is_admin(); + fs::u8path get_self_exe_path(); + fs::u8path get_libmamba_path(); + + using PID = +#ifdef _WIN32 + DWORD +#else + int +#endif + ; + + std::string get_process_name_by_pid(const PID pid); +#ifdef _WIN32 + PID getppid(); +#endif + + void run_as_admin(const std::string& args); + bool enable_long_paths_support(bool force, Palette palette = Palette::no_color()); + + void init_console(); + void reset_console(); + + /* Test whether a given `std::ostream` object refers to a terminal. */ + bool is_atty(const std::ostream& stream); + + struct ConsoleFeatures + { + bool virtual_terminal_processing, true_colors; + }; + + ConsoleFeatures get_console_features(); + int get_console_width(); + int get_console_height(); + + void codesign(const fs::u8path& path, bool verbose = false); +} + +#endif diff --git a/data/miniconda3/include/mamba/core/util_scope.hpp b/data/miniconda3/include/mamba/core/util_scope.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4323aeb61c132447ed741dc4a969d4d27ae2e12a --- /dev/null +++ b/data/miniconda3/include/mamba/core/util_scope.hpp @@ -0,0 +1,48 @@ + +#ifndef MAMBA_CORE_UTIL_SCOPE_HPP +#define MAMBA_CORE_UTIL_SCOPE_HPP + +#include + +#include "mamba/core/output.hpp" + +#include "spdlog/spdlog.h" + +namespace mamba +{ + + template + struct on_scope_exit + { + F func; + + explicit on_scope_exit(F&& f) + : func(std::forward(f)) + { + } + + ~on_scope_exit() + { + try + { + func(); + } + catch (const std::exception& ex) + { + LOG_ERROR << fmt::format("Scope exit error (caught and ignored): {}", ex.what()); + } + catch (...) + { + LOG_ERROR << "Scope exit unknown error (caught and ignored)"; + } + } + + // Deactivate copy & move until we implement moves + on_scope_exit(const on_scope_exit&) = delete; + on_scope_exit& operator=(const on_scope_exit&) = delete; + on_scope_exit(on_scope_exit&&) = delete; + on_scope_exit& operator=(on_scope_exit&&) = delete; + }; +} + +#endif diff --git a/data/miniconda3/include/mamba/core/virtual_packages.hpp b/data/miniconda3/include/mamba/core/virtual_packages.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6111e6a34739918027a0b69620c2ff03804b41d4 --- /dev/null +++ b/data/miniconda3/include/mamba/core/virtual_packages.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_VIRTUAL_PACKAGES_HPP +#define MAMBA_CORE_VIRTUAL_PACKAGES_HPP + +#include +#include + +#include "mamba/specs/package_info.hpp" + +namespace mamba +{ + class Context; + + std::vector get_virtual_packages(const std::string& platform); + + namespace detail + { + std::string cuda_version(); + + auto make_virtual_package( + std::string name, + std::string subdir, + std::string version = "", + std::string build_string = "" + ) -> specs::PackageInfo; + + std::vector dist_packages(const std::string& platform); + } +} + +#endif diff --git a/data/miniconda3/include/mamba/solver/problems_graph.hpp b/data/miniconda3/include/mamba/solver/problems_graph.hpp new file mode 100644 index 0000000000000000000000000000000000000000..21165605ff79e2c93acac27058db7125aad2104c --- /dev/null +++ b/data/miniconda3/include/mamba/solver/problems_graph.hpp @@ -0,0 +1,403 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_PROBLEMS_GRAPH_HPP +#define MAMBA_PROBLEMS_GRAPH_HPP + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "mamba/specs/match_spec.hpp" +#include "mamba/specs/package_info.hpp" +#include "mamba/util/flat_set.hpp" +#include "mamba/util/graph.hpp" + +namespace mamba::solver +{ + namespace libsolv + { + class Database; + } + + template + class conflict_map : private std::unordered_map> + { + public: + + using Base = std::unordered_map>; + using typename Base::const_iterator; + using typename Base::key_type; + using typename Base::value_type; + + conflict_map() = default; + conflict_map(std::initializer_list> conflicts_pairs); + + using Base::empty; + using Base::size; + [[nodiscard]] auto has_conflict(const key_type& a) const -> bool; + [[nodiscard]] auto conflicts(const key_type& a) const -> const util::flat_set&; + [[nodiscard]] auto in_conflict(const key_type& a, const key_type& b) const -> bool; + + using Base::cbegin; + using Base::cend; + auto begin() const noexcept -> const_iterator; + auto end() const noexcept -> const_iterator; + + using Base::clear; + auto add(const key_type& a, const key_type& b) -> bool; + auto remove(const key_type& a, const key_type& b) -> bool; + auto remove(const key_type& a) -> bool; + + private: + + auto base() const -> const Base&; + + auto remove_asym(const key_type& a, const key_type& b) -> bool; + + template + friend auto operator==(const conflict_map& lhs, const conflict_map& rhs) -> bool; + template + friend auto operator!=(const conflict_map& lhs, const conflict_map& rhs) -> bool; + }; + + template + auto operator==(const conflict_map& lhs, const conflict_map& rhs) -> bool; + + template + auto operator!=(const conflict_map& lhs, const conflict_map& rhs) -> bool; + + /** + * A directed graph of the packages involved in a libsolv conflict. + */ + class ProblemsGraph + { + public: + + struct RootNode + { + }; + + struct PackageNode : specs::PackageInfo + { + }; + + struct UnresolvedDependencyNode : specs::MatchSpec + { + }; + + struct ConstraintNode : specs::MatchSpec + { + }; + + using node_t = std::variant; + + using edge_t = specs::MatchSpec; + + using graph_t = util::DiGraph; + using node_id = graph_t::node_id; + using conflicts_t = conflict_map; + + ProblemsGraph(graph_t graph, conflicts_t conflicts, node_id root_node); + + [[nodiscard]] auto graph() const noexcept -> const graph_t&; + [[nodiscard]] auto conflicts() const noexcept -> const conflicts_t&; + [[nodiscard]] auto root_node() const noexcept -> node_id; + + private: + + graph_t m_graph; + conflicts_t m_conflicts; + node_id m_root_node; + }; + + /** + * Hand-crafted hurisitics to simplify conflicts in messy situations. + */ + auto simplify_conflicts(const ProblemsGraph& pbs) -> ProblemsGraph; + + class CompressedProblemsGraph + { + public: + + using RootNode = ProblemsGraph::RootNode; + + /** + * A rough comparison for nodes. + * + * We need to be able to compare nodes for using them in a set but we do not have + * proper version parsing. + * Ideally we would like proper comparison for printing packages in order. + * + * As with ``NamedList`` below, the implementation is currently kept private for + * needed types. + */ + template + struct RoughCompare + { + auto operator()(const T& a, const T& b) const -> bool; + }; + + /** + * A list of objects with a name, version, and build member. + * + * For simplicity, the implementation is kept in the translation unit with + * specialization for needed types. + */ + template > + class NamedList : private util::flat_set, Allocator> + { + public: + + using Base = util::flat_set, Allocator>; + using typename Base::allocator_type; + using typename Base::const_iterator; + using typename Base::const_reverse_iterator; + using typename Base::value_type; + + NamedList() = default; + template + NamedList(InputIterator first, InputIterator last); + + using Base::empty; + using Base::size; + auto front() const noexcept -> const value_type&; + auto back() const noexcept -> const value_type&; + using Base::cbegin; + using Base::cend; + using Base::crbegin; + using Base::crend; + auto begin() const noexcept -> const_iterator; + auto end() const noexcept -> const_iterator; + auto rbegin() const noexcept -> const_reverse_iterator; + auto rend() const noexcept -> const_reverse_iterator; + + [[nodiscard]] auto name() const -> const std::string&; + [[nodiscard]] auto versions_trunc( + std::string_view sep = "|", + std::string_view etc = "...", + std::size_t threshold = 5, + bool remove_duplicates = true + ) const -> std::pair; + [[nodiscard]] auto build_strings_trunc( + std::string_view sep = "|", + std::string_view etc = "...", + std::size_t threshold = 5, + bool remove_duplicates = true + ) const -> std::pair; + [[nodiscard]] auto versions_and_build_strings_trunc( + std::string_view sep = "|", + std::string_view etc = "...", + std::size_t threshold = 5, + bool remove_duplicates = true + ) const -> std::pair; + + using Base::clear; + using Base::reserve; + void insert(const value_type& e); + void insert(value_type&& e); + template + void insert(InputIterator first, InputIterator last); + + private: + + template + void insert_impl(T_&& e); + }; + + using PackageListNode = NamedList; + using UnresolvedDependencyListNode = NamedList; + using ConstraintListNode = NamedList; + using node_t = std::variant< + RootNode, // + PackageListNode, + UnresolvedDependencyListNode, + ConstraintListNode>; + + using edge_t = NamedList; + + using graph_t = util::DiGraph; + using node_id = graph_t::node_id; + using conflicts_t = conflict_map; + + using merge_criteria_t = std::function< + bool(const ProblemsGraph&, ProblemsGraph::node_id, ProblemsGraph::node_id)>; + + static auto + from_problems_graph(const ProblemsGraph& pbs, const merge_criteria_t& merge_criteria = {}) + -> CompressedProblemsGraph; + + CompressedProblemsGraph(graph_t graph, conflicts_t conflicts, node_id root_node); + + [[nodiscard]] auto graph() const noexcept -> const graph_t&; + [[nodiscard]] auto conflicts() const noexcept -> const conflicts_t&; + [[nodiscard]] auto root_node() const noexcept -> node_id; + + private: + + graph_t m_graph; + conflicts_t m_conflicts; + node_id m_root_node; + }; + + /** + * Formatting options for error message functions. + */ + struct ProblemsMessageFormat + { + fmt::text_style unavailable = fmt::fg(fmt::terminal_color::red); + fmt::text_style available = fmt::fg(fmt::terminal_color::green); + std::array indents = { "โ”‚ ", " ", "โ”œโ”€ ", "โ””โ”€ " }; + }; + + auto print_problem_tree_msg( + std::ostream& out, + const CompressedProblemsGraph& pbs, + const ProblemsMessageFormat& format = {} + ) -> std::ostream&; + + auto problem_tree_msg( // + const CompressedProblemsGraph& pbs, + const ProblemsMessageFormat& format = {} + ) -> std::string; + + /************************************ + * Implementation of conflict_map * + ************************************/ + + template + conflict_map::conflict_map(std::initializer_list> conflicts_pairs) + { + for (const auto& [a, b] : conflicts_pairs) + { + add(a, b); + } + } + + template + auto conflict_map::has_conflict(const key_type& a) const -> bool + { + return Base::find(a) != end(); + } + + template + auto conflict_map::conflicts(const key_type& a) const -> const util::flat_set& + { + return Base::at(a); + } + + template + auto conflict_map::in_conflict(const key_type& a, const key_type& b) const -> bool + { + return has_conflict(a) && Base::at(a).contains(b); + } + + template + auto conflict_map::begin() const noexcept -> const_iterator + { + return Base::begin(); + } + + template + auto conflict_map::end() const noexcept -> const_iterator + { + return Base::end(); + } + + template + auto conflict_map::add(const key_type& a, const key_type& b) -> bool + { + auto [_, inserted] = Base::operator[](a).insert(b); + if (a != b) + { + Base::operator[](b).insert(a); + } + return inserted; + } + + template + auto conflict_map::base() const -> const Base& + { + return static_cast(*this); + } + + template + auto conflict_map::remove_asym(const key_type& a, const key_type& b) -> bool + { + auto iter = Base::find(a); + if (iter == Base::end()) + { + return false; + } + auto& cflcts = iter->second; + const bool erased = cflcts.erase(b); + if (cflcts.empty()) + { + Base::erase(a); + } + return erased; + }; + + template + auto conflict_map::remove(const key_type& a, const key_type& b) -> bool + { + return remove_asym(a, b) && ((a == b) || remove_asym(b, a)); + } + + template + auto conflict_map::remove(const key_type& a) -> bool + { + auto a_iter = Base::find(a); + if (a_iter == Base::end()) + { + return false; + } + for (const auto& b : a_iter->second) + { + if (a != b) // Cannot modify while we iterate on it + { + remove_asym(b, a); + } + } + Base::erase(a); + return true; + } + + template + auto operator==(const conflict_map& lhs, const conflict_map& rhs) -> bool + { + return lhs.base() == rhs.base(); + } + + template + auto operator!=(const conflict_map& lhs, const conflict_map& rhs) -> bool + { + return !(lhs == rhs); + } + + /********************************* + * Implementation of NamedList * + *********************************/ + + template + template + void CompressedProblemsGraph::NamedList::insert(InputIterator first, InputIterator last) + { + for (; first < last; ++first) + { + insert(*first); + } + } +} +#endif diff --git a/data/miniconda3/include/mamba/solver/request.hpp b/data/miniconda3/include/mamba/solver/request.hpp new file mode 100644 index 0000000000000000000000000000000000000000..50f3a2b906bbeacee45c827cc31b5e5e3b1305e5 --- /dev/null +++ b/data/miniconda3/include/mamba/solver/request.hpp @@ -0,0 +1,125 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SOLVER_REQUEST_HPP +#define MAMBA_SOLVER_REQUEST_HPP + +#include +#include + +#include "mamba/specs/match_spec.hpp" +#include "mamba/util/loop_control.hpp" +#include "mamba/util/type_traits.hpp" + +namespace mamba::solver +{ + struct Request + { + struct Flags + { + /** Keep the dependencies of the install package in the solution. */ + bool keep_dependencies = true; + /** Keep the original user requested package in the solution. */ + bool keep_user_specs = true; + /** Force reinstallation of jobs. */ + bool force_reinstall = false; + /** Allow downgrading packages to satisfy requirements. */ + bool allow_downgrade = true; + /** Allow uninstalling packages to satisfy requirements. */ + bool allow_uninstall = true; + /** Prefer packages by repoitory order. */ + bool strict_repo_priority = true; + /** Order the request to get a deterministic solution. */ + bool order_request = true; + }; + + /** Instruct to install a package matching the given spec. */ + struct Install + { + specs::MatchSpec spec; + }; + + /** Instruct to remove packages matching the given spec. */ + struct Remove + { + specs::MatchSpec spec; + bool clean_dependencies = true; + }; + + /** Instruct to update packages matching the given spec. */ + struct Update + { + specs::MatchSpec spec; + bool clean_dependencies = true; + }; + + /** Instruct to update all installed packages. */ + struct UpdateAll + { + bool clean_dependencies = true; + }; + + /** Instruct to keep packages matching the spec during dependency clean. */ + struct Keep + { + specs::MatchSpec spec; + }; + + /** Instruct to freeze the version and status of the matching installed package. */ + struct Freeze + { + specs::MatchSpec spec; + }; + + /** Add a constraints on packages possible to install. */ + struct Pin + { + specs::MatchSpec spec; + }; + + using Job = std::variant; + using job_list = std::vector; + + Flags flags = {}; + job_list jobs = {}; + }; + + template + void for_each_of(const Request& request, Func&& func) + { + for (const auto& unknown_job : request.jobs) + { + const auto control = std::visit( + [&](const auto& itm) -> util::LoopControl + { + using Itm = std::decay_t; + if constexpr (util::is_any_of_v) + { + if constexpr (std::is_same_v) + { + return func(itm); + } + else + { + func(itm); + return util::LoopControl::Continue; + } + } + else + { + return util::LoopControl::Continue; + } + }, + unknown_job + ); + if (control == util::LoopControl::Break) + { + break; + } + } + } +} +#endif diff --git a/data/miniconda3/include/mamba/solver/solution.hpp b/data/miniconda3/include/mamba/solver/solution.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9f52587f6d56145548343cc332f4ffea1db553db --- /dev/null +++ b/data/miniconda3/include/mamba/solver/solution.hpp @@ -0,0 +1,261 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_SOLUTION_HPP +#define MAMBA_CORE_SOLUTION_HPP + +#include +#include +#include + +#include "mamba/specs/package_info.hpp" +#include "mamba/util/loop_control.hpp" +#include "mamba/util/type_traits.hpp" + +namespace mamba::solver +{ + struct Solution + { + struct Omit + { + specs::PackageInfo what; + }; + + struct Upgrade + { + specs::PackageInfo remove; + specs::PackageInfo install; + }; + + struct Downgrade + { + specs::PackageInfo remove; + specs::PackageInfo install; + }; + + struct Change + { + specs::PackageInfo remove; + specs::PackageInfo install; + }; + + struct Reinstall + { + specs::PackageInfo what; + }; + + struct Remove + { + specs::PackageInfo remove; + }; + + struct Install + { + specs::PackageInfo install; + }; + + template + inline static constexpr bool has_remove_v = util::is_any_of_v; + + template + inline static constexpr bool has_install_v = util::is_any_of_v; + + using Action = std::variant; + using action_list = std::vector; + + action_list actions = {}; + }; + + template + void for_each_to_remove(Iter first, Iter last, UnaryFunc&& func); + template + void for_each_to_remove(Range&& actions, UnaryFunc&& func); + + template + void for_each_to_install(Iter first, Iter last, UnaryFunc&& func); + template + void for_each_to_install(Range&& actions, UnaryFunc&& func); + + template + void for_each_to_omit(Iter first, Iter last, UnaryFunc&& func); + template + void for_each_to_omit(Range&& actions, UnaryFunc&& func); + + /******************************** + * Implementation of Solution * + ********************************/ + + namespace detail + { + template + auto to_remove_ptr(Action& action) + { + using PackageInfoPtr = std:: + conditional_t, const specs::PackageInfo*, specs::PackageInfo*>; + return std::visit( + [](auto& a) -> PackageInfoPtr + { + using A = std::decay_t; + if constexpr (Solution::has_remove_v) + { + return &(a.remove); + } + else if constexpr (std::is_same_v) + { + return &(a.what); + } + else + { + return nullptr; + } + }, + action + ); + } + } + + // TODO(C++20): Poor man's replacement to range filter transform + template + void for_each_to_remove(Iter first, Iter last, UnaryFunc&& func) + { + for (; first != last; ++first) + { + if (auto* const ptr = detail::to_remove_ptr(*first)) + { + if constexpr (std::is_same_v) + { + if (func(*ptr) == util::LoopControl::Break) + { + break; + } + } + else + { + func(*ptr); + } + } + } + } + + template + void for_each_to_remove(Range&& actions, UnaryFunc&& func) + { + return for_each_to_remove(actions.begin(), actions.end(), std::forward(func)); + } + + namespace detail + { + template + auto to_install_ptr(Action& action) + { + using PackageInfoPtr = std:: + conditional_t, const specs::PackageInfo*, specs::PackageInfo*>; + return std::visit( + [](auto& a) -> PackageInfoPtr + { + using A = std::decay_t; + if constexpr (Solution::has_install_v) + { + return &(a.install); + } + else if constexpr (std::is_same_v) + { + return &(a.what); + } + else + { + return nullptr; + } + }, + action + ); + } + } + + template + void for_each_to_install(Iter first, Iter last, UnaryFunc&& func) + { + for (; first != last; ++first) + { + if (auto* const ptr = detail::to_install_ptr(*first)) + { + if constexpr (std::is_same_v) + { + if (func(*ptr) == util::LoopControl::Break) + { + break; + } + } + else + { + func(*ptr); + } + } + } + } + + // TODO(C++20): Poor man's replacement to range filter transform + template + void for_each_to_install(Range&& actions, UnaryFunc&& func) + { + return for_each_to_install(actions.begin(), actions.end(), std::forward(func)); + } + + namespace detail + { + template + auto to_omit_ptr(Action& action) + { + using PackageInfoPtr = std:: + conditional_t, const specs::PackageInfo*, specs::PackageInfo*>; + return std::visit( + [](auto& a) -> PackageInfoPtr + { + using A = std::decay_t; + if constexpr (std::is_same_v) + { + return &(a.what); + } + else + { + return nullptr; + } + }, + action + ); + } + } + + // TODO(C++20): Poor man's replacement to range filter transform + template + void for_each_to_omit(Iter first, Iter last, UnaryFunc&& func) + { + for (; first != last; ++first) + { + if (auto* const ptr = detail::to_omit_ptr(*first)) + { + if constexpr (std::is_same_v) + { + if (func(*ptr) == util::LoopControl::Break) + { + break; + } + } + else + { + func(*ptr); + } + } + } + } + + template + void for_each_to_omit(Range&& actions, UnaryFunc&& func) + { + return for_each_to_omit(actions.begin(), actions.end(), std::forward(func)); + } +} +#endif diff --git a/data/miniconda3/include/mamba/specs/archive.hpp b/data/miniconda3/include/mamba/specs/archive.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0454a816bf9da4aec8758accf22233f7e8e340f9 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/archive.hpp @@ -0,0 +1,52 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_ARCHIVE_HPP +#define MAMBA_SPECS_ARCHIVE_HPP + +#include +#include +#include + +#include "mamba/fs/filesystem.hpp" + +namespace mamba::specs +{ + inline static constexpr auto ARCHIVE_EXTENSIONS = std::array{ std::string_view(".tar.bz2"), + std::string_view(".conda"), + std::string_view(".whl"), + std::string_view(".tar.gz") }; + + /** Detect if the package path has one of the known archive extension. */ + template , bool> = true> + [[nodiscard]] auto has_archive_extension(const Str& path) -> bool; + [[nodiscard]] auto has_archive_extension(std::string_view path) -> bool; + [[nodiscard]] auto has_archive_extension(const fs::u8path& path) -> bool; + + /** Remove the known archive extension from the package path if present. */ + template , bool> = true> + [[nodiscard]] auto strip_archive_extension(const Str& path) -> std::string_view; + [[nodiscard]] auto strip_archive_extension(std::string_view path) -> std::string_view; + [[nodiscard]] auto strip_archive_extension(fs::u8path path) -> fs::u8path; + + /******************** + * Implementation * + ********************/ + + template , bool>> + [[nodiscard]] auto has_archive_extension(const Str& path) -> bool + { + return has_archive_extension(std::string_view(path)); + } + + template , bool>> + [[nodiscard]] auto strip_archive_extension(const Str& path) -> std::string_view + { + return strip_archive_extension(std::string_view(path)); + } + +} +#endif diff --git a/data/miniconda3/include/mamba/specs/authentication_info.hpp b/data/miniconda3/include/mamba/specs/authentication_info.hpp new file mode 100644 index 0000000000000000000000000000000000000000..02455fc31e6aec4000edbadf616cf3ec705c23c0 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/authentication_info.hpp @@ -0,0 +1,109 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_AUTHENTICATION_INFO_HPP +#define MAMBA_SPECS_AUTHENTICATION_INFO_HPP + +#include +#include +#include +#include +#include +#include + +#include "mamba/util/weakening_map.hpp" + +namespace mamba::specs +{ + /** User and password authetification set in the URL. */ + struct BasicHTTPAuthentication + { + std::string user; + std::string password; + }; + + auto operator==(const BasicHTTPAuthentication& a, const BasicHTTPAuthentication& b) -> bool; + auto operator!=(const BasicHTTPAuthentication& a, const BasicHTTPAuthentication& b) -> bool; + + /** HTTP Bearer token set in the request headers. */ + struct BearerToken + { + std::string token; + }; + + auto operator==(const BearerToken& a, const BearerToken& b) -> bool; + auto operator!=(const BearerToken& a, const BearerToken& b) -> bool; + + /** A Conda token set in the URL path. */ + struct CondaToken + { + std::string token; + }; + + auto operator==(const CondaToken& a, const CondaToken& b) -> bool; + auto operator!=(const CondaToken& a, const CondaToken& b) -> bool; + + using AuthenticationInfo = std::variant; + + /** + * The weakener for @ref AuthenticationDataBase. + */ + struct URLWeakener + { + /** + * Add a trailing '/' if abscent. + * + * This lets "mamba.org/" be found by "mamba.org" key. + */ + [[nodiscard]] auto make_first_key(std::string_view key) const -> std::string; + + /** + * Remove the last part of the URL path, or simply the trailing slash. + * + * For instance, iterations mya follow + * "mamba.org/p/chan" > "mamba.org/p/" > "mamba.org/p" > "mamba.org/" > "mamba.org". + */ + [[nodiscard]] auto weaken_key(std::string_view key) const -> std::optional; + }; + + /** + * A class that holds the authentication info stored by users. + * + * Essentially a map, except that some keys can match multiple queries. + * For instance "mamba.org/private" should be matched by queries "mamba.org/private", + * "mamba.org/private/channel", but not "mamba.org/public". + * + * A best effort is made to satifiy this with `xxx_compatible`. + * + * Future development of this class should aim to replace the map and keys with a + * `AuthenticationSpec`, that can decide whether or not a URL should benefit from such + * its authentication. + * Possibly, a string representation such as "*.mamba.org/private/channel*" could be added + * to parse users intentions, rather than relying on the assumptions made here. + */ + using AuthenticationDataBase = util:: + weakening_map, URLWeakener>; +} + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::BasicHTTPAuthentication& auth) const -> std::size_t; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::BearerToken& auth) const -> std::size_t; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::CondaToken& auth) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/build_number_spec.hpp b/data/miniconda3/include/mamba/specs/build_number_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ea03242452b27070f75005966aca18573fc4c2a1 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/build_number_spec.hpp @@ -0,0 +1,184 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_BUILD_NUMBER_SPEC_HPP +#define MAMBA_SPECS_BUILD_NUMBER_SPEC_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/specs/error.hpp" + +namespace mamba::specs +{ + /** + * A stateful unary boolean function on the integer space. + */ + class BuildNumberPredicate + { + public: + + using BuildNumber = std::size_t; + + [[nodiscard]] static auto make_free() -> BuildNumberPredicate; + [[nodiscard]] static auto make_equal_to(BuildNumber ver) -> BuildNumberPredicate; + [[nodiscard]] static auto make_not_equal_to(BuildNumber ver) -> BuildNumberPredicate; + [[nodiscard]] static auto make_greater(BuildNumber ver) -> BuildNumberPredicate; + [[nodiscard]] static auto make_greater_equal(BuildNumber ver) -> BuildNumberPredicate; + [[nodiscard]] static auto make_less(BuildNumber ver) -> BuildNumberPredicate; + [[nodiscard]] static auto make_less_equal(BuildNumber ver) -> BuildNumberPredicate; + + /** Construct an free interval. */ + BuildNumberPredicate() = default; + + /** + * True if the predicate contains the given build_number. + */ + [[nodiscard]] auto contains(const BuildNumber& point) const -> bool; + + [[nodiscard]] auto to_string() const -> std::string; + + private: + + struct free_interval + { + auto operator()(const BuildNumber&, const BuildNumber&) const -> bool; + }; + + /** + * Operator to compare with the stored build_number. + */ + using BinaryOperator = std::variant< + free_interval, + std::equal_to, + std::not_equal_to, + std::greater, + std::greater_equal, + std::less, + std::less_equal>; + + BuildNumber m_build_number = {}; + BinaryOperator m_operator = free_interval{}; + + BuildNumberPredicate(BuildNumber ver, BinaryOperator op); + + friend auto equal(free_interval, free_interval) -> bool; + friend auto operator==(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) + -> bool; + friend struct ::fmt::formatter; + }; + + auto operator==(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) -> bool; + auto operator!=(const BuildNumberPredicate& lhs, const BuildNumberPredicate& rhs) -> bool; + + /** + * Match a build number with a predicate. + * + * Conda does not implement expression for build numbers but they could be added similarly + * to @ref VersionSpec. + */ + class BuildNumberSpec + { + public: + + using BuildNumber = typename BuildNumberPredicate::BuildNumber; + + static constexpr std::string_view preferred_free_str = "=*"; + static constexpr std::array all_free_strs = { "", "*", "=*", "==*" }; + static constexpr std::string_view equal_str = "="; + static constexpr std::string_view not_equal_str = "!="; + static constexpr std::string_view greater_str = ">"; + static constexpr std::string_view greater_equal_str = ">="; + static constexpr std::string_view less_str = "<"; + static constexpr std::string_view less_equal_str = "<="; + + [[nodiscard]] static auto parse(std::string_view str) -> expected_parse_t; + + /** Construct BuildNumberSpec that match all versions. */ + BuildNumberSpec(); + + explicit BuildNumberSpec(BuildNumberPredicate predicate) noexcept; + + /** + * Returns whether the BuildNumberSpec is unconstrained. + */ + [[nodiscard]] auto is_explicitly_free() const -> bool; + + /** + * A string representation of the build number spec. + * + * May not always be the same as the parsed string (due to reconstruction) but reparsing + * this string will give the same build number spec. + */ + [[nodiscard]] auto to_string() const -> std::string; + + /** + * True if the set described by the BuildNumberSpec contains the given version. + */ + [[nodiscard]] auto contains(BuildNumber point) const -> bool; + + [[nodiscard]] auto operator==(const BuildNumberSpec& other) const -> bool = default; + + [[nodiscard]] auto operator!=(const BuildNumberSpec& other) const -> bool = default; + + private: + + BuildNumberPredicate m_predicate; + + friend struct ::fmt::formatter; + }; + + namespace build_number_spec_literals + { + auto operator""_bs(const char* str, std::size_t len) -> BuildNumberSpec; + } +} + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw format_error("invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::BuildNumberPredicate& pred, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw format_error("invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::BuildNumberSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::BuildNumberSpec& spec) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/channel.hpp b/data/miniconda3/include/mamba/specs/channel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..26e829a7284f46fb6d416f58e601fd1739761ab7 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/channel.hpp @@ -0,0 +1,160 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#include +#include +#include +#include +#include + +#include "mamba/specs/authentication_info.hpp" +#include "mamba/specs/conda_url.hpp" +#include "mamba/specs/error.hpp" +#include "mamba/specs/unresolved_channel.hpp" +#include "mamba/util/flat_set.hpp" +#include "mamba/util/weakening_map.hpp" + +#ifndef MAMBA_SPECS_CHANNEL_HPP +#define MAMBA_SPECS_CHANNEL_HPP + +namespace mamba::specs +{ + struct ChannelResolveParams; + struct ChannelResolveParamsView; + + class Channel + { + public: + + using platform_list = util::flat_set; + using channel_list = std::vector; + + [[nodiscard]] static auto resolve( // + UnresolvedChannel uc, + const ChannelResolveParams& params + ) -> expected_parse_t; + + [[nodiscard]] static auto resolve( // + UnresolvedChannel uc, + ChannelResolveParamsView params + ) -> expected_parse_t; + + Channel(CondaURL url, std::string display_name, platform_list platforms = {}); + Channel(std::vector mirror_urls, std::string display_name, platform_list platforms = {}); + + [[nodiscard]] auto is_package() const -> bool; + + [[nodiscard]] auto mirror_urls() const -> const std::vector&; + [[nodiscard]] auto platform_mirror_urls() const -> std::vector; + [[nodiscard]] auto platform_mirror_urls(const std::string_view platform) const + -> std::vector; + + [[nodiscard]] auto url() const -> const CondaURL&; + auto clear_url() -> const CondaURL; + void set_url(CondaURL url); + + [[nodiscard]] auto platform_urls() const -> std::vector; + + [[nodiscard]] auto platform_url(std::string_view platform) const -> CondaURL; + + [[nodiscard]] auto platforms() const -> const platform_list&; + auto clear_platforms() -> platform_list; + void set_platforms(platform_list platforms); + + /* + * This ID is a cross URL id, and is dependent on the + * channel_alias when the channel has not been specified in + * the new mirrored_channel section of the configuration. + */ + [[nodiscard]] auto id() const -> const std::string&; + [[nodiscard]] auto display_name() const -> const std::string&; + auto clear_display_name() -> std::string; + void set_display_name(std::string display_name); + + enum struct Match + { + No, + InOtherPlatform, + Full, + }; + + [[nodiscard]] auto url_equivalent_with(const Channel& other) const -> bool; + + [[nodiscard]] auto is_equivalent_to(const Channel& other) const -> bool; + + [[nodiscard]] auto contains_equivalent(const Channel& other) const -> bool; + + [[nodiscard]] auto contains_package(const CondaURL& pkg) const -> Match; + + private: + + CondaURL platform_url_impl(const CondaURL& url, const std::string_view platform) const; + + std::vector m_mirror_urls; + std::string m_display_name; + std::string m_id; + util::flat_set m_platforms; + }; + + struct ChannelResolveParams + { + /** + * The weakener for @ref ResolveParams::custom_channels. + */ + struct NameWeakener + { + /** + * Return the key unchanged. + */ + [[nodiscard]] auto make_first_key(std::string_view key) const -> std::string_view; + + /** + * Remove the last element of the '/'-separated name. + */ + [[nodiscard]] auto weaken_key(std::string_view key) const + -> std::optional; + }; + + template + using name_map = util::weakening_map, NameWeakener>; + + using platform_list = util::flat_set; + using channel_list = std::vector; + using channel_map = name_map; + using multichannel_map = name_map; + + platform_list platforms = {}; + CondaURL channel_alias = {}; + channel_map custom_channels = {}; + multichannel_map custom_multichannels = {}; + AuthenticationDataBase authentication_db = {}; + std::string home_dir = {}; + std::string current_working_dir = {}; + }; + + struct ChannelResolveParamsView + { + const ChannelResolveParams::platform_list& platforms = {}; + const CondaURL& channel_alias = {}; + const ChannelResolveParams::channel_map& custom_channels = {}; + const ChannelResolveParams::multichannel_map& custom_multichannels = {}; + const AuthenticationDataBase& authentication_db = {}; + std::string_view home_dir = {}; + std::string_view current_working_dir = {}; + }; + + /** Tuple-like equality of all observable members */ + auto operator==(const Channel& a, const Channel& b) -> bool; + auto operator!=(const Channel& a, const Channel& b) -> bool; +} + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::Channel& c) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/chimera_string_spec.hpp b/data/miniconda3/include/mamba/specs/chimera_string_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5d2bd1b35bd422fc86c75b88ffb4163b5188b59d --- /dev/null +++ b/data/miniconda3/include/mamba/specs/chimera_string_spec.hpp @@ -0,0 +1,95 @@ +// Copyright (c) 2024, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_CHIMERA_STRING_SPEC +#define MAMBA_SPECS_CHIMERA_STRING_SPEC + +#include +#include + +#include +#include + +#include "mamba/specs/error.hpp" +#include "mamba/specs/glob_spec.hpp" +#include "mamba/specs/regex_spec.hpp" + +namespace mamba::specs +{ + /** + * A matcher for either a glob or a regex expression. + */ + class ChimeraStringSpec + { + public: + + using Chimera = std::variant; + + [[nodiscard]] static auto parse(std::string pattern) -> expected_parse_t; + + ChimeraStringSpec(); + explicit ChimeraStringSpec(Chimera spec); + + [[nodiscard]] auto contains(std::string_view str) const -> bool; + + /** + * Return true if the spec will match true on any input. + */ + [[nodiscard]] auto is_explicitly_free() const -> bool; + + /** + * Return true if the spec will match exactly one input. + */ + [[nodiscard]] auto is_exact() const -> bool; + + /** + * Return true if the spec is a glob and not a regex. + */ + [[nodiscard]] auto is_glob() const -> bool; + + [[nodiscard]] auto to_string() const -> const std::string&; + + // TODO(C++20): replace by the `= default` implementation of `operator==` + [[nodiscard]] auto operator==(const ChimeraStringSpec& other) const -> bool + { + return m_spec == other.m_spec; + } + + [[nodiscard]] auto operator!=(const ChimeraStringSpec& other) const -> bool + { + return !(*this == other); + } + + private: + + Chimera m_spec; + }; +} + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::ChimeraStringSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::ChimeraStringSpec& spec) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/conda_url.hpp b/data/miniconda3/include/mamba/specs/conda_url.hpp new file mode 100644 index 0000000000000000000000000000000000000000..27d511b030733ebe27e9eaa0feac2b4d1af38ee5 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/conda_url.hpp @@ -0,0 +1,262 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_CONDA_URL_HPP +#define MAMBA_SPECS_CONDA_URL_HPP + +#include +#include + +#include "mamba/specs/error.hpp" +#include "mamba/specs/platform.hpp" +#include "mamba/util/url.hpp" + +namespace mamba::specs +{ + class CondaURL : private util::URL + { + using Base = typename util::URL; + + public: + + using StripScheme = util::detail::StripScheme; + using Credentials = util::detail::Credentials; + using Encode = util::detail::Encode; + using Decode = util::detail::Decode; + + inline static constexpr std::string_view token_prefix = "/t/"; + + /** Parse a string url. + * The url must be percent encoded beforehand. + * cf. https://en.wikipedia.org/wiki/Percent-encoding + */ + [[nodiscard]] static auto parse(std::string_view url) -> expected_parse_t; + + /** Create a local URL. */ + CondaURL() = default; + explicit CondaURL(util::URL&& url); + explicit CondaURL(const util::URL& url); + + [[nodiscard]] auto generic() const -> const util::URL&; + + using Base::scheme_is_defaulted; + using Base::scheme; + using Base::set_scheme; + using Base::clear_scheme; + using Base::has_user; + using Base::user; + using Base::set_user; + using Base::clear_user; + using Base::has_password; + using Base::password; + using Base::set_password; + using Base::clear_password; + using Base::authentication; + using Base::host_is_defaulted; + using Base::host; + using Base::set_host; + using Base::clear_host; + using Base::port; + using Base::set_port; + using Base::clear_port; + using Base::authority; + using Base::path; + using Base::pretty_path; + using Base::clear_path; + using Base::query; + using Base::set_query; + using Base::clear_query; + using Base::fragment; + using Base::set_fragment; + using Base::clear_fragment; + + /** + * Set the path from a not encoded value. + * + * All '/' are not encoded but interpreted as separators. + * On windows with a file scheme, the colon after the drive letter is not encoded. + * A leading '/' is added if abscent. + * If the path contains only a token, a trailing '/' is added afterwards. + */ + void set_path(std::string_view path, Encode::yes_type = Encode::yes); + + /** Set the path from an already encoded value. + * + * A leading '/' is added if abscent. + * If the path contains only a token, a trailing '/' is added afterwards. + */ + void set_path(std::string path, Encode::no_type); + + /** + * Append a not encoded sub path to the current path. + * + * Contrary to `std::filesystem::path::append`, this always append and never replace + * the current path, even if @p subpath starts with a '/'. + * All '/' are not encoded but interpreted as separators. + * If the final path contains only a token, a trailing '/' is added afterwards. + */ + void append_path(std::string_view path, Encode::yes_type = Encode::yes); + + /** + * Append a already encoded sub path to the current path. + * + * Contrary to `std::filesystem::path::append`, this always append and never replace + * the current path, even if @p subpath starts with a '/'. + * If the final path contains only a token, a trailing '/' is added afterwards. + */ + void append_path(std::string_view path, Encode::no_type); + + /** Return whether a token is set. */ + [[nodiscard]] auto has_token() const -> bool; + + /** Return the Conda token, as delimited with "/t/", or empty if there isn't any. */ + [[nodiscard]] auto token() const -> std::string_view; + + /** + * Set a token. + * + * If the URL already contains one replace it at the same location, otherwise, add it at + * the beginning of the path. + */ + void set_token(std::string_view token); + + /** Clear the token and return ``true`` if it exists, otherwise return ``false``. */ + auto clear_token() -> bool; + + /** Return the encoded part of the path without any Conda token, always start with '/'. */ + [[nodiscard]] auto path_without_token(Decode::no_type) const -> std::string_view; + + /** Return the decoded part of the path without any Conda token, always start with '/'. */ + [[nodiscard]] auto path_without_token(Decode::yes_type = Decode::yes) const -> std::string; + + /** + * Set the path from an already encoded value, without changing the Conda token. + * + * A leading '/' is added if abscent. + */ + void set_path_without_token(std::string_view path, Encode::no_type); + + /** + * Set the path from an not yet encoded value, without changing the Conda token. + * + * A leading '/' is added if abscent. + */ + void set_path_without_token(std::string_view path, Encode::yes_type = Encode::yes); + + /** Clear the path without changing the Conda token and return ``true`` if it exists. */ + auto clear_path_without_token() -> bool; + + /** Return the platform if part of the URL path. */ + [[nodiscard]] auto platform() const -> std::optional; + + /** + * Return the platform if part of the URL path, or empty. + * + * If a platform is found, it is returned as a view onto the path without normalization + * (for instance the capitalization isn't changed). + */ + [[nodiscard]] auto platform_name() const -> std::string_view; + + /** Set the platform if the URL already contains one, or throw an error. */ + void set_platform(KnownPlatform platform); + + /** + * Set the platform if the URL already contains one, or throw an error. + * + * If the input @p platform is a valid platform, it is inserted as it is into the path + * (for instance the capitalization isn't changed). + */ + void set_platform(std::string_view platform); + + /** Clear the token and return true if it exists, otherwise return ``false``. */ + auto clear_platform() -> bool; + + /** + * Return the encoded package name, or empty otherwise. + * + * Package name are at the end of the path and end with a archive extension. + * + * @see has_archive_extension + */ + [[nodiscard]] auto package(Decode::yes_type = Decode::yes) const -> std::string; + + /** + * Return the decoded package name, or empty otherwise. + * + * Package name are at the end of the path and end with a archive extension. + * + * @see has_archive_extension + */ + [[nodiscard]] auto package(Decode::no_type) const -> std::string_view; + + /** + * Change the package file name with a not encoded value. + * + * If a package file name is present, replace it, otherwise add it at the end + * of the path. + */ + void set_package(std::string_view pkg, Encode::yes_type = Encode::yes); + + /** + * Change the package file name with already encoded value. + * + * If a package file name is present, replace it, otherwise add it at the end + * of the path. + */ + void set_package(std::string_view pkg, Encode::no_type); + + /** Clear the package and return true if it exists, otherwise return ``false``. */ + auto clear_package() -> bool; + + /** Return the full, exact, encoded URL. */ + [[nodiscard]] auto str(Credentials credentials = Credentials::Hide) const -> std::string; + + /** + * Return the full decoded url. + * + * Due to decoding, the outcome may not be understood by parser and usable to reach an + * asset. + * @param strip_scheme If true, remove the scheme and "localhost" on file URI. + * @param rstrip_path If non-null, remove the given characters at the end of the path. + * @param credentials If true, hide password and tokens in the decoded string. + * @param credentials Decide to keep, remove, or hide passwrd, users, and token. + */ + [[nodiscard]] auto pretty_str( + StripScheme strip_scheme = StripScheme::no, + char rstrip_path = 0, + Credentials credentials = Credentials::Hide + ) const -> std::string; + + + private: + + void set_platform_no_check_input(std::string_view platform); + void ensure_path_without_token_leading_slash(); + + friend auto operator==(const CondaURL&, const CondaURL&) -> bool; + }; + + /** Tuple-like equality of all observable members */ + auto operator==(const CondaURL& a, const CondaURL& b) -> bool; + auto operator!=(const CondaURL& a, const CondaURL& b) -> bool; + + /** A functional equivalent to ``CondaURL::append_path``. */ + auto operator/(const CondaURL& url, std::string_view subpath) -> CondaURL; + auto operator/(CondaURL&& url, std::string_view subpath) -> CondaURL; + + namespace conda_url_literals + { + auto operator""_cu(const char* str, std::size_t len) -> CondaURL; + } +} + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::CondaURL& p) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/error.hpp b/data/miniconda3/include/mamba/specs/error.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d764463a178a7e4fa1eb6ed950a0b2d95da4a3cf --- /dev/null +++ b/data/miniconda3/include/mamba/specs/error.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2024, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_ERROR_HPP +#define MAMBA_SPECS_ERROR_HPP + +#include +#include + +#include + +namespace mamba::specs +{ + + struct ParseError final : std::invalid_argument + { + using std::invalid_argument::invalid_argument; + }; + + template + using expected_parse_t = tl::expected; + + template + [[nodiscard]] auto make_unexpected_parse(T&& err) -> tl::unexpected; + + /******************** + * Implementation * + ********************/ + + template + auto make_unexpected_parse(T&& err) -> tl::unexpected + { + return tl::make_unexpected(ParseError(std::forward(err))); + } +} +#endif diff --git a/data/miniconda3/include/mamba/specs/glob_spec.hpp b/data/miniconda3/include/mamba/specs/glob_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f1f1c8536cef4fff143b9d7033a0a7fd1fa3a637 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/glob_spec.hpp @@ -0,0 +1,87 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_GLOB_SPEC +#define MAMBA_SPECS_GLOB_SPEC + +#include +#include + +#include +#include + +namespace mamba::specs +{ + /** + * A matcher for glob expression. + * + * Currently only support "*" wildcard for matching zero or more characters. + */ + class GlobSpec + { + public: + + inline static constexpr std::string_view free_pattern = "*"; + inline static constexpr char glob_pattern = '*'; + + GlobSpec() = default; + explicit GlobSpec(std::string pattern); + + [[nodiscard]] auto contains(std::string_view str) const -> bool; + + /** + * Return true if the spec will match true on any input. + */ + [[nodiscard]] auto is_free() const -> bool; + + /** + * Return true if the spec will match exactly one input. + */ + [[nodiscard]] auto is_exact() const -> bool; + + [[nodiscard]] auto to_string() const -> const std::string&; + + // TODO(C++20): replace by the `= default` implementation of `operator==` + [[nodiscard]] auto operator==(const GlobSpec& other) const -> bool + { + return m_pattern == other.m_pattern; + } + + [[nodiscard]] auto operator!=(const GlobSpec& other) const -> bool + { + return !(*this == other); + } + + private: + + std::string m_pattern = std::string(free_pattern); + }; +} + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::GlobSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::GlobSpec& spec) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/match_spec.hpp b/data/miniconda3/include/mamba/specs/match_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..943d86b7dcf9d13fe6a631fd01175b652f4c085f --- /dev/null +++ b/data/miniconda3/include/mamba/specs/match_spec.hpp @@ -0,0 +1,320 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_MATCH_SPEC +#define MAMBA_SPECS_MATCH_SPEC + +#include +#include +#include +#include + +#include +#include + +#include "mamba/specs/build_number_spec.hpp" +#include "mamba/specs/chimera_string_spec.hpp" +#include "mamba/specs/error.hpp" +#include "mamba/specs/glob_spec.hpp" +#include "mamba/specs/unresolved_channel.hpp" +#include "mamba/specs/version_spec.hpp" +#include "mamba/util/flat_set.hpp" +#include "mamba/util/heap_optional.hpp" + +namespace mamba::specs +{ + class PackageInfo; + + class MatchSpec + { + public: + + using NameSpec = GlobSpec; + using BuildStringSpec = ChimeraStringSpec; + using platform_set = typename UnresolvedChannel::platform_set; + using platform_set_const_ref = std::reference_wrapper; + using string_set = typename util::flat_set; + using string_set_const_ref = typename std::reference_wrapper; + + inline static constexpr char url_md5_sep = '#'; + inline static constexpr char preferred_list_open = '['; + inline static constexpr char preferred_list_close = ']'; + inline static constexpr char alt_list_open = '('; + inline static constexpr char alt_list_close = ')'; + inline static constexpr char preferred_quote = '"'; + inline static constexpr char alt_quote = '\''; + inline static constexpr char channel_namespace_spec_sep = ':'; + inline static constexpr char attribute_sep = ','; + inline static constexpr char attribute_assign = '='; + inline static constexpr auto package_version_sep = std::array{ ' ', '=', '<', '>', '~', '!' }; + inline static constexpr auto feature_sep = std::array{ ' ', ',' }; + + + [[nodiscard]] static auto parse(std::string_view spec) -> expected_parse_t; + + [[nodiscard]] static auto parse_url(std::string_view spec) -> expected_parse_t; + + [[nodiscard]] auto channel() const -> const std::optional&; + void set_channel(std::optional chan); + + [[nodiscard]] auto filename() const -> std::string_view; + void set_filename(std::string val); + + [[nodiscard]] auto is_file() const -> bool; + + [[nodiscard]] auto platforms() const -> std::optional; + void set_platforms(platform_set val); + + [[nodiscard]] auto name_space() const -> const std::string&; + void set_name_space(std::string ns); + + [[nodiscard]] auto name() const -> const NameSpec&; + void set_name(NameSpec name); + + [[nodiscard]] auto version() const -> const VersionSpec&; + void set_version(VersionSpec ver); + + [[nodiscard]] auto build_number() const -> const BuildNumberSpec&; + void set_build_number(BuildNumberSpec num); + + [[nodiscard]] auto build_string() const -> const BuildStringSpec&; + void set_build_string(BuildStringSpec bs); + + [[nodiscard]] auto md5() const -> std::string_view; + void set_md5(std::string val); + + [[nodiscard]] auto sha256() const -> std::string_view; + void set_sha256(std::string val); + + [[nodiscard]] auto license() const -> std::string_view; + void set_license(std::string val); + + [[nodiscard]] auto license_family() const -> std::string_view; + void set_license_family(std::string val); + + [[nodiscard]] auto features() const -> std::string_view; + void set_features(std::string val); + + [[nodiscard]] auto track_features() const -> std::optional; + void set_track_features(string_set val); + + [[nodiscard]] auto optional() const -> bool; + void set_optional(bool opt); + + [[nodiscard]] auto conda_build_form() const -> std::string; + [[nodiscard]] auto to_string() const -> std::string; + + /** + * Return true if the MatchSpec can be written as `` ``. + */ + [[nodiscard]] auto is_simple() const -> bool; + + /** + * Return true if the MatchSpec contains an exact package name and nothing else. + */ + [[nodiscard]] auto is_only_package_name() const -> bool; + + /** + * Make a new MatchSpec that matches only on the name part. + */ + [[nodiscard]] auto to_named_spec() const -> MatchSpec; + + /** + * Check if the MatchSpec matches the given package. + * + * The check exclude anything related to the channel, du to the difficulties in + * comparing unresolved channels and the fact that this check can be also be done once + * at a repository level when the user knows how packages are organised. + * + * This function is written as a generic template, to accommodate various uses: the fact + * that the attributes may not always be in the correct format in the package, and that + * their parsing may be cached. + */ + template + [[nodiscard]] auto contains_except_channel(const Pkg& pkg) const -> bool; + + /** + * Convenience wrapper making necessary conversions. + */ + [[nodiscard]] auto contains_except_channel(const PackageInfo& pkg) const -> bool; + + /** + * Naive attribute-wise comparison. + * + * @warning Some complex matchspec could compare to false but actually represent the same + * set of packages. This strong equality is hard to detect. + */ + [[nodiscard]] auto operator==(const MatchSpec& other) const -> bool = default; + + [[nodiscard]] auto operator!=(const MatchSpec& other) const -> bool = default; + + auto extra_members_hash() const -> std::size_t; + + private: + + struct ExtraMembers + { + // The filename is stored as part of the channel when it is a full Package URL + std::string filename = {}; + // The filename is stored as part of the channel when it is available + platform_set subdirs = {}; + std::string md5 = {}; + std::string sha256 = {}; + std::string license = {}; + std::string license_family = {}; + std::string features = {}; + string_set track_features = {}; + bool optional = false; + + // TODO(C++20): replace by the `= default` implementation of `operator==` + [[nodiscard]] auto operator==(const ExtraMembers& other) const -> bool + { + return filename == other.filename // + && subdirs == other.subdirs // + && md5 == other.md5 // + && sha256 == other.sha256 // + && license == other.license // + && license_family == other.license_family // + && features == other.features // + && track_features == other.track_features // + && optional == other.optional; + } + + [[nodiscard]] auto operator!=(const ExtraMembers& other) const -> bool + { + return !(*this == other); + } + + friend struct std::hash; + }; + friend struct std::hash; + + std::optional m_channel; + VersionSpec m_version; + NameSpec m_name; + BuildStringSpec m_build_string; + std::string m_name_space; + BuildNumberSpec m_build_number; + util::heap_optional m_extra = {}; // unlikely data + + auto extra() -> ExtraMembers&; + + [[nodiscard]] auto channel_is_file() const -> bool; + [[nodiscard]] auto channel_filename() const -> std::string_view; + void set_channel_filename(std::string val); + + [[nodiscard]] auto extra_filename() const -> std::string_view; + void set_extra_filename(std::string val); + + [[nodiscard]] auto extra_subdirs() const -> std::optional; + void set_extra_subdirs(platform_set val); + }; + + namespace match_spec_literals + { + auto operator""_ms(const char* str, std::size_t len) -> MatchSpec; + } +} + +template <> +struct fmt::formatter<::mamba::specs::MatchSpec> +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::MatchSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::MatchSpec& spec) const -> std::size_t; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::MatchSpec::ExtraMembers& extra) const -> std::size_t; +}; + +/********************************* + * Implementation of MatchSpec * + *********************************/ + +namespace mamba::specs +{ + namespace detail + { + template + struct Deref + { + template + static auto deref(T&& x) -> decltype(auto) + { + return x; + } + }; + + template + struct Deref> + { + template + static auto deref(T&& x) -> decltype(auto) + { + return std::forward(x).get(); + } + }; + + template + auto invoke_pkg(Attr&& attr, Pkg&& pkg) -> decltype(auto) + { + using Return = std::decay_t>; + return Deref::deref(std::invoke(std::forward(attr), std::forward(pkg))); + } + } + + template + auto MatchSpec::contains_except_channel(const Pkg& pkg) const -> bool + { + if ( // + !name().contains(detail::invoke_pkg(&Pkg::name, pkg)) // + || !version().contains(detail::invoke_pkg(&Pkg::version, pkg)) // + || !build_string().contains(detail::invoke_pkg(&Pkg::build_string, pkg)) // + || !build_number().contains(detail::invoke_pkg(&Pkg::build_number, pkg)) // + || (!md5().empty() && (md5() != detail::invoke_pkg(&Pkg::md5, pkg))) // + || (!sha256().empty() && (sha256() != detail::invoke_pkg(&Pkg::sha256, pkg))) // + || (!license().empty() && (license() != detail::invoke_pkg(&Pkg::license, pkg))) // + ) + { + return false; + } + + if (const auto& plats = platforms(); + plats.has_value() && !plats->get().contains(detail::invoke_pkg(&Pkg::platform, pkg))) + { + return false; + } + + if (const auto& tfeats = track_features(); + tfeats.has_value() + && !util::set_is_subset_of(tfeats->get(), detail::invoke_pkg(&Pkg::track_features, pkg))) + { + return false; + } + + return true; + } +} + +#endif diff --git a/data/miniconda3/include/mamba/specs/package_info.hpp b/data/miniconda3/include/mamba/specs/package_info.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0cdd9f6d8dbda6f64b4714edc9e4e22cdce15b8c --- /dev/null +++ b/data/miniconda3/include/mamba/specs/package_info.hpp @@ -0,0 +1,137 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_CORE_PACKAGE_INFO +#define MAMBA_CORE_PACKAGE_INFO + +#include +#include +#include + +#include + +#include "mamba/specs/error.hpp" +#include "mamba/specs/platform.hpp" +#include "mamba/util/tuple_hash.hpp" + +namespace mamba::specs +{ + enum class PackageType + { + Unknown, + Conda, + Wheel, + TarGz, + }; + + class PackageInfo + { + public: + + std::string name = {}; + std::string version = {}; + std::string build_string = {}; + std::size_t build_number = 0; + /** + * Could contain "conda-forge", "conda-forge/linux-64", or a url. + * + * @todo need to use a proper type for channels + */ + std::string channel = {}; + std::string package_url = {}; + DynamicPlatform platform = {}; + std::string filename = {}; + std::string license = {}; + std::string md5 = {}; + std::string sha256 = {}; + std::string python_site_packages_path = {}; + std::string signatures = {}; + std::vector track_features = {}; + std::vector dependencies = {}; + std::vector constrains = {}; + // WARNING Be aware that `defaulted_keys` value, if set later, + // is not passed when going through `make_package_info` from libsolv + std::vector defaulted_keys = {}; + NoArchType noarch = NoArchType::No; + std::size_t size = 0; + std::size_t timestamp = 0; + // FIXME this is a temporary hack to accommodate Python wheels but wheels and conda + // PackageInfo, should really be split in different types. + // WARNING Be aware that `package_type` value, + // if set later to anything other than default (PackageType::Unknown), + // will not be passed when going through `make_package_info` from libsolv + PackageType package_type = PackageType::Unknown; + + [[nodiscard]] static auto from_url(std::string_view url) -> expected_parse_t; + + PackageInfo() = default; + explicit PackageInfo(std::string name); + PackageInfo(std::string name, std::string version, std::string build_string, std::size_t build_number); + PackageInfo(std::string name, std::string version, std::string build_string, std::string channel); + + [[nodiscard]] auto json_signable() const -> nlohmann::json; + // TODO: rename to_string, following C++ conventions + [[nodiscard]] auto str() const -> std::string; + [[nodiscard]] auto long_str() const -> std::string; + + /** + * Dynamically get a field (e.g. name, version) as a string. + */ + [[nodiscard]] auto field(std::string_view name) const -> std::string; + }; + + auto operator==(const PackageInfo& lhs, const PackageInfo& rhs) -> bool; + + auto operator!=(const PackageInfo& lhs, const PackageInfo& rhs) -> bool; + + void to_json(nlohmann::json& j, const PackageInfo& pkg); + + void from_json(const nlohmann::json& j, PackageInfo& pkg); +} + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::PackageInfo& pkg) const -> std::size_t + { + auto seed = std::size_t(0); + seed = mamba::util::hash_vals( + seed, + pkg.name, + pkg.version, + pkg.build_string, + pkg.build_number, + pkg.channel, + pkg.package_url, + pkg.platform, + pkg.filename, + pkg.license, + pkg.md5, + pkg.sha256, + pkg.signatures + ); + seed = mamba::util::hash_combine_val_range( + seed, + pkg.track_features.begin(), + pkg.track_features.end() + ); + seed = mamba::util::hash_combine_val_range( + seed, + pkg.dependencies.begin(), + pkg.dependencies.end() + ); + seed = mamba::util::hash_combine_val_range(seed, pkg.constrains.begin(), pkg.constrains.end()); + seed = mamba::util::hash_combine_val_range( + seed, + pkg.defaulted_keys.begin(), + pkg.defaulted_keys.end() + ); + seed = mamba::util::hash_vals(seed, pkg.noarch, pkg.size, pkg.timestamp, pkg.package_type); + return seed; + } +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/platform.hpp b/data/miniconda3/include/mamba/specs/platform.hpp new file mode 100644 index 0000000000000000000000000000000000000000..ae708edd497f6fac8a8c8980374591f8bd46fa11 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/platform.hpp @@ -0,0 +1,267 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + + +#ifndef MAMBA_SPECS_PLATFORM_HPP +#define MAMBA_SPECS_PLATFORM_HPP + +#include +#include +#include + +#include + +namespace mamba::specs +{ + /** + * All platforms known to Conda. + * + * When one platform name is the substring of another, the longest appears first so that + * it makes it easier to use in a parser. + */ + enum class KnownPlatform + { + noarch = 0, + linux_32, + linux_64, + linux_armv6l, + linux_armv7l, + linux_aarch64, + linux_ppc64le, + linux_ppc64, + linux_s390x, + linux_riscv32, + linux_riscv64, + osx_64, + osx_arm64, + win_32, + win_64, + win_arm64, + zos_z, + + // For reflexion purposes only + count_, + }; + + using DynamicPlatform = std::string; + + [[nodiscard]] constexpr auto known_platforms_count() -> std::size_t + { + return static_cast(KnownPlatform::count_); + } + + [[nodiscard]] constexpr auto known_platforms() + -> std::array; + + [[nodiscard]] constexpr auto known_platform_names() + -> std::array; + + /** + * Convert the enumeration to its conda string. + */ + [[nodiscard]] constexpr auto platform_name(KnownPlatform p) -> std::string_view; + + /** + * Return the enum matching the platform name. + */ + [[nodiscard]] auto platform_parse(std::string_view str) -> std::optional; + + [[nodiscard]] auto platform_is_linux(KnownPlatform plat) -> bool; + [[nodiscard]] auto platform_is_linux(DynamicPlatform plat) -> bool; + + [[nodiscard]] auto platform_is_osx(KnownPlatform plat) -> bool; + [[nodiscard]] auto platform_is_osx(DynamicPlatform plat) -> bool; + + [[nodiscard]] auto platform_is_win(KnownPlatform plat) -> bool; + [[nodiscard]] auto platform_is_win(DynamicPlatform plat) -> bool; + + [[nodiscard]] auto platform_is_noarch(KnownPlatform plat) -> bool; + [[nodiscard]] auto platform_is_noarch(DynamicPlatform plat) -> bool; + + /** + * Detect the platform on which mamba was built. + */ + [[nodiscard]] auto build_platform() -> KnownPlatform; + [[nodiscard]] auto build_platform_name() -> std::string_view; + + /** + * Serialize to JSON string. + */ + void to_json(nlohmann::json& j, const KnownPlatform& p); + + /** + * Deserialize from JSON string. + */ + void from_json(const nlohmann::json& j, KnownPlatform& p); + + /** + * Noarch packages are packages that are not architecture specific. + * + * Noarch packages only have to be built once. + */ + enum struct NoArchType + { + /** Not a noarch type. */ + No, + + /** Noarch generic packages allow users to distribute docs, datasets, and source code. */ + Generic, + + /** + * A noarch python package is a python package without any precompiled python files. + * + * Normally, precompiled files (`.pyc` or `__pycache__`) are bundled with the package. + * However, these files are tied to a specific version of Python and must therefore be + * generated for every target platform and architecture. + * This complicates the build process. + * For noarch Python packages these files are generated when installing the package by + * invoking the compilation process through the python binary that is installed in the + * same environment. + * + * @see https://www.anaconda.com/blog/condas-new-noarch-packages + * @see + * https://docs.conda.io/projects/conda/en/latest/user-guide/concepts/packages.html#noarch-python + */ + Python, + + // For reflexion purposes only + count_, + }; + + constexpr auto known_noarch_count() -> std::size_t + { + return static_cast(NoArchType::count_); + } + + constexpr auto known_noarch() -> std::array; + + constexpr auto known_noarch_names() -> std::array; + + /** + * Convert the enumeration to its conda string. + */ + constexpr auto noarch_name(NoArchType noarch) -> std::string_view; + + /** + * Return the enum matching the noarch name. + */ + auto noarch_parse(std::string_view str) -> std::optional; + + /** + * Serialize to JSON string. + */ + void to_json(nlohmann::json& j, const NoArchType& noarch); + + /** + * Deserialize from JSON string. + */ + void from_json(const nlohmann::json& j, NoArchType& noarch); + + /******************** + * Implementation * + ********************/ + + constexpr auto platform_name(KnownPlatform p) -> std::string_view + { + switch (p) + { + case KnownPlatform::noarch: + return "noarch"; + case KnownPlatform::linux_32: + return "linux-32"; + case KnownPlatform::linux_64: + return "linux-64"; + case KnownPlatform::linux_armv6l: + return "linux-armv6l"; + case KnownPlatform::linux_armv7l: + return "linux-armv7l"; + case KnownPlatform::linux_aarch64: + return "linux-aarch64"; + case KnownPlatform::linux_ppc64: + return "linux-ppc64"; + case KnownPlatform::linux_ppc64le: + return "linux-ppc64le"; + case KnownPlatform::linux_s390x: + return "linux-s390x"; + case KnownPlatform::linux_riscv32: + return "linux-riscv32"; + case KnownPlatform::linux_riscv64: + return "linux-riscv64"; + case KnownPlatform::osx_64: + return "osx-64"; + case KnownPlatform::osx_arm64: + return "osx-arm64"; + case KnownPlatform::win_32: + return "win-32"; + case KnownPlatform::win_64: + return "win-64"; + case KnownPlatform::win_arm64: + return "win-arm64"; + case KnownPlatform::zos_z: + return "zos-z"; + default: + return ""; + } + } + + constexpr auto known_platforms() -> std::array + { + auto out = std::array{}; + for (std::size_t idx = 0; idx < out.size(); ++idx) + { + out[idx] = static_cast(idx); + } + return out; + } + + constexpr auto known_platform_names() -> std::array + { + auto out = std::array{}; + auto iter = out.begin(); + for (auto p : known_platforms()) + { + *(iter++) = platform_name(p); + } + return out; + } + + constexpr auto noarch_name(NoArchType noarch) -> std::string_view + { + switch (noarch) + { + case NoArchType::No: + return "no"; + case NoArchType::Generic: + return "generic"; + case NoArchType::Python: + return "python"; + default: + return ""; + } + } + + constexpr auto known_noarch() -> std::array + { + auto out = std::array{}; + for (std::size_t idx = 0; idx < out.size(); ++idx) + { + out[idx] = static_cast(idx); + } + return out; + } + + constexpr auto known_noarch_names() -> std::array + { + auto out = std::array{}; + auto iter = out.begin(); + for (auto p : known_noarch()) + { + *(iter++) = noarch_name(p); + } + return out; + } +} +#endif diff --git a/data/miniconda3/include/mamba/specs/regex_spec.hpp b/data/miniconda3/include/mamba/specs/regex_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..936546b5a883e9b22d8d6f27047f52212f8bbe50 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/regex_spec.hpp @@ -0,0 +1,93 @@ +// Copyright (c) 2024, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_REGEX_SPEC +#define MAMBA_SPECS_REGEX_SPEC + +#include +#include +#include + +#include +#include + +#include "mamba/specs/error.hpp" + +namespace mamba::specs +{ + /** + * A matcher for regex expression. + */ + class RegexSpec + { + public: + + inline static constexpr std::string_view free_pattern = ".*"; + inline static constexpr char pattern_start = '^'; + inline static constexpr char pattern_end = '$'; + + [[nodiscard]] static auto parse(std::string pattern) -> expected_parse_t; + + RegexSpec(); + explicit RegexSpec(std::string raw_pattern); + + [[nodiscard]] auto contains(std::string_view str) const -> bool; + + /** + * Return true if the spec will match true on any input. + */ + [[nodiscard]] auto is_explicitly_free() const -> bool; + + /** + * Return true if the spec will match exactly one input. + */ + [[nodiscard]] auto is_exact() const -> bool; + + [[nodiscard]] auto to_string() const -> const std::string&; + + // TODO(C++20): replace by the `= default` implementation of `operator==` + [[nodiscard]] auto operator==(const RegexSpec& other) const -> bool + { + return m_raw_pattern == other.m_raw_pattern + && m_pattern.flags() == other.m_pattern.flags(); + } + + [[nodiscard]] auto operator!=(const RegexSpec& other) const -> bool + { + return !(*this == other); + } + + private: + + std::string m_raw_pattern; + std::regex m_pattern; + }; +} + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::RegexSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::RegexSpec& spec) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/repo_data.hpp b/data/miniconda3/include/mamba/specs/repo_data.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4573ed04726dc785933ea393c9a8be1d576e4808 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/repo_data.hpp @@ -0,0 +1,212 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#include +#include +#include +#include + +#include + +#include "mamba/specs/platform.hpp" +#include "mamba/specs/version.hpp" + +namespace mamba::specs +{ + + /** + * A single record in the Conda ``repodata.json``. + * + * A single record refers to a single binary distribution of a package on a Conda channel. + * + * Looking at the `RepoDataPackage` class in the Conda source code a record can also include + * the following fields but it is unclear what they do. + * - std::optional preferred_env; + * - std::optional date; + * - ? package_type + * Repodata also contains some of the following keys, although they are not parsed by Conda. + * - std::optional app_type; + * - std::optional app_entry; + * + * @see conda.models.records + * https://github.com/conda/conda/blob/main/conda/models/records.py + * @see rattler_conda_types::repo_data::PackageRecord + * https://github.com/mamba-org/rattler/blob/main/crates/rattler_conda_types/src/repo_data/mod.rs + */ + struct RepoDataPackage + { + /** The name of the package. */ + std::string name = {}; + + /** The version of the package. */ + Version version = Version(0, { { { 0 } } }); + + /** The build string of the package. */ + std::string build_string = {}; + + /** The build number of the package. */ + std::size_t build_number = {}; + + /** + * The subdirectory where the package can be found. + * + * This is likely not used as it contains not so useful strings such as "linux". + */ + std::optional subdir = {}; + + /** Optionally a MD5 hash of the package archive. */ + std::optional md5 = {}; + + /** Optionally a SHA256 hash of the package archive. */ + std::optional sha256 = {}; + + /** Optionally a path to the site-packages directory. */ + std::optional python_site_packages_path = {}; + + /** A deprecated md5 hash. */ + std::optional legacy_bz2_md5 = {}; + + /** A deprecated package archive size. */ + std::optional legacy_bz2_size = {}; + + /** Optionally the size of the package archive in bytes. */ + std::optional size = {}; + + /** Optionally the architecture the package supports. */ + std::optional arch = {}; + + /** Optionally the platform the package supports. */ + std::optional platform = {}; + + /** Specification of packages this package depends on. */ + std::vector depends = {}; + + /** + * Additional constraints on packages. + * + * `constrains` are different from `depends` in that packages specified in `depends` must + * be installed next to this package, whereas packages specified in `constrains` are not + * required to be installed, but if they are installed they must follow these constraints. + */ + std::vector constrains = {}; + + /** + * Track features are nowadays only used to deprioritize packages. + * + * To that effect, the number of track features is counted (number of commas) and the + * package is downweighted by the number of track_features. + */ + std::vector track_features = {}; + + /** + * Features are a deprecated way to specify different feature sets for the conda solver. + * + * This is not supported anymore and should not be used. + * Instead, `mutex` packages should be used to specify mutually exclusive features. + */ + std::optional features = {}; + + /** If this package is independent of architecture this field specifies in what way. */ + std::optional noarch = {}; + + /** The specific license of the package. */ + std::optional license = {}; + + /** The license family. */ + std::optional license_family = {}; + + /** + * The UNIX Epoch timestamp when this package was created. + * + * Note that sometimes this is specified in seconds and sometimes in milliseconds. + */ + std::optional timestamp = {}; + }; + + /** + * Serialize to JSON. + * + * Optional members are omitted from json. + */ + void to_json(nlohmann::json& j, const RepoDataPackage& p); + + /** + * Deserialize from JSON + * + * Missing json entries fill optionals with a null values and collections as empty. + * Special handling of the following fields is performed: + * - ``"noarch"`` can be a string or a boolean (old behaviour), in which case ``false`` + * parse to ``std::nullopt`` and ``true`` to ``NoArchType::Generic``. + * - ``"track_features"`` can be a string or list of string. In the former case, it is + * considered as a single element list. + */ + void from_json(const nlohmann::json& j, RepoDataPackage& p); + + /** Information about subdirectory of channel in the Conda RepoData. */ + struct ChannelInfo + { + /** The channel's subdirectory. */ + KnownPlatform subdir = {}; + }; + + /** Serialize to JSON. */ + void to_json(nlohmann::json& j, const ChannelInfo& info); + + /** Deserialize from JSON. */ + void from_json(const nlohmann::json& j, ChannelInfo& info); + + /** + * The repository data structure. + * + * This schema maps to the repository ``repodata.json``. + **/ + struct RepoData + { + /** The version of the repodata format. */ + std::optional version = {}; + + /** The channel information contained in the repodata.json file. + */ + std::optional info = {}; + + /** + * The tar.bz2 packages contained in the repodata.json file. + * + * Maps a filename sucha as ``libmamba-0.13.0-h3a044de_0.tar.bz2`` to its RepoDataPackage. + **/ + std::map packages = {}; + + /** + * The conda packages contained in the repodata.json file. + * + * Maps a filename such as ``libmamba-1.3.0-hcea66bb_1.conda`` to its RepoDataPackage. + * This is put under a different key for backwards compatibility with previous conda + * versions. + */ + std::map conda_packages = {}; + + /** + * Removed packages + * + * These files are still accessible, but they are not installable like regular packages. + */ + std::vector removed = {}; + }; + + /** + * Serialize to JSON. + * + * Optional members are omitted from json. + */ + void to_json(nlohmann::json& j, const RepoData& data); + + /** + * Deserialize from JSON + * + * Missing json entries fill optionals with a null values and collections as empty. + */ + void from_json(const nlohmann::json& j, RepoData& data); +} diff --git a/data/miniconda3/include/mamba/specs/unresolved_channel.hpp b/data/miniconda3/include/mamba/specs/unresolved_channel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..120dcef805b0fcfef9e1fa71ff8bb500cc7e0d43 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/unresolved_channel.hpp @@ -0,0 +1,162 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_UNRESOLVED_CHANNEL_HPP +#define MAMBA_SPECS_UNRESOLVED_CHANNEL_HPP + +#include +#include +#include + +#include +#include + +#include "mamba/specs/error.hpp" +#include "mamba/specs/platform.hpp" +#include "mamba/util/flat_set.hpp" +#include "mamba/util/tuple_hash.hpp" + +namespace mamba::specs +{ + /** + * Unresolved Channel specification. + * + * This represent an unverified channel string passed by the user, or written through files. + * Due the the heavy reliance of channels on configuration options, this placeholder type + * can be used to represent channel inputs that have not been "resolved" to s specific + * location. + * This can even be true when a full URL or path is given, as some authentication information + * may come from login database. + * + * Note that for a string to be considered a URL, it must have an explicit scheme. + * So "repo.anaconda.com" is considered a name, similarly to "conda-forge" and not a URL. + * This is because otherwise it is not possible to tell names and URL apart. + */ + class UnresolvedChannel + { + public: + + enum class Type + { + /** + * A URL to a full repo structure. + * + * Example "https://repo.anaconda.com/conda-forge". + */ + URL, + /** + * A URL to a single package. + * + * Example "https://repo.anaconda.com/conda-forge/linux-64/pkg-0.0-bld.conda". + */ + PackageURL, + /** + * An (possibly implicit) path to a full repo structure. + * + * Example "/Users/name/conda-bld", "./conda-bld", "~/.conda-bld". + */ + Path, + /** + * An (possibly implicit) path to a single-package. + * + * Example "/tmp/pkg-0.0-bld.conda", "./pkg-0.0-bld.conda", "~/pkg-0.0-bld.tar.bz2". + */ + PackagePath, + /** + * A relative name. + * + * It needs to be resolved using a channel alias, or a custom channel. + * Example "conda-forge", "locals", "my-channel/my-label". + */ + Name, + /** + * An unknown channel source. + * + * It is currently unclear why it is needed. + */ + Unknown, + }; + + static constexpr std::string_view platform_separators = "|,;"; + static constexpr std::string_view unknown_channel = ""; + static constexpr std::array invalid_channels_lower = { + "", + "none:///", + "none", + ":///", + }; + + using platform_set = util::flat_set; + + [[nodiscard]] static auto parse_platform_list(std::string_view plats) -> platform_set; + + [[nodiscard]] static auto parse(std::string_view str) -> expected_parse_t; + + UnresolvedChannel() = default; + UnresolvedChannel(std::string location, platform_set filters, Type type); + + [[nodiscard]] auto type() const -> Type; + + [[nodiscard]] auto location() const& -> const std::string&; + [[nodiscard]] auto location() && -> std::string; + auto clear_location() -> std::string; + + [[nodiscard]] auto platform_filters() const& -> const platform_set&; + [[nodiscard]] auto platform_filters() && -> platform_set; + auto clear_platform_filters() -> platform_set; + + [[nodiscard]] auto is_package() const -> bool; + + [[nodiscard]] auto str() const -> std::string; + + [[nodiscard]] auto operator==(const UnresolvedChannel& other) const -> bool + { + return m_location == other.m_location // + && m_platform_filters == other.m_platform_filters // + && m_type == other.m_type; + } + + [[nodiscard]] auto operator!=(const UnresolvedChannel& other) const -> bool + { + return !(*this == other); + } + + private: + + std::string m_location = std::string(unknown_channel); + platform_set m_platform_filters = {}; + Type m_type = Type::Unknown; + }; +} + +template <> +struct fmt::formatter +{ + using UnresolvedChannel = ::mamba::specs::UnresolvedChannel; + + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const UnresolvedChannel& uc, format_context& ctx) const -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::UnresolvedChannel& uc) const -> std::size_t + { + return mamba::util::hash_vals(uc.location(), uc.platform_filters(), static_cast(uc.type())); + } +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/version.hpp b/data/miniconda3/include/mamba/specs/version.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d11e12a6a4d1323c4d70a18da9160ed3992f0273 --- /dev/null +++ b/data/miniconda3/include/mamba/specs/version.hpp @@ -0,0 +1,305 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_VERSION_HPP +#define MAMBA_SPECS_VERSION_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/specs/error.hpp" +#include "mamba/util/charconv.hpp" + +namespace mamba::specs +{ + + /** + * A succession of a number and a lowercase literal. + * + * Comparison is done lexicographically, with the number first and the literal second. + * Certain literals have special meaning: + * "*" < "dev" < "_"< any other literal < "" < "post" + */ + class VersionPartAtom + { + public: + + VersionPartAtom() noexcept = default; + VersionPartAtom(std::size_t numeral) noexcept; + VersionPartAtom(std::size_t numeral, std::string_view literal); + // The use of a template is only meant to prevent ambiguous conversions + template + VersionPartAtom(std::size_t numeral, std::basic_string literal); + + [[nodiscard]] auto numeral() const noexcept -> std::size_t; + [[nodiscard]] auto literal() const& noexcept -> const std::string&; + auto literal() && noexcept -> std::string; + + [[nodiscard]] auto to_string() const -> std::string; + + private: + + // Stored in decreasing size order for performance + std::string m_literal = ""; + std::size_t m_numeral = 0; + }; + + auto operator==(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + auto operator!=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + auto operator<(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + auto operator<=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + auto operator>(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + auto operator>=(const VersionPartAtom& left, const VersionPartAtom& right) -> bool; + + extern template VersionPartAtom::VersionPartAtom(std::size_t, std::string); + + /** + * A sequence of VersionPartAtom meant to represent a part of a version (e.g. major, minor). + * + * In a version like ``1.3.0post1dev``, the parts are ``1``, ``3``, and ``0post1dev``. + * Version parts can have a arbitrary number of atoms, such as {0, "post"} {1, "dev"} + * in ``0post1dev``. + * + * @see Version::parse for how this is computed from strings. + * @todo Use a small vector of expected size 1 if performance ar not good enough. + */ + struct VersionPart + { + /** The atoms of the version part */ + std::vector atoms = {}; + + /** + * Whether a potential leading zero in the first atom should be considered implicit. + * + * During parsing of ``Version``, if a part starts with a literal atom, it is considered + * the same as if it started with a leading ``0``. + * For instance ``0post1dev`` is parsed in the same way as ``post1dev``. + * Marking it as implicit enables the possibility to remove it when reconstructing a string + * representation. + * This is desirable for compatibility with other version formats, such as Python, where + * a version modifier might be expressed as ``1.3.0.dev3``. + */ + bool implicit_leading_zero = false; + + VersionPart(); + VersionPart(std::initializer_list init); + VersionPart(std::vector atoms, bool implicit_leading_zero); + + [[nodiscard]] auto to_string() const -> std::string; + }; + + auto operator==(const VersionPart& left, const VersionPart& other) -> bool; + auto operator!=(const VersionPart& left, const VersionPart& other) -> bool; + auto operator<(const VersionPart& left, const VersionPart& other) -> bool; + auto operator<=(const VersionPart& left, const VersionPart& other) -> bool; + auto operator>(const VersionPart& left, const VersionPart& other) -> bool; + auto operator>=(const VersionPart& left, const VersionPart& other) -> bool; + + /** + * A sequence of VersionPart meant to represent all parts of a version. + * + * CommonVersion are composed of an arbitrary positive number parts, such as major, minor. + * They are typically separated by dots, for instance the three parts in 3.0post1dev.4 are + * {{3, ""}}, {{0, "post"}, {1, "dev"}}, and {{4, ""}}. + * + * @see Version::parse for how this is computed from strings. + * @todo Use a small vector of expected size 4 if performance ar not good enough. + */ + using CommonVersion = std::vector; + + /** + * A version according to Conda specifications. + * + * A version is composed of + * - A epoch number, usually 0; + * - A regular version, + * - An optional local. + * These elements are used to lexicographicaly compare two versions. + * + * @see https://github.com/conda/conda/blob/main/conda/models/version.py + */ + class Version + { + public: + + static constexpr char epoch_delim = '!'; + static constexpr char local_delim = '+'; + static constexpr char part_delim = '.'; + static constexpr char part_delim_alt = '-'; + static constexpr char part_delim_special = '_'; + + static auto parse(std::string_view str) -> expected_parse_t; + + /** Construct version ``0.0``. */ + Version() noexcept = default; + Version(std::size_t epoch, CommonVersion version, CommonVersion local = {}) noexcept; + + [[nodiscard]] auto epoch() const noexcept -> std::size_t; + [[nodiscard]] auto version() const noexcept -> const CommonVersion&; + [[nodiscard]] auto local() const noexcept -> const CommonVersion&; + + /** + * A string representation of the version. + * + * May not always be the same as the parsed string (due to reconstruction) but reparsing + * this string will give the same version. + * ``v == Version::parse(v.to_string())``. + */ + [[nodiscard]] auto to_string() const -> std::string; + + /** + * A string truncated of extended representation of the version. + * + * Represent the string with the desired number of parts. + * If the actual number of parts is larger, then the string is truncated. + * If the actual number of parts is smalle, then the string is expanded with zeros. + */ + [[nodiscard]] auto to_string(std::size_t level) const -> std::string; + + /** + * String representation that treats ``*`` as glob pattern. + * + * Instead of printing them as ``0*`` (as a special literal), it formats them as ``*``. + * In full, a version like ``*.1.*`` will print as such instead of ``0*.1.0*``. + */ + [[nodiscard]] auto to_string_glob() const -> std::string; + + /** + * Return true if this version starts with the other prefix. + * + * For instance 1.2.3 starts with 1.2 but not the opposite. + * Because Conda versions can contain an arbitrary number of segments, some of which + * with alpha releases, this function cannot be written as a comparison. + * One would need to comoare with a version with infinitely pre-release segments. + */ + [[nodiscard]] auto starts_with(const Version& prefix) const -> bool; + + /** + * Return true if this version is a compatible upgrade to the given one. + * + * For instance 1.3.1 is compatible with 1.2.1 at level 0 (first component `1 == 1``), + * at level 1 (second component `` 3 >= 2``), but not at level two (because the second + * component is strictly larger ``3 > 2``). + * Compatible versions are always smaller than the current version. + */ + [[nodiscard]] auto compatible_with(const Version& older, std::size_t level) const -> bool; + + private: + + // Stored in decreasing size order for performance + CommonVersion m_version = {}; + CommonVersion m_local = {}; + std::size_t m_epoch = 0; + }; + + auto operator==(const Version& left, const Version& other) -> bool; + auto operator!=(const Version& left, const Version& other) -> bool; + auto operator<(const Version& left, const Version& other) -> bool; + auto operator<=(const Version& left, const Version& other) -> bool; + auto operator>(const Version& left, const Version& other) -> bool; + auto operator>=(const Version& left, const Version& other) -> bool; + + namespace version_literals + { + auto operator""_v(const char* str, std::size_t len) -> Version; + } +} + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::VersionPartAtom atom, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct fmt::formatter +{ + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + // make sure that range is empty + if (ctx.begin() != ctx.end() && *ctx.begin() != '}') + { + throw fmt::format_error("Invalid format"); + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::VersionPart atom, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct fmt::formatter +{ + enum struct FormatType + { + Normal, + /** + * The Glob pattern, as used internally ``VersionPredicate``, lets you treat ``*`` as a + * glob pattern instead of the special character. + * It lets you format ``*.*`` as such instead of ``0*.0*``. + */ + Glob, + }; + + std::optional m_level; + FormatType m_type = FormatType::Normal; + + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + const auto end = ctx.end(); + const auto start = ctx.begin(); + + // Make sure that range is not empty + if (start == end || *start == '}') + { + return start; + } + + // Check for restricted number of segments at beginning + std::size_t val = 0; + auto [ptr, ec] = mamba::util::constexpr_from_chars(start, end, val); + if (ec == std::errc()) + { + m_level = val; + } + + // Check for end of format spec + if (ptr == end || *ptr == '}') + { + return ptr; + } + + // Check the custom format type + if (*ptr == 'g') + { + m_type = FormatType::Glob; + ++ptr; + } + + return ptr; + } + + auto format(const ::mamba::specs::Version v, format_context& ctx) const + -> format_context::iterator; +}; + +#endif diff --git a/data/miniconda3/include/mamba/specs/version_spec.hpp b/data/miniconda3/include/mamba/specs/version_spec.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f559d484dd61d9875df52a3f479a344f06c9fbae --- /dev/null +++ b/data/miniconda3/include/mamba/specs/version_spec.hpp @@ -0,0 +1,338 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_SPECS_VERSION_SPEC_HPP +#define MAMBA_SPECS_VERSION_SPEC_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/specs/error.hpp" +#include "mamba/specs/version.hpp" +#include "mamba/util/flat_bool_expr_tree.hpp" + +namespace mamba::specs +{ + /** + * A stateful unary boolean function on the Version space. + */ + class VersionPredicate + { + public: + + [[nodiscard]] static auto make_free() -> VersionPredicate; + [[nodiscard]] static auto make_equal_to(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_not_equal_to(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_greater(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_greater_equal(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_less(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_less_equal(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_starts_with(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_not_starts_with(Version ver) -> VersionPredicate; + [[nodiscard]] static auto make_compatible_with(Version ver, std::size_t level) + -> VersionPredicate; + [[nodiscard]] static auto make_version_glob(Version pattern) -> VersionPredicate; + [[nodiscard]] static auto make_not_version_glob(Version pattern) -> VersionPredicate; + + /** Construct an free interval. */ + VersionPredicate() = default; + + /** + * True if the predicate contains the given version. + */ + [[nodiscard]] auto contains(const Version& point) const -> bool; + + /** + * True if it contains a glob or negative glob expression. + * + * Does not return true for predicates that could be written as globs but are not. + */ + [[nodiscard]] auto has_glob() const -> bool; + + /** + * True if the predicate is a simple operator. + * + * Simple operators are ``=``, ``!=``, ``<``, ``<=``, ``>``, ``>=``. + */ + [[nodiscard]] auto is_classic_operator() const -> bool; + + [[nodiscard]] auto to_string() const -> std::string; + + /** + * An alternative string representation of the version spec. + * + * Attempts to be compatible with conda-build/libsolv. + */ + [[nodiscard]] auto to_string_conda_build() const -> std::string; + + private: + + struct free_interval + { + auto operator()(const Version&, const Version&) const -> bool; + }; + + struct starts_with + { + auto operator()(const Version&, const Version&) const -> bool; + }; + + struct not_starts_with + { + auto operator()(const Version&, const Version&) const -> bool; + }; + + struct compatible_with + { + std::size_t level; + auto operator()(const Version&, const Version&) const -> bool; + }; + + struct version_glob + { + auto operator()(const Version&, const Version&) const -> bool; + }; + + struct not_version_glob + { + auto operator()(const Version&, const Version&) const -> bool; + }; + + /** + * Operator to compare with the stored version. + * + * We could store arbitrary binary operators, but since this is tightly coupled with + * ``VersionSpec`` parsing (hence not user-extensible), and performance-sensitive, + * we choose an ``std::variant`` for dynamic dispatch. + * An alternative could be a type-erased wrapper with local storage. + * + * Not alternatives (``not_starts_with``, ``not_version_glob``) could also be implemented + * as a not operator in VersionSpec rather than a predicate, but they are used often enough + * to deserve their specialization. + */ + using BinaryOperator = std::variant< + free_interval, + std::equal_to, + std::not_equal_to, + std::greater, + std::greater_equal, + std::less, + std::less_equal, + starts_with, + not_starts_with, + compatible_with, + not_version_glob, + version_glob>; + + // Originally, with only stateless operators, it made sense to have the version factored + // in this class' attributes. However, with additions of variants that use the version + // for a different meaning (version_glob, compatible_with), or not at all (free interval), + // it would make sense to move it to each individual class for better scoping (e.g. see + // this class' operator==). + Version m_version = {}; + BinaryOperator m_operator = free_interval{}; + + VersionPredicate(Version ver, BinaryOperator op); + + friend auto operator==(free_interval, free_interval) -> bool; + friend auto operator==(starts_with, starts_with) -> bool; + friend auto operator==(not_starts_with, not_starts_with) -> bool; + friend auto operator==(compatible_with, compatible_with) -> bool; + friend auto operator==(version_glob, version_glob) -> bool; + friend auto operator==(not_version_glob, not_version_glob) -> bool; + friend auto operator==(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool; + friend struct ::fmt::formatter; + }; + + auto operator==(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool; + auto operator!=(const VersionPredicate& lhs, const VersionPredicate& rhs) -> bool; + + /** + * Represent a set of versions. + * + * Internally, a VersionSpec is a binary expression tree of union (or) or intersections (and) + * of the sets represented by VersionPredicate. + * + * The VersionSpec can itself be considered a complex predicate on the space of Version. + * + * Due to the complex nature of the expression system (comutativity, associativity, etc.), there + * is no easy way to say if two VersionSpecs are equal. + */ + class VersionSpec + { + public: + + using tree_type = util::flat_bool_expr_tree; + + static constexpr char and_token = ','; + static constexpr char or_token = '|'; + static constexpr char left_parenthesis_token = '('; + static constexpr char right_parenthesis_token = ')'; + + static constexpr std::string_view preferred_free_str = "=*"; + static constexpr std::array all_free_strs = { "", "*", "=*", "==*" }; + static constexpr std::string_view starts_with_str = "="; + static constexpr std::string_view equal_str = "=="; + static constexpr std::string_view not_equal_str = "!="; + static constexpr std::string_view greater_str = ">"; + static constexpr std::string_view greater_equal_str = ">="; + static constexpr std::string_view less_str = "<"; + static constexpr std::string_view less_equal_str = "<="; + static constexpr std::string_view compatible_str = "~="; + static constexpr std::string_view glob_suffix_str = ".*"; + static constexpr std::string_view glob_pattern_str = "*"; + + [[nodiscard]] static auto parse(std::string_view str) -> expected_parse_t; + + /** + * Create a Version spec with a single predicate in the expression. + */ + [[nodiscard]] static auto from_predicate(VersionPredicate pred) -> VersionSpec; + + /** Construct VersionSpec that match all versions. */ + VersionSpec() = default; + explicit VersionSpec(tree_type&& tree) noexcept; + + /** + * Returns whether the VersionSpec is unconstrained. + * + * Due to the complex nature of VersionSpec expressions, it is not always easy to know + * whether a complex expression can be simplified to the unconstrained one. + * This functions only handles the trivial cases. + */ + [[nodiscard]] auto is_explicitly_free() const -> bool; + + /** + * True if it contains a glob or negative glob expression anywhere in the tree. + * + * Does not return true for predicates that could be written as globs but are not. + */ + [[nodiscard]] auto has_glob() const -> bool; + + /** + * True if the version spec is an expression composed of simple operators. + * + * @see VersionPredicate::is_classic_operator + */ + [[nodiscard]] auto is_classic_operator_expression() const -> bool; + + /** + * A string representation of the version spec. + * + * May not always be the same as the parsed string (due to reconstruction) but reparsing + * this string will give the same version spec. + */ + [[nodiscard]] auto to_string() const -> std::string; + + /** + * An alternative string representation of the version spec. + * + * Attempts to be compatible with conda-build/libsolv. + */ + [[nodiscard]] auto to_string_conda_build() const -> std::string; + + /** + * True if the set described by the VersionSpec contains the given version. + */ + [[nodiscard]] auto contains(const Version& point) const -> bool; + + /** + * Return the size of the boolean expression tree. + */ + [[nodiscard]] auto expression_size() const -> std::size_t; + + [[nodiscard]] auto operator==(const VersionSpec& other) const -> bool + { + return m_tree == other.m_tree; + } + + [[nodiscard]] auto operator!=(const VersionSpec& other) const -> bool + { + return !(*this == other); + } + + private: + + tree_type m_tree; + + friend struct ::fmt::formatter; + }; + + namespace version_spec_literals + { + auto operator""_vs(const char* str, std::size_t len) -> VersionSpec; + } +} + +template <> +struct fmt::formatter +{ + /** + * Change the representation of some predicates not understood by conda-build/libsolv. + */ + bool conda_build_form = false; + + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + const auto end = ctx.end(); + for (auto it = ctx.begin(); it != end; ++it) + { + if (*it == 'b') + { + conda_build_form = true; + return ++it; + } + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::VersionPredicate& pred, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct fmt::formatter +{ + /** + * Change the representation of some predicates not understood by conda-build/libsolv. + */ + bool conda_build_form = false; + + constexpr auto parse(format_parse_context& ctx) -> format_parse_context::iterator + { + const auto end = ctx.end(); + for (auto it = ctx.begin(); it != end; ++it) + { + if (*it == 'b') + { + conda_build_form = true; + return ++it; + } + } + return ctx.begin(); + } + + auto format(const ::mamba::specs::VersionSpec& spec, format_context& ctx) const + -> format_context::iterator; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::VersionPredicate& pred) const -> std::size_t; +}; + +template <> +struct std::hash +{ + auto operator()(const mamba::specs::VersionSpec& spec) const -> std::size_t; +}; + +#endif diff --git a/data/miniconda3/include/mamba/validation/errors.hpp b/data/miniconda3/include/mamba/validation/errors.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b9ef5f485423bb251171287c20deb67333e88f52 --- /dev/null +++ b/data/miniconda3/include/mamba/validation/errors.hpp @@ -0,0 +1,157 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_ERRORS_HPP +#define MAMBA_VALIDATION_ERRORS_HPP + +#include +#include +#include + +namespace mamba::validation +{ + /** + * Base class for artifact/package verification error. + */ + class trust_error : public std::exception + { + public: + + trust_error(std::string_view message); + ~trust_error() override = default; + [[nodiscard]] auto what() const noexcept -> const char* override; + + private: + + std::string m_message; + }; + + /** + * Error raised when a threshold of signatures is not met. + * + * This can be due to wrong signatures, wrong or missing public keys. + */ + class threshold_error : public trust_error + { + public: + + threshold_error(); + ~threshold_error() override = default; + }; + + /** + * Error raised when wrong metadata are spotted + * in a role file. + */ + class role_metadata_error : public trust_error + { + public: + + role_metadata_error(); + ~role_metadata_error() override = default; + }; + + /** + * Error raised when a wrong file name is + * detected for role metadata. + */ + class role_file_error : public trust_error + { + public: + + role_file_error(); + ~role_file_error() override = default; + }; + + /** + * Error raised when a possible rollback attack is detected. + */ + class rollback_error : public trust_error + { + public: + + rollback_error(); + ~rollback_error() override = default; + }; + + /** + * Error raised when a possible freeze attack is detected. + */ + class freeze_error : public trust_error + { + public: + + freeze_error(); + ~freeze_error() override = default; + }; + + /** + * Error raised when a spec version is either wrong/invalid or not supported by the client. + */ + class spec_version_error : public trust_error + { + public: + + spec_version_error(); + ~spec_version_error() override = default; + }; + + /** + * Error raised when a role metadata file fetching process fails. + */ + class fetching_error : public trust_error + { + public: + + fetching_error(); + ~fetching_error() override = default; + }; + + /** + * Error raised when signatures threshold is not met for a package. + */ + class package_error : public trust_error + { + public: + + package_error(); + ~package_error() override = default; + }; + + /** + * Error raised when signatures threshold is not met for a trust role. + */ + class role_error : public trust_error + { + public: + + role_error(); + ~role_error() override = default; + }; + + /** + * Error raised when an invalid package index is met. + */ + class index_error : public trust_error + { + public: + + index_error(); + ~index_error() override = default; + }; + + /** + * Error raised when the given signatures of a package are empty/invalid. + */ + class signatures_error : public trust_error + { + public: + + signatures_error(); + ~signatures_error() override = default; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/validation/keys.hpp b/data/miniconda3/include/mamba/validation/keys.hpp new file mode 100644 index 0000000000000000000000000000000000000000..af278b27c400e62d77485c4ce3b6a61d56c009a3 --- /dev/null +++ b/data/miniconda3/include/mamba/validation/keys.hpp @@ -0,0 +1,96 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_UPDATE_FRAMEWORK_ROLES_HPP +#define MAMBA_VALIDATION_UPDATE_FRAMEWORK_ROLES_HPP + +#include +#include + +#include + +namespace mamba::validation +{ + /** + * Representation of the public part of a cryptographic key pair. + */ + struct Key + { + std::string keytype = ""; + std::string scheme = ""; + std::string keyval = ""; + + [[nodiscard]] static auto from_ed25519(std::string keyval) -> Key; + }; + + void to_json(nlohmann::json& j, const Key& k); + void from_json(const nlohmann::json& j, Key& k); + + /** + * Representation of a role signature. + * + * Optional 'pgp_trailer' will trigger special handling during verification to conform to + * OpenPGP RFC4880. + */ + struct RoleSignature + { + std::string keyid = ""; + std::string sig = ""; + std::string pgp_trailer = ""; + }; + + void to_json(nlohmann::json& j, const RoleSignature& rs); + void from_json(const nlohmann::json& j, RoleSignature& rs); + + [[nodiscard]] auto operator<(const RoleSignature& rs1, const RoleSignature& rs2) -> bool; + + /** + * Store key IDs and threshold for a role. + * + * Key ID can be a hash of Key, or just its public key value. + */ + struct RoleKeys + { + std::vector keyids; + std::size_t threshold; + }; + + void to_json(nlohmann::json& j, const RoleKeys& rk); + void from_json(const nlohmann::json& j, RoleKeys& rk); + + /** + * Store key values and threshold for role. Assumes key scheme/type is `ed25519`. + */ + struct RolePubKeys + { + std::vector pubkeys; + std::size_t threshold; + + [[nodiscard]] auto to_role_keys() const -> RoleKeys; + }; + + void to_json(nlohmann::json& j, const RolePubKeys& rk); + void from_json(const nlohmann::json& j, RolePubKeys& rk); + + /** + * Store full keys and threshold for role. + */ + struct RoleFullKeys + { + RoleFullKeys() = default; + RoleFullKeys(const std::map& keys_, const std::size_t& threshold_); + + std::map keys; + std::size_t threshold; + + [[nodiscard]] auto to_keys() const -> std::map; + [[nodiscard]] auto to_roles() const -> RoleKeys; + }; + + void to_json(nlohmann::json& j, const RoleFullKeys& r); + void from_json(const nlohmann::json& j, RoleFullKeys& r); +} +#endif diff --git a/data/miniconda3/include/mamba/validation/repo_checker.hpp b/data/miniconda3/include/mamba/validation/repo_checker.hpp new file mode 100644 index 0000000000000000000000000000000000000000..e04360bf90e054340c43608318541d9ab1074927 --- /dev/null +++ b/data/miniconda3/include/mamba/validation/repo_checker.hpp @@ -0,0 +1,89 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_REPO_CHECKER_HPP +#define MAMBA_VALIDATION_REPO_CHECKER_HPP + +#include +#include +#include + +#include + +#include "mamba/fs/filesystem.hpp" + +namespace mamba +{ + class Context; +} + +namespace mamba::validation +{ + class RepoIndexChecker; + class RootRole; + class TimeRef; + + /** + * Perform security check against a repository package index using cryptographic signatures. + * + * Relies on multiple roles defined in The Update Framework specification. + */ + class RepoChecker + { + public: + + /** + * Constructor. + * + * @param base_url Repository base URL + * @param ref_path Path to the reference directory, hosting trusted root metadata + * @param cache_path Path to the cache directory + */ + RepoChecker( + const Context& context, + std::string base_url, + fs::u8path ref_path, + fs::u8path cache_path = "" + ); + RepoChecker(RepoChecker&&) noexcept; + ~RepoChecker(); + + auto operator=(RepoChecker&&) noexcept -> RepoChecker&; + + // Forwarding to a ``RepoIndexChecker`` implementation + void verify_index(const nlohmann::json& j) const; + void verify_index(const fs::u8path& p) const; + void + verify_package(const nlohmann::json& signed_data, const nlohmann::json& signatures) const; + void verify_package(const nlohmann::json& signed_data, std::string_view signatures) const; + + void generate_index_checker(); + + auto cache_path() const -> const fs::u8path&; + auto root_version() const -> std::size_t; + + private: + + std::unique_ptr p_index_checker; + std::reference_wrapper m_context; + + std::string m_base_url; + fs::u8path m_ref_path; + fs::u8path m_cache_path; + + std::size_t m_root_version; + + auto ref_root() const -> fs::u8path; + auto cached_root() const -> fs::u8path; + + auto initial_trusted_root() const -> fs::u8path; + + void persist_file(const fs::u8path& file_path); + + auto get_root_role(const TimeRef& time_reference) -> std::unique_ptr; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/validation/tools.hpp b/data/miniconda3/include/mamba/validation/tools.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2c222c94a0922520ef21b31dfac9bfd04d96184e --- /dev/null +++ b/data/miniconda3/include/mamba/validation/tools.hpp @@ -0,0 +1,88 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_TOOLS_HPP +#define MAMBA_VALIDATION_TOOLS_HPP + +#include +#include +#include + +namespace mamba::fs +{ + class u8path; +} + +namespace mamba::validation +{ + [[nodiscard]] auto sha256sum(const fs::u8path& path) -> std::string; + + [[nodiscard]] auto md5sum(const fs::u8path& path) -> std::string; + + auto file_size(const fs::u8path& path, std::uintmax_t validation) -> bool; + + inline constexpr std::size_t MAMBA_SHA256_SIZE_HEX = 64; + inline constexpr std::size_t MAMBA_SHA256_SIZE_BYTES = 32; + inline constexpr std::size_t MAMBA_MD5_SIZE_HEX = 32; + inline constexpr std::size_t MAMBA_MD5_SIZE_BYTES = 16; + inline constexpr std::size_t MAMBA_ED25519_KEYSIZE_HEX = 64; + inline constexpr std::size_t MAMBA_ED25519_KEYSIZE_BYTES = 32; + inline constexpr std::size_t MAMBA_ED25519_SIGSIZE_HEX = 128; + inline constexpr std::size_t MAMBA_ED25519_SIGSIZE_BYTES = 64; + + auto generate_ed25519_keypair(std::byte* pk, std::byte* sk) -> int; + auto generate_ed25519_keypair() -> std::pair< + std::array, + std::array>; + auto generate_ed25519_keypair_hex() -> std::pair; + + auto sign(const std::string& data, const std::byte* sk, std::byte* signature) -> int; + auto sign(const std::string& data, const std::string& sk, std::string& signature) -> int; + + auto ed25519_sig_hex_to_bytes(const std::string& sig_hex, int& error_code) noexcept + -> std::array; + + auto ed25519_key_hex_to_bytes(const std::string& key_hex, int& error_code) noexcept + -> std::array; + + auto + verify(const std::byte* data, std::size_t data_len, const std::byte* pk, const std::byte* signature) + -> int; + auto verify(const std::string& data, const std::byte* pk, const std::byte* signature) -> int; + auto verify(const std::string& data, const std::string& pk_hex, const std::string& signature_hex) + -> int; + + /** + * Verify a GPG/PGP signature against the hash of the binary data and + * the additional trailer added in V4 signature. + * See RFC4880, section 5.2.4 https://datatracker.ietf.org/doc/html/rfc4880#section-5.2.4 + * This method assumes hash function to be SHA-256 + */ + auto verify_gpg_hashed_msg(const std::byte* data, const std::byte* pk, const std::byte* signature) + -> int; + auto + verify_gpg_hashed_msg(const std::string& data, const std::byte* pk, const std::byte* signature) + -> int; + auto + verify_gpg_hashed_msg(const std::string& data, const std::string& pk, const std::string& signature) + -> int; + + /** + * Verify a GPG/PGP signature against the binary data and + * the additional trailer added in V4 signature. + * See RFC4880, section 5.2.4 https://datatracker.ietf.org/doc/html/rfc4880#section-5.2.4 + * This method assumes hash function to be SHA-256 + */ + auto verify_gpg( + const std::string& data, + const std::string& gpg_v4_trailer, + const std::string& pk, + const std::string& signature + ) -> int; + + void check_timestamp_metadata_format(const std::string& ts); +} +#endif diff --git a/data/miniconda3/include/mamba/validation/update_framework.hpp b/data/miniconda3/include/mamba/validation/update_framework.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2e163c703506b0e6acb0d750ef1849b76905b2ed --- /dev/null +++ b/data/miniconda3/include/mamba/validation/update_framework.hpp @@ -0,0 +1,212 @@ +// Copyright (c) 2019, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_UPDATE_FRAMEWORK_HPP +#define MAMBA_VALIDATION_UPDATE_FRAMEWORK_HPP + +#include +#include +#include +#include + +#include + +#include "mamba/core/timeref.hpp" +#include "mamba/validation/keys.hpp" + +namespace mamba +{ + class Context; + + namespace fs + { + class u8path; + } +} + +namespace mamba::validation +{ + class RepoIndexChecker; + + /** + * Base class for spec implementations. + */ + class SpecBase + { + public: + + virtual ~SpecBase() = default; + + [[nodiscard]] auto version_str() const -> std::string; + + [[nodiscard]] virtual auto canonicalize(const nlohmann::json& j) const -> std::string; + + [[nodiscard]] auto compatible_prefix() const -> std::string; + [[nodiscard]] auto upgrade_prefix() const -> std::vector; + + [[nodiscard]] auto is_compatible(const fs::u8path& p) const -> bool; + [[nodiscard]] auto is_compatible(const nlohmann::json& j) const -> bool; + [[nodiscard]] auto is_compatible(const std::string& version) const -> bool; + + [[nodiscard]] auto is_upgrade(const nlohmann::json& j) const -> bool; + [[nodiscard]] auto is_upgrade(const std::string& version) const -> bool; + + [[nodiscard]] virtual auto upgradable() const -> bool; + + [[nodiscard]] virtual auto json_key() const -> std::string = 0; + [[nodiscard]] virtual auto expiration_json_key() const -> std::string = 0; + + [[nodiscard]] virtual auto signatures(const nlohmann::json& j) const + -> std::set + = 0; + + protected: + + SpecBase(std::string spec_version); + + [[nodiscard]] auto get_json_value(const nlohmann::json& j) const -> std::string; + + private: + + std::string m_spec_version; + }; + + auto operator==(const SpecBase& sv1, const SpecBase& sv2) -> bool; + auto operator!=(const SpecBase& sv1, const SpecBase& sv2) -> bool; + + /** + * Base class for role implementation. + */ + class RoleBase + { + public: + + RoleBase(std::string type, std::shared_ptr sv); + + virtual ~RoleBase() = 0; + + [[nodiscard]] auto type() const -> std::string; + [[nodiscard]] auto spec_version() const -> SpecBase&; + [[nodiscard]] auto version() const -> std::size_t; + [[nodiscard]] auto file_ext() const -> std::string; + [[nodiscard]] auto expires() const -> std::string; + + [[nodiscard]] auto expired(const TimeRef& time_reference) const -> bool; + + [[nodiscard]] auto roles() const -> std::set; + [[nodiscard]] auto signatures(const nlohmann::json& j) const -> std::set; + + [[nodiscard]] virtual auto self_keys() const -> RoleFullKeys = 0; + [[nodiscard]] auto all_keys() const -> std::map; + + protected: + + [[nodiscard]] auto read_json_file(const fs::u8path& p, bool update = false) const + -> nlohmann::json; + + /** + * Check that a threshold of valid signatures is met + * for the signed metadata of a role, using another + * role keys (possibly the same). + * Both signed and signatures metadata are contained + * in 'data'. + */ + void check_role_signatures(const nlohmann::json& data, const RoleBase& role); + /** + * Check that a threshold of valid signatures is met + * for the signed metadata, using a set of keys. + */ + void check_signatures( + const std::string& signed_data, + const std::set& signatures, + const RoleFullKeys& keyring + ) const; + + void set_spec_version(std::shared_ptr sv); + void set_expiration(const std::string& expires); + + // Forwarding to spec implementation + [[nodiscard]] auto canonicalize(const nlohmann::json& j) const -> std::string; + // Return the spec implementation + [[nodiscard]] auto spec_impl() const -> std::shared_ptr; + + // Mandatory roles defined by the current role + [[nodiscard]] virtual auto mandatory_defined_roles() const -> std::set; + // Optional roles defined by the current role + [[nodiscard]] virtual auto optionally_defined_roles() const -> std::set; + + // Check role + void check_expiration_format() const; + void check_defined_roles(bool allow_any = false) const; + + std::map m_defined_roles; + + private: + + std::string m_internal_type; + std::string m_type; + std::shared_ptr p_spec; + std::size_t m_version = 1; + std::string m_expires; + std::string m_ext = "json"; + + friend void to_json(nlohmann::json& j, const RoleBase& r); + friend void from_json(const nlohmann::json& j, RoleBase& r); + }; + + void to_json(nlohmann::json& j, const RoleBase& role); + void from_json(const nlohmann::json& j, RoleBase& role); + + /** + * 'root' role interface. + */ + class RootRole : public RoleBase + { + public: + + ~RootRole() override = default; + + auto update(fs::u8path path) -> std::unique_ptr; + auto update(nlohmann::json j) -> std::unique_ptr; + + auto possible_update_files() -> std::vector; + + virtual auto build_index_checker( + const Context& context, + const TimeRef& time_reference, + const std::string& url, + const fs::u8path& cache_path + ) const -> std::unique_ptr + = 0; + + protected: + + RootRole(std::shared_ptr spec); + + private: + + virtual auto create_update(const nlohmann::json& j) -> std::unique_ptr = 0; + }; + + /** + * Interface that performs validity checks + * on a repository packages index. + */ + class RepoIndexChecker + { + public: + + virtual ~RepoIndexChecker() = default; + virtual void verify_index(const nlohmann::json& j) const = 0; + virtual void verify_index(const fs::u8path& p) const = 0; + virtual void verify_package(const nlohmann::json& signed_data, const nlohmann::json& signatures) const = 0; + + protected: + + RepoIndexChecker() = default; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/validation/update_framework_v0_6.hpp b/data/miniconda3/include/mamba/validation/update_framework_v0_6.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3dd6ba35ceb404a13cea7f293e62392dbcede44e --- /dev/null +++ b/data/miniconda3/include/mamba/validation/update_framework_v0_6.hpp @@ -0,0 +1,198 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_UPDATE_FRAMEWORK_V0_6_HPP +#define MAMBA_VALIDATION_UPDATE_FRAMEWORK_V0_6_HPP + +#include +#include +#include + +#include + +#include "mamba/validation/keys.hpp" +#include "mamba/validation/update_framework.hpp" + +namespace mamba::validation::v0_6 +{ + /** + * The Update Frameworkd ``conda-content-trust`` v0.6.0 specific implementation. + * + * This is a variation of TUF specification. + */ + class SpecImpl final : public SpecBase + { + public: + + SpecImpl(std::string sv = "0.6.0"); + + [[nodiscard]] auto json_key() const -> std::string override; + [[nodiscard]] auto expiration_json_key() const -> std::string override; + + [[nodiscard]] auto signatures(const nlohmann::json& j) const + -> std::set override; + + [[nodiscard]] auto canonicalize(const nlohmann::json& j) const -> std::string override; + [[nodiscard]] auto upgradable() const -> bool override; + }; + + class V06RoleBaseExtension + { + public: + + void set_timestamp(const std::string& ts); + + [[nodiscard]] auto timestamp() const -> std::string; + + protected: + + std::string m_timestamp; + + void check_timestamp_format() const; + }; + + // Forward declaration of KeyMgrRole. + class KeyMgrRole; + + /** + * 'root' role implementation. + */ + class RootImpl final + : public RootRole + , public V06RoleBaseExtension + { + public: + + RootImpl(const fs::u8path& p); + RootImpl(const nlohmann::json& j); + RootImpl(const std::string& json_str); + + /** + * Return a ``RepoIndexChecker`` implementation (derived class) from repository base URL. + */ + auto build_index_checker( + const Context& context, + const TimeRef& time_reference, + const std::string& url, + const fs::u8path& cache_path + ) const -> std::unique_ptr override; + + [[nodiscard]] auto self_keys() const -> RoleFullKeys override; + + [[nodiscard]] auto upgraded_signable() const -> nlohmann::json; + auto + upgraded_signature(const nlohmann::json& j, const std::string& pk, const std::byte* sk) const + -> RoleSignature; + + [[nodiscard]] auto create_key_mgr(const fs::u8path& p) const -> KeyMgrRole; + [[nodiscard]] auto create_key_mgr(const nlohmann::json& j) const -> KeyMgrRole; + + friend void to_json(nlohmann::json& j, const RootImpl& r); + friend void from_json(const nlohmann::json& j, RootImpl& r); + + private: + + void load_from_json(const nlohmann::json& j); + + auto create_update(const nlohmann::json& j) -> std::unique_ptr override; + + [[nodiscard]] auto mandatory_defined_roles() const -> std::set override; + [[nodiscard]] auto optionally_defined_roles() const -> std::set override; + + void set_defined_roles(std::map keys); + }; + + + class PkgMgrRole; + + /** + * The Update Framework 'key_mgr' role implementation. + */ + class KeyMgrRole final + : public RoleBase + , public V06RoleBaseExtension + { + public: + + KeyMgrRole(const fs::u8path& p, RoleFullKeys keys, const std::shared_ptr spec); + KeyMgrRole(const nlohmann::json& j, RoleFullKeys keys, const std::shared_ptr spec); + KeyMgrRole(const std::string& json_str, RoleFullKeys keys, const std::shared_ptr spec); + + // std::set roles() const override; + [[nodiscard]] auto self_keys() const -> RoleFullKeys override; + + [[nodiscard]] auto create_pkg_mgr(const fs::u8path& p) const -> PkgMgrRole; + [[nodiscard]] auto create_pkg_mgr(const nlohmann::json& j) const -> PkgMgrRole; + + /** + * Return a ``RepoIndexChecker`` implementation (derived class) from repository base URL. + */ + auto build_index_checker( + const Context& context, + const TimeRef& time_reference, + const std::string& url, + const fs::u8path& cache_path + ) const -> std::unique_ptr; + + friend void to_json(nlohmann::json& j, const KeyMgrRole& r); + friend void from_json(const nlohmann::json& j, KeyMgrRole& r); + + private: + + void load_from_json(const nlohmann::json& j); + + RoleFullKeys m_keys; + std::map m_delegations; + + [[nodiscard]] auto mandatory_defined_roles() const -> std::set override; + [[nodiscard]] auto optionally_defined_roles() const -> std::set override; + + void set_defined_roles(std::map keys); + }; + + /** + * The Update Framework 'pkg_mgr' role implementation. + * + * This role inherits from ``RepoIndexChecker`` and will be used by ``RepoChecker`` to + * perform the repository index verification. + */ + class PkgMgrRole final + : public RoleBase + , public V06RoleBaseExtension + , public RepoIndexChecker + { + public: + + PkgMgrRole(RoleFullKeys keys, const std::shared_ptr spec); + PkgMgrRole(const fs::u8path& p, RoleFullKeys keys, const std::shared_ptr spec); + PkgMgrRole(const nlohmann::json& j, RoleFullKeys keys, const std::shared_ptr spec); + PkgMgrRole(const std::string& json_str, RoleFullKeys keys, const std::shared_ptr spec); + + void verify_index(const fs::u8path& p) const override; + void verify_index(const nlohmann::json& j) const override; + void + verify_package(const nlohmann::json& signed_data, const nlohmann::json& signatures) const override; + + friend void to_json(nlohmann::json& j, const PkgMgrRole& r); + friend void from_json(const nlohmann::json& j, PkgMgrRole& r); + + private: + + void load_from_json(const nlohmann::json& j); + + [[nodiscard]] auto self_keys() const -> RoleFullKeys override; + [[nodiscard]] auto pkg_signatures(const nlohmann::json& j) const -> std::set; + void + check_pkg_signatures(const nlohmann::json& signed_data, const nlohmann::json& signatures) const; + + void set_defined_roles(std::map keys); + + RoleFullKeys m_keys; + + friend class KeyMgrRole; + }; +} +#endif diff --git a/data/miniconda3/include/mamba/validation/update_framework_v1.hpp b/data/miniconda3/include/mamba/validation/update_framework_v1.hpp new file mode 100644 index 0000000000000000000000000000000000000000..9646fdb5c193063e684690f1010d682f7eca17aa --- /dev/null +++ b/data/miniconda3/include/mamba/validation/update_framework_v1.hpp @@ -0,0 +1,81 @@ +// Copyright (c) 2023, QuantStack and Mamba Contributors +// +// Distributed under the terms of the BSD 3-Clause License. +// +// The full license is in the file LICENSE, distributed with this software. + +#ifndef MAMBA_VALIDATION_UPDATE_FRAMEWORK_V1_HPP +#define MAMBA_VALIDATION_UPDATE_FRAMEWORK_V1_HPP + +#include +#include + +#include + +#include "mamba/validation/keys.hpp" +#include "mamba/validation/update_framework.hpp" + +namespace mamba::fs +{ + class u8path; +} + +namespace mamba::validation::v1 +{ + /** + * TUF v1 specific implementation. + */ + class SpecImpl final : public SpecBase + { + public: + + SpecImpl(std::string sv = "1.0.17"); + + [[nodiscard]] auto json_key() const -> std::string override; + [[nodiscard]] auto expiration_json_key() const -> std::string override; + + [[nodiscard]] auto signatures(const nlohmann::json& j) const + -> std::set override; + }; + + /** + * The Update Frameworkd 'root' role implementation. + * + * TUF v1.0.17 ยง2.1.1 + * https://theupdateframework.github.io/specification/latest/#root + */ + class RootImpl final : public RootRole + { + public: + + RootImpl(const fs::u8path& p); + RootImpl(const nlohmann::json& j); + + [[nodiscard]] auto self_keys() const -> RoleFullKeys override; + + auto build_index_checker( + const Context& context, + const TimeRef& time_reference, + const std::string& url, + const fs::u8path& cache_path + ) const -> std::unique_ptr override; + + friend void to_json(nlohmann::json& j, const RootImpl& r); + friend void from_json(const nlohmann::json& j, RootImpl& r); + + private: + + void load_from_json(const nlohmann::json& j); + + auto create_update(const nlohmann::json& j) -> std::unique_ptr override; + + [[nodiscard]] auto mandatory_defined_roles() const -> std::set override; + [[nodiscard]] auto optionally_defined_roles() const -> std::set override; + + void set_defined_roles( + const std::map& keys, + const std::map& roles + ); + }; +} +#endif diff --git a/data/miniconda3/include/yaml-cpp/node/convert.h b/data/miniconda3/include/yaml-cpp/node/convert.h new file mode 100644 index 0000000000000000000000000000000000000000..d0eb450f73142e70b25e40624f9bcfe1fb383b48 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/convert.h @@ -0,0 +1,469 @@ +#ifndef NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#if __cplusplus >= 201703L +#include +#endif + +#include "yaml-cpp/binary.h" +#include "yaml-cpp/node/impl.h" +#include "yaml-cpp/node/iterator.h" +#include "yaml-cpp/node/node.h" +#include "yaml-cpp/node/type.h" +#include "yaml-cpp/null.h" + + +namespace YAML { +class Binary; +struct _Null; +template +struct convert; +} // namespace YAML + +namespace YAML { +namespace conversion { +inline bool IsInfinity(const std::string& input) { + return input == ".inf" || input == ".Inf" || input == ".INF" || + input == "+.inf" || input == "+.Inf" || input == "+.INF"; +} + +inline bool IsNegativeInfinity(const std::string& input) { + return input == "-.inf" || input == "-.Inf" || input == "-.INF"; +} + +inline bool IsNaN(const std::string& input) { + return input == ".nan" || input == ".NaN" || input == ".NAN"; +} +} + +// Node +template <> +struct convert { + static Node encode(const Node& rhs) { return rhs; } + + static bool decode(const Node& node, Node& rhs) { + rhs.reset(node); + return true; + } +}; + +// std::string +template <> +struct convert { + static Node encode(const std::string& rhs) { return Node(rhs); } + + static bool decode(const Node& node, std::string& rhs) { + if (!node.IsScalar()) + return false; + rhs = node.Scalar(); + return true; + } +}; + +// C-strings can only be encoded +template <> +struct convert { + static Node encode(const char* rhs) { return Node(rhs); } +}; + +template <> +struct convert { + static Node encode(const char* rhs) { return Node(rhs); } +}; + +template +struct convert { + static Node encode(const char* rhs) { return Node(rhs); } +}; + +#if __cplusplus >= 201703L +template <> +struct convert { + static Node encode(std::string_view rhs) { return Node(std::string(rhs)); } + + static bool decode(const Node& node, std::string_view& rhs) { + if (!node.IsScalar()) + return false; + rhs = node.Scalar(); + return true; + } +}; +#endif + +template <> +struct convert<_Null> { + static Node encode(const _Null& /* rhs */) { return Node(); } + + static bool decode(const Node& node, _Null& /* rhs */) { + return node.IsNull(); + } +}; + +namespace conversion { +template +typename std::enable_if< std::is_floating_point::value, void>::type +inner_encode(const T& rhs, std::stringstream& stream){ + if (std::isnan(rhs)) { + stream << ".nan"; + } else if (std::isinf(rhs)) { + if (std::signbit(rhs)) { + stream << "-.inf"; + } else { + stream << ".inf"; + } + } else { + stream << rhs; + } +} + +template +typename std::enable_if::value, void>::type +inner_encode(const T& rhs, std::stringstream& stream){ + stream << rhs; +} + +template +typename std::enable_if<(std::is_same::value || + std::is_same::value), bool>::type +ConvertStreamTo(std::stringstream& stream, T& rhs) { + int num; + if ((stream >> std::noskipws >> num) && (stream >> std::ws).eof()) { + if (num >= (std::numeric_limits::min)() && + num <= (std::numeric_limits::max)()) { + rhs = static_cast(num); + return true; + } + } + return false; +} + +template +typename std::enable_if::value || + std::is_same::value), bool>::type +ConvertStreamTo(std::stringstream& stream, T& rhs) { + if ((stream >> std::noskipws >> rhs) && (stream >> std::ws).eof()) { + return true; + } + return false; +} +} + +#define YAML_DEFINE_CONVERT_STREAMABLE(type, negative_op) \ + template <> \ + struct convert { \ + \ + static Node encode(const type& rhs) { \ + std::stringstream stream; \ + stream.precision(std::numeric_limits::max_digits10); \ + conversion::inner_encode(rhs, stream); \ + return Node(stream.str()); \ + } \ + \ + static bool decode(const Node& node, type& rhs) { \ + if (node.Type() != NodeType::Scalar) { \ + return false; \ + } \ + const std::string& input = node.Scalar(); \ + std::stringstream stream(input); \ + stream.unsetf(std::ios::dec); \ + if ((stream.peek() == '-') && std::is_unsigned::value) { \ + return false; \ + } \ + if (conversion::ConvertStreamTo(stream, rhs)) { \ + return true; \ + } \ + if (std::numeric_limits::has_infinity) { \ + if (conversion::IsInfinity(input)) { \ + rhs = std::numeric_limits::infinity(); \ + return true; \ + } else if (conversion::IsNegativeInfinity(input)) { \ + rhs = negative_op std::numeric_limits::infinity(); \ + return true; \ + } \ + } \ + \ + if (std::numeric_limits::has_quiet_NaN) { \ + if (conversion::IsNaN(input)) { \ + rhs = std::numeric_limits::quiet_NaN(); \ + return true; \ + } \ + } \ + \ + return false; \ + } \ + } + +#define YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(type) \ + YAML_DEFINE_CONVERT_STREAMABLE(type, -) + +#define YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(type) \ + YAML_DEFINE_CONVERT_STREAMABLE(type, +) + +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(int); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(short); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long long); +YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned); +YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned short); +YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long); +YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned long long); + +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(char); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(signed char); +YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED(unsigned char); + +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(float); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(double); +YAML_DEFINE_CONVERT_STREAMABLE_SIGNED(long double); + +#undef YAML_DEFINE_CONVERT_STREAMABLE_SIGNED +#undef YAML_DEFINE_CONVERT_STREAMABLE_UNSIGNED +#undef YAML_DEFINE_CONVERT_STREAMABLE + +// bool +template <> +struct convert { + static Node encode(bool rhs) { return rhs ? Node("true") : Node("false"); } + + YAML_CPP_API static bool decode(const Node& node, bool& rhs); +}; + +// std::map +template +struct convert> { + static Node encode(const std::map& rhs) { + Node node(NodeType::Map); + for (const auto& element : rhs) + node.force_insert(element.first, element.second); + return node; + } + + static bool decode(const Node& node, std::map& rhs) { + if (!node.IsMap()) + return false; + + rhs.clear(); + for (const auto& element : node) +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs[element.first.template as()] = element.second.template as(); +#else + rhs[element.first.as()] = element.second.as(); +#endif + return true; + } +}; + +// std::unordered_map +template +struct convert> { + static Node encode(const std::unordered_map& rhs) { + Node node(NodeType::Map); + for (const auto& element : rhs) + node.force_insert(element.first, element.second); + return node; + } + + static bool decode(const Node& node, std::unordered_map& rhs) { + if (!node.IsMap()) + return false; + + rhs.clear(); + for (const auto& element : node) +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs[element.first.template as()] = element.second.template as(); +#else + rhs[element.first.as()] = element.second.as(); +#endif + return true; + } +}; + +// std::vector +template +struct convert> { + static Node encode(const std::vector& rhs) { + Node node(NodeType::Sequence); + for (const auto& element : rhs) + node.push_back(element); + return node; + } + + static bool decode(const Node& node, std::vector& rhs) { + if (!node.IsSequence()) + return false; + + rhs.clear(); + for (const auto& element : node) +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs.push_back(element.template as()); +#else + rhs.push_back(element.as()); +#endif + return true; + } +}; + +// std::list +template +struct convert> { + static Node encode(const std::list& rhs) { + Node node(NodeType::Sequence); + for (const auto& element : rhs) + node.push_back(element); + return node; + } + + static bool decode(const Node& node, std::list& rhs) { + if (!node.IsSequence()) + return false; + + rhs.clear(); + for (const auto& element : node) +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs.push_back(element.template as()); +#else + rhs.push_back(element.as()); +#endif + return true; + } +}; + +// std::array +template +struct convert> { + static Node encode(const std::array& rhs) { + Node node(NodeType::Sequence); + for (const auto& element : rhs) { + node.push_back(element); + } + return node; + } + + static bool decode(const Node& node, std::array& rhs) { + if (!isNodeValid(node)) { + return false; + } + + for (auto i = 0u; i < node.size(); ++i) { +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs[i] = node[i].template as(); +#else + rhs[i] = node[i].as(); +#endif + } + return true; + } + + private: + static bool isNodeValid(const Node& node) { + return node.IsSequence() && node.size() == N; + } +}; + + +// std::valarray +template +struct convert> { + static Node encode(const std::valarray& rhs) { + Node node(NodeType::Sequence); + for (const auto& element : rhs) { + node.push_back(element); + } + return node; + } + + static bool decode(const Node& node, std::valarray& rhs) { + if (!node.IsSequence()) { + return false; + } + + rhs.resize(node.size()); + for (auto i = 0u; i < node.size(); ++i) { +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs[i] = node[i].template as(); +#else + rhs[i] = node[i].as(); +#endif + } + return true; + } +}; + + +// std::pair +template +struct convert> { + static Node encode(const std::pair& rhs) { + Node node(NodeType::Sequence); + node.push_back(rhs.first); + node.push_back(rhs.second); + return node; + } + + static bool decode(const Node& node, std::pair& rhs) { + if (!node.IsSequence()) + return false; + if (node.size() != 2) + return false; + +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs.first = node[0].template as(); +#else + rhs.first = node[0].as(); +#endif +#if defined(__GNUC__) && __GNUC__ < 4 + // workaround for GCC 3: + rhs.second = node[1].template as(); +#else + rhs.second = node[1].as(); +#endif + return true; + } +}; + +// binary +template <> +struct convert { + static Node encode(const Binary& rhs) { + return Node(EncodeBase64(rhs.data(), rhs.size())); + } + + static bool decode(const Node& node, Binary& rhs) { + if (!node.IsScalar()) + return false; + + std::vector data = DecodeBase64(node.Scalar()); + if (data.empty() && !node.Scalar().empty()) + return false; + + rhs.swap(data); + return true; + } +}; +} + +#endif // NODE_CONVERT_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/impl.h b/data/miniconda3/include/yaml-cpp/node/detail/impl.h new file mode 100644 index 0000000000000000000000000000000000000000..b38038dfd225207d008730d673a7845dcfb16027 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/impl.h @@ -0,0 +1,235 @@ +#ifndef NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/node/detail/node.h" +#include "yaml-cpp/node/detail/node_data.h" + +#include +#include + +namespace YAML { +namespace detail { +template +struct get_idx { + static node* get(const std::vector& /* sequence */, + const Key& /* key */, shared_memory_holder /* pMemory */) { + return nullptr; + } +}; + +template +struct get_idx::value && + !std::is_same::value>::type> { + static node* get(const std::vector& sequence, const Key& key, + shared_memory_holder /* pMemory */) { + return key < sequence.size() ? sequence[key] : nullptr; + } + + static node* get(std::vector& sequence, const Key& key, + shared_memory_holder pMemory) { + if (key > sequence.size() || (key > 0 && !sequence[key - 1]->is_defined())) + return nullptr; + if (key == sequence.size()) + sequence.push_back(&pMemory->create_node()); + return sequence[key]; + } +}; + +template +struct get_idx::value>::type> { + static node* get(const std::vector& sequence, const Key& key, + shared_memory_holder pMemory) { + return key >= 0 ? get_idx::get( + sequence, static_cast(key), pMemory) + : nullptr; + } + static node* get(std::vector& sequence, const Key& key, + shared_memory_holder pMemory) { + return key >= 0 ? get_idx::get( + sequence, static_cast(key), pMemory) + : nullptr; + } +}; + +template +struct remove_idx { + static bool remove(std::vector&, const Key&, std::size_t&) { + return false; + } +}; + +template +struct remove_idx< + Key, typename std::enable_if::value && + !std::is_same::value>::type> { + + static bool remove(std::vector& sequence, const Key& key, + std::size_t& seqSize) { + if (key >= sequence.size()) { + return false; + } else { + sequence.erase(sequence.begin() + key); + if (seqSize > key) { + --seqSize; + } + return true; + } + } +}; + +template +struct remove_idx::value>::type> { + + static bool remove(std::vector& sequence, const Key& key, + std::size_t& seqSize) { + return key >= 0 ? remove_idx::remove( + sequence, static_cast(key), seqSize) + : false; + } +}; + +template +inline bool node::equals(const T& rhs, shared_memory_holder pMemory) { + T lhs; + if (convert::decode(Node(*this, pMemory), lhs)) { + return lhs == rhs; + } + return false; +} + +inline bool node::equals(const char* rhs, shared_memory_holder pMemory) { + std::string lhs; + if (convert::decode(Node(*this, std::move(pMemory)), lhs)) { + return lhs == rhs; + } + return false; +} + +// indexing +template +inline node* node_data::get(const Key& key, + shared_memory_holder pMemory) const { + switch (m_type) { + case NodeType::Map: + break; + case NodeType::Undefined: + case NodeType::Null: + return nullptr; + case NodeType::Sequence: + if (node* pNode = get_idx::get(m_sequence, key, pMemory)) + return pNode; + return nullptr; + case NodeType::Scalar: + throw BadSubscript(m_mark, key); + } + + auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); + + return it != m_map.end() ? it->second : nullptr; +} + +template +inline node& node_data::get(const Key& key, shared_memory_holder pMemory) { + switch (m_type) { + case NodeType::Map: + break; + case NodeType::Undefined: + case NodeType::Null: + case NodeType::Sequence: + if (node* pNode = get_idx::get(m_sequence, key, pMemory)) { + m_type = NodeType::Sequence; + return *pNode; + } + + convert_to_map(pMemory); + break; + case NodeType::Scalar: + throw BadSubscript(m_mark, key); + } + + auto it = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); + + if (it != m_map.end()) { + return *it->second; + } + + node& k = convert_to_node(key, pMemory); + node& v = pMemory->create_node(); + insert_map_pair(k, v); + return v; +} + +template +inline bool node_data::remove(const Key& key, shared_memory_holder pMemory) { + if (m_type == NodeType::Sequence) { + return remove_idx::remove(m_sequence, key, m_seqSize); + } + + if (m_type == NodeType::Map) { + kv_pairs::iterator it = m_undefinedPairs.begin(); + while (it != m_undefinedPairs.end()) { + kv_pairs::iterator jt = std::next(it); + if (it->first->equals(key, pMemory)) { + m_undefinedPairs.erase(it); + } + it = jt; + } + + auto iter = std::find_if(m_map.begin(), m_map.end(), [&](const kv_pair m) { + return m.first->equals(key, pMemory); + }); + + if (iter != m_map.end()) { + m_map.erase(iter); + return true; + } + } + + return false; +} + +// map +template +inline void node_data::force_insert(const Key& key, const Value& value, + shared_memory_holder pMemory) { + switch (m_type) { + case NodeType::Map: + break; + case NodeType::Undefined: + case NodeType::Null: + case NodeType::Sequence: + convert_to_map(pMemory); + break; + case NodeType::Scalar: + throw BadInsert(); + } + + node& k = convert_to_node(key, pMemory); + node& v = convert_to_node(value, pMemory); + insert_map_pair(k, v); +} + +template +inline node& node_data::convert_to_node(const T& rhs, + shared_memory_holder pMemory) { + Node value = convert::encode(rhs); + value.EnsureNodeExists(); + pMemory->merge(*value.m_pMemory); + return *value.m_pNode; +} +} +} + +#endif // NODE_DETAIL_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/iterator.h b/data/miniconda3/include/yaml-cpp/node/detail/iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..997c69a14c57080534def52a0b2bbe2e97230c53 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/iterator.h @@ -0,0 +1,96 @@ +#ifndef VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/node/detail/node_iterator.h" +#include "yaml-cpp/node/node.h" +#include "yaml-cpp/node/ptr.h" +#include +#include + + +namespace YAML { +namespace detail { +struct iterator_value; + +template +class iterator_base { + + private: + template + friend class iterator_base; + struct enabler {}; + using base_type = node_iterator; + + struct proxy { + explicit proxy(const V& x) : m_ref(x) {} + V* operator->() { return std::addressof(m_ref); } + operator V*() { return std::addressof(m_ref); } + + V m_ref; + }; + + public: + using iterator_category = std::forward_iterator_tag; + using value_type = V; + using difference_type = std::ptrdiff_t; + using pointer = V*; + using reference = V; + + public: + iterator_base() : m_iterator(), m_pMemory() {} + explicit iterator_base(base_type rhs, shared_memory_holder pMemory) + : m_iterator(rhs), m_pMemory(pMemory) {} + + template + iterator_base(const iterator_base& rhs, + typename std::enable_if::value, + enabler>::type = enabler()) + : m_iterator(rhs.m_iterator), m_pMemory(rhs.m_pMemory) {} + + iterator_base& operator++() { + ++m_iterator; + return *this; + } + + iterator_base operator++(int) { + iterator_base iterator_pre(*this); + ++(*this); + return iterator_pre; + } + + template + bool operator==(const iterator_base& rhs) const { + return m_iterator == rhs.m_iterator; + } + + template + bool operator!=(const iterator_base& rhs) const { + return m_iterator != rhs.m_iterator; + } + + value_type operator*() const { + const typename base_type::value_type& v = *m_iterator; + if (v.pNode) + return value_type(Node(*v, m_pMemory)); + if (v.first && v.second) + return value_type(Node(*v.first, m_pMemory), Node(*v.second, m_pMemory)); + return value_type(); + } + + proxy operator->() const { return proxy(**this); } + + private: + base_type m_iterator; + shared_memory_holder m_pMemory; +}; +} // namespace detail +} // namespace YAML + +#endif // VALUE_DETAIL_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/iterator_fwd.h b/data/miniconda3/include/yaml-cpp/node/detail/iterator_fwd.h new file mode 100644 index 0000000000000000000000000000000000000000..75c9de086c05727dadd237cec874120d2c9fec88 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/iterator_fwd.h @@ -0,0 +1,27 @@ +#ifndef VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/dll.h" +#include +#include +#include + +namespace YAML { + +namespace detail { +struct iterator_value; +template +class iterator_base; +} + +using iterator = detail::iterator_base; +using const_iterator = detail::iterator_base; +} + +#endif // VALUE_DETAIL_ITERATOR_FWD_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/memory.h b/data/miniconda3/include/yaml-cpp/node/detail/memory.h new file mode 100644 index 0000000000000000000000000000000000000000..e881545bf2f24094a021f2d357ebc3e3abcab55a --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/memory.h @@ -0,0 +1,47 @@ +#ifndef VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/node/ptr.h" + +namespace YAML { +namespace detail { +class node; +} // namespace detail +} // namespace YAML + +namespace YAML { +namespace detail { +class YAML_CPP_API memory { + public: + memory() : m_nodes{} {} + node& create_node(); + void merge(const memory& rhs); + + private: + using Nodes = std::set; + Nodes m_nodes; +}; + +class YAML_CPP_API memory_holder { + public: + memory_holder() : m_pMemory(new memory) {} + + node& create_node() { return m_pMemory->create_node(); } + void merge(memory_holder& rhs); + + private: + shared_memory m_pMemory; +}; +} // namespace detail +} // namespace YAML + +#endif // VALUE_DETAIL_MEMORY_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/node.h b/data/miniconda3/include/yaml-cpp/node/detail/node.h new file mode 100644 index 0000000000000000000000000000000000000000..acf60ffb6dff588dcc4f47675ec97ef8cc9d9a5e --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/node.h @@ -0,0 +1,177 @@ +#ifndef NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/emitterstyle.h" +#include "yaml-cpp/node/detail/node_ref.h" +#include "yaml-cpp/node/ptr.h" +#include "yaml-cpp/node/type.h" +#include +#include + +namespace YAML { +namespace detail { +class node { + private: + struct less { + bool operator ()(const node* l, const node* r) const {return l->m_index < r->m_index;} + }; + + public: + node() : m_pRef(new node_ref), m_dependencies{}, m_index{} {} + node(const node&) = delete; + node& operator=(const node&) = delete; + + bool is(const node& rhs) const { return m_pRef == rhs.m_pRef; } + const node_ref* ref() const { return m_pRef.get(); } + + bool is_defined() const { return m_pRef->is_defined(); } + const Mark& mark() const { return m_pRef->mark(); } + NodeType::value type() const { return m_pRef->type(); } + + const std::string& scalar() const { return m_pRef->scalar(); } + const std::string& tag() const { return m_pRef->tag(); } + EmitterStyle::value style() const { return m_pRef->style(); } + + template + bool equals(const T& rhs, shared_memory_holder pMemory); + bool equals(const char* rhs, shared_memory_holder pMemory); + + void mark_defined() { + if (is_defined()) + return; + + m_pRef->mark_defined(); + for (node* dependency : m_dependencies) + dependency->mark_defined(); + m_dependencies.clear(); + } + + void add_dependency(node& rhs) { + if (is_defined()) + rhs.mark_defined(); + else + m_dependencies.insert(&rhs); + } + + void set_ref(const node& rhs) { + if (rhs.is_defined()) + mark_defined(); + m_pRef = rhs.m_pRef; + } + void set_data(const node& rhs) { + if (rhs.is_defined()) + mark_defined(); + m_pRef->set_data(*rhs.m_pRef); + } + + void set_mark(const Mark& mark) { m_pRef->set_mark(mark); } + + void set_type(NodeType::value type) { + if (type != NodeType::Undefined) + mark_defined(); + m_pRef->set_type(type); + } + void set_null() { + mark_defined(); + m_pRef->set_null(); + } + void set_scalar(const std::string& scalar) { + mark_defined(); + m_pRef->set_scalar(scalar); + } + void set_tag(const std::string& tag) { + mark_defined(); + m_pRef->set_tag(tag); + } + + // style + void set_style(EmitterStyle::value style) { + mark_defined(); + m_pRef->set_style(style); + } + + // size/iterator + std::size_t size() const { return m_pRef->size(); } + + const_node_iterator begin() const { + return static_cast(*m_pRef).begin(); + } + node_iterator begin() { return m_pRef->begin(); } + + const_node_iterator end() const { + return static_cast(*m_pRef).end(); + } + node_iterator end() { return m_pRef->end(); } + + // sequence + void push_back(node& input, shared_memory_holder pMemory) { + m_pRef->push_back(input, pMemory); + input.add_dependency(*this); + m_index = m_amount.fetch_add(1); + } + void insert(node& key, node& value, shared_memory_holder pMemory) { + m_pRef->insert(key, value, pMemory); + key.add_dependency(*this); + value.add_dependency(*this); + } + + // indexing + template + node* get(const Key& key, shared_memory_holder pMemory) const { + // NOTE: this returns a non-const node so that the top-level Node can wrap + // it, and returns a pointer so that it can be nullptr (if there is no such + // key). + return static_cast(*m_pRef).get(key, pMemory); + } + template + node& get(const Key& key, shared_memory_holder pMemory) { + node& value = m_pRef->get(key, pMemory); + value.add_dependency(*this); + return value; + } + template + bool remove(const Key& key, shared_memory_holder pMemory) { + return m_pRef->remove(key, pMemory); + } + + node* get(node& key, shared_memory_holder pMemory) const { + // NOTE: this returns a non-const node so that the top-level Node can wrap + // it, and returns a pointer so that it can be nullptr (if there is no such + // key). + return static_cast(*m_pRef).get(key, pMemory); + } + node& get(node& key, shared_memory_holder pMemory) { + node& value = m_pRef->get(key, pMemory); + key.add_dependency(*this); + value.add_dependency(*this); + return value; + } + bool remove(node& key, shared_memory_holder pMemory) { + return m_pRef->remove(key, pMemory); + } + + // map + template + void force_insert(const Key& key, const Value& value, + shared_memory_holder pMemory) { + m_pRef->force_insert(key, value, pMemory); + } + + private: + shared_node_ref m_pRef; + using nodes = std::set; + nodes m_dependencies; + size_t m_index; + static YAML_CPP_API std::atomic m_amount; +}; +} // namespace detail +} // namespace YAML + +#endif // NODE_DETAIL_NODE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/node_data.h b/data/miniconda3/include/yaml-cpp/node/detail/node_data.h new file mode 100644 index 0000000000000000000000000000000000000000..07cf81aa099217822bfefff5558889a899c3cf86 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/node_data.h @@ -0,0 +1,127 @@ +#ifndef VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include +#include +#include +#include +#include + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/node/detail/node_iterator.h" +#include "yaml-cpp/node/iterator.h" +#include "yaml-cpp/node/ptr.h" +#include "yaml-cpp/node/type.h" + +namespace YAML { +namespace detail { +class node; +} // namespace detail +} // namespace YAML + +namespace YAML { +namespace detail { +class YAML_CPP_API node_data { + public: + node_data(); + node_data(const node_data&) = delete; + node_data& operator=(const node_data&) = delete; + + void mark_defined(); + void set_mark(const Mark& mark); + void set_type(NodeType::value type); + void set_tag(const std::string& tag); + void set_null(); + void set_scalar(const std::string& scalar); + void set_style(EmitterStyle::value style); + + bool is_defined() const { return m_isDefined; } + const Mark& mark() const { return m_mark; } + NodeType::value type() const { + return m_isDefined ? m_type : NodeType::Undefined; + } + const std::string& scalar() const { return m_scalar; } + const std::string& tag() const { return m_tag; } + EmitterStyle::value style() const { return m_style; } + + // size/iterator + std::size_t size() const; + + const_node_iterator begin() const; + node_iterator begin(); + + const_node_iterator end() const; + node_iterator end(); + + // sequence + void push_back(node& node, const shared_memory_holder& pMemory); + void insert(node& key, node& value, const shared_memory_holder& pMemory); + + // indexing + template + node* get(const Key& key, shared_memory_holder pMemory) const; + template + node& get(const Key& key, shared_memory_holder pMemory); + template + bool remove(const Key& key, shared_memory_holder pMemory); + + node* get(node& key, const shared_memory_holder& pMemory) const; + node& get(node& key, const shared_memory_holder& pMemory); + bool remove(node& key, const shared_memory_holder& pMemory); + + // map + template + void force_insert(const Key& key, const Value& value, + shared_memory_holder pMemory); + + public: + static const std::string& empty_scalar(); + + private: + void compute_seq_size() const; + void compute_map_size() const; + + void reset_sequence(); + void reset_map(); + + void insert_map_pair(node& key, node& value); + void convert_to_map(const shared_memory_holder& pMemory); + void convert_sequence_to_map(const shared_memory_holder& pMemory); + + template + static node& convert_to_node(const T& rhs, shared_memory_holder pMemory); + + private: + bool m_isDefined; + Mark m_mark; + NodeType::value m_type; + std::string m_tag; + EmitterStyle::value m_style; + + // scalar + std::string m_scalar; + + // sequence + using node_seq = std::vector; + node_seq m_sequence; + + mutable std::size_t m_seqSize; + + // map + using node_map = std::vector>; + node_map m_map; + + using kv_pair = std::pair; + using kv_pairs = std::list; + mutable kv_pairs m_undefinedPairs; +}; +} +} + +#endif // VALUE_DETAIL_NODE_DATA_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/node_iterator.h b/data/miniconda3/include/yaml-cpp/node/detail/node_iterator.h new file mode 100644 index 0000000000000000000000000000000000000000..49dcf958dbbddf90358bbd52128e80d78915f057 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/node_iterator.h @@ -0,0 +1,181 @@ +#ifndef VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/node/ptr.h" +#include +#include +#include +#include +#include +#include + +namespace YAML { +namespace detail { +struct iterator_type { + enum value { NoneType, Sequence, Map }; +}; + +template +struct node_iterator_value : public std::pair { + using kv = std::pair; + + node_iterator_value() : kv(), pNode(nullptr) {} + explicit node_iterator_value(V& rhs) : kv(), pNode(&rhs) {} + explicit node_iterator_value(V& key, V& value) : kv(&key, &value), pNode(nullptr) {} + + V& operator*() const { return *pNode; } + V& operator->() const { return *pNode; } + + V* pNode; +}; + +using node_seq = std::vector; +using node_map = std::vector>; + +template +struct node_iterator_type { + using seq = node_seq::iterator; + using map = node_map::iterator; +}; + +template +struct node_iterator_type { + using seq = node_seq::const_iterator; + using map = node_map::const_iterator; +}; + +template +class node_iterator_base { + private: + struct enabler {}; + + struct proxy { + explicit proxy(const node_iterator_value& x) : m_ref(x) {} + node_iterator_value* operator->() { return std::addressof(m_ref); } + operator node_iterator_value*() { return std::addressof(m_ref); } + + node_iterator_value m_ref; + }; + + public: + using iterator_category = std::forward_iterator_tag; + using value_type = node_iterator_value; + using difference_type = std::ptrdiff_t; + using pointer = node_iterator_value*; + using reference = node_iterator_value; + using SeqIter = typename node_iterator_type::seq; + using MapIter = typename node_iterator_type::map; + + node_iterator_base() + : m_type(iterator_type::NoneType), m_seqIt(), m_mapIt(), m_mapEnd() {} + explicit node_iterator_base(SeqIter seqIt) + : m_type(iterator_type::Sequence), + m_seqIt(seqIt), + m_mapIt(), + m_mapEnd() {} + explicit node_iterator_base(MapIter mapIt, MapIter mapEnd) + : m_type(iterator_type::Map), + m_seqIt(), + m_mapIt(mapIt), + m_mapEnd(mapEnd) { + m_mapIt = increment_until_defined(m_mapIt); + } + + template + node_iterator_base(const node_iterator_base& rhs, + typename std::enable_if::value, + enabler>::type = enabler()) + : m_type(rhs.m_type), + m_seqIt(rhs.m_seqIt), + m_mapIt(rhs.m_mapIt), + m_mapEnd(rhs.m_mapEnd) {} + + template + friend class node_iterator_base; + + template + bool operator==(const node_iterator_base& rhs) const { + if (m_type != rhs.m_type) + return false; + + switch (m_type) { + case iterator_type::NoneType: + return true; + case iterator_type::Sequence: + return m_seqIt == rhs.m_seqIt; + case iterator_type::Map: + return m_mapIt == rhs.m_mapIt; + } + return true; + } + + template + bool operator!=(const node_iterator_base& rhs) const { + return !(*this == rhs); + } + + node_iterator_base& operator++() { + switch (m_type) { + case iterator_type::NoneType: + break; + case iterator_type::Sequence: + ++m_seqIt; + break; + case iterator_type::Map: + ++m_mapIt; + m_mapIt = increment_until_defined(m_mapIt); + break; + } + return *this; + } + + node_iterator_base operator++(int) { + node_iterator_base iterator_pre(*this); + ++(*this); + return iterator_pre; + } + + value_type operator*() const { + switch (m_type) { + case iterator_type::NoneType: + return value_type(); + case iterator_type::Sequence: + return value_type(**m_seqIt); + case iterator_type::Map: + return value_type(*m_mapIt->first, *m_mapIt->second); + } + return value_type(); + } + + proxy operator->() const { return proxy(**this); } + + MapIter increment_until_defined(MapIter it) { + while (it != m_mapEnd && !is_defined(it)) + ++it; + return it; + } + + bool is_defined(MapIter it) const { + return it->first->is_defined() && it->second->is_defined(); + } + + private: + typename iterator_type::value m_type; + + SeqIter m_seqIt; + MapIter m_mapIt, m_mapEnd; +}; + +using node_iterator = node_iterator_base; +using const_node_iterator = node_iterator_base; +} +} + +#endif // VALUE_DETAIL_NODE_ITERATOR_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/detail/node_ref.h b/data/miniconda3/include/yaml-cpp/node/detail/node_ref.h new file mode 100644 index 0000000000000000000000000000000000000000..d8a94f8b8045cf106f5db24e7254f02fada9df2b --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/detail/node_ref.h @@ -0,0 +1,98 @@ +#ifndef VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/dll.h" +#include "yaml-cpp/node/type.h" +#include "yaml-cpp/node/ptr.h" +#include "yaml-cpp/node/detail/node_data.h" + +namespace YAML { +namespace detail { +class node_ref { + public: + node_ref() : m_pData(new node_data) {} + node_ref(const node_ref&) = delete; + node_ref& operator=(const node_ref&) = delete; + + bool is_defined() const { return m_pData->is_defined(); } + const Mark& mark() const { return m_pData->mark(); } + NodeType::value type() const { return m_pData->type(); } + const std::string& scalar() const { return m_pData->scalar(); } + const std::string& tag() const { return m_pData->tag(); } + EmitterStyle::value style() const { return m_pData->style(); } + + void mark_defined() { m_pData->mark_defined(); } + void set_data(const node_ref& rhs) { m_pData = rhs.m_pData; } + + void set_mark(const Mark& mark) { m_pData->set_mark(mark); } + void set_type(NodeType::value type) { m_pData->set_type(type); } + void set_tag(const std::string& tag) { m_pData->set_tag(tag); } + void set_null() { m_pData->set_null(); } + void set_scalar(const std::string& scalar) { m_pData->set_scalar(scalar); } + void set_style(EmitterStyle::value style) { m_pData->set_style(style); } + + // size/iterator + std::size_t size() const { return m_pData->size(); } + + const_node_iterator begin() const { + return static_cast(*m_pData).begin(); + } + node_iterator begin() { return m_pData->begin(); } + + const_node_iterator end() const { + return static_cast(*m_pData).end(); + } + node_iterator end() { return m_pData->end(); } + + // sequence + void push_back(node& node, shared_memory_holder pMemory) { + m_pData->push_back(node, pMemory); + } + void insert(node& key, node& value, shared_memory_holder pMemory) { + m_pData->insert(key, value, pMemory); + } + + // indexing + template + node* get(const Key& key, shared_memory_holder pMemory) const { + return static_cast(*m_pData).get(key, pMemory); + } + template + node& get(const Key& key, shared_memory_holder pMemory) { + return m_pData->get(key, pMemory); + } + template + bool remove(const Key& key, shared_memory_holder pMemory) { + return m_pData->remove(key, pMemory); + } + + node* get(node& key, shared_memory_holder pMemory) const { + return static_cast(*m_pData).get(key, pMemory); + } + node& get(node& key, shared_memory_holder pMemory) { + return m_pData->get(key, pMemory); + } + bool remove(node& key, shared_memory_holder pMemory) { + return m_pData->remove(key, pMemory); + } + + // map + template + void force_insert(const Key& key, const Value& value, + shared_memory_holder pMemory) { + m_pData->force_insert(key, value, pMemory); + } + + private: + shared_node_data m_pData; +}; +} +} + +#endif // VALUE_DETAIL_NODE_REF_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/impl.h b/data/miniconda3/include/yaml-cpp/node/impl.h new file mode 100644 index 0000000000000000000000000000000000000000..312281f18cc355714f706e305d96c3e94eb659cb --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/impl.h @@ -0,0 +1,385 @@ +#ifndef NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include "yaml-cpp/exceptions.h" +#include "yaml-cpp/node/detail/memory.h" +#include "yaml-cpp/node/detail/node.h" +#include "yaml-cpp/node/iterator.h" +#include "yaml-cpp/node/node.h" +#include +#include + +namespace YAML { +inline Node::Node() + : m_isValid(true), m_invalidKey{}, m_pMemory(nullptr), m_pNode(nullptr) {} + +inline Node::Node(NodeType::value type) + : m_isValid(true), + m_invalidKey{}, + m_pMemory(new detail::memory_holder), + m_pNode(&m_pMemory->create_node()) { + m_pNode->set_type(type); +} + +template +inline Node::Node(const T& rhs) + : m_isValid(true), + m_invalidKey{}, + m_pMemory(new detail::memory_holder), + m_pNode(&m_pMemory->create_node()) { + Assign(rhs); +} + +inline Node::Node(const detail::iterator_value& rhs) + : m_isValid(rhs.m_isValid), + m_invalidKey(rhs.m_invalidKey), + m_pMemory(rhs.m_pMemory), + m_pNode(rhs.m_pNode) {} + +inline Node::Node(const Node&) = default; + +inline Node::Node(Zombie) + : m_isValid(false), m_invalidKey{}, m_pMemory{}, m_pNode(nullptr) {} + +inline Node::Node(Zombie, const std::string& key) + : m_isValid(false), m_invalidKey(key), m_pMemory{}, m_pNode(nullptr) {} + +inline Node::Node(detail::node& node, detail::shared_memory_holder pMemory) + : m_isValid(true), m_invalidKey{}, m_pMemory(pMemory), m_pNode(&node) {} + +inline Node::~Node() = default; + +inline void Node::EnsureNodeExists() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + if (!m_pNode) { + m_pMemory.reset(new detail::memory_holder); + m_pNode = &m_pMemory->create_node(); + m_pNode->set_null(); + } +} + +inline bool Node::IsDefined() const { + if (!m_isValid) { + return false; + } + return m_pNode ? m_pNode->is_defined() : true; +} + +inline Mark Node::Mark() const { + if (!m_isValid) { + throw InvalidNode(m_invalidKey); + } + return m_pNode ? m_pNode->mark() : Mark::null_mark(); +} + +inline NodeType::value Node::Type() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->type() : NodeType::Null; +} + +// access + +// template helpers +template +struct as_if { + explicit as_if(const Node& node_) : node(node_) {} + const Node& node; + + T operator()(const S& fallback) const { + if (!node.m_pNode) + return fallback; + + T t; + if (convert::decode(node, t)) + return t; + return fallback; + } +}; + +template +struct as_if { + explicit as_if(const Node& node_) : node(node_) {} + const Node& node; + + std::string operator()(const S& fallback) const { + if (node.Type() == NodeType::Null) + return "null"; + if (node.Type() != NodeType::Scalar) + return fallback; + return node.Scalar(); + } +}; + +template +struct as_if { + explicit as_if(const Node& node_) : node(node_) {} + const Node& node; + + T operator()() const { + if (!node.m_pNode) + throw TypedBadConversion(node.Mark()); + + T t; + if (convert::decode(node, t)) + return t; + throw TypedBadConversion(node.Mark()); + } +}; + +template <> +struct as_if { + explicit as_if(const Node& node_) : node(node_) {} + const Node& node; + + std::string operator()() const { + if (node.Type() == NodeType::Null) + return "null"; + if (node.Type() != NodeType::Scalar) + throw TypedBadConversion(node.Mark()); + return node.Scalar(); + } +}; + +// access functions +template +inline T Node::as() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return as_if(*this)(); +} + +template +inline T Node::as(const S& fallback) const { + if (!m_isValid) + return fallback; + return as_if(*this)(fallback); +} + +inline const std::string& Node::Scalar() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->scalar() : detail::node_data::empty_scalar(); +} + +inline const std::string& Node::Tag() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->tag() : detail::node_data::empty_scalar(); +} + +inline void Node::SetTag(const std::string& tag) { + EnsureNodeExists(); + m_pNode->set_tag(tag); +} + +inline EmitterStyle::value Node::Style() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->style() : EmitterStyle::Default; +} + +inline void Node::SetStyle(EmitterStyle::value style) { + EnsureNodeExists(); + m_pNode->set_style(style); +} + +// assignment +inline bool Node::is(const Node& rhs) const { + if (!m_isValid || !rhs.m_isValid) + throw InvalidNode(m_invalidKey); + if (!m_pNode || !rhs.m_pNode) + return false; + return m_pNode->is(*rhs.m_pNode); +} + +template +inline Node& Node::operator=(const T& rhs) { + Assign(rhs); + return *this; +} + +inline Node& Node::operator=(const Node& rhs) { + if (is(rhs)) + return *this; + AssignNode(rhs); + return *this; +} + +inline void Node::reset(const YAML::Node& rhs) { + if (!m_isValid || !rhs.m_isValid) + throw InvalidNode(m_invalidKey); + m_pMemory = rhs.m_pMemory; + m_pNode = rhs.m_pNode; +} + +template +inline void Node::Assign(const T& rhs) { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + AssignData(convert::encode(rhs)); +} + +template <> +inline void Node::Assign(const std::string& rhs) { + EnsureNodeExists(); + m_pNode->set_scalar(rhs); +} + +inline void Node::Assign(const char* rhs) { + EnsureNodeExists(); + m_pNode->set_scalar(rhs); +} + +inline void Node::Assign(char* rhs) { + EnsureNodeExists(); + m_pNode->set_scalar(rhs); +} + +inline void Node::AssignData(const Node& rhs) { + EnsureNodeExists(); + rhs.EnsureNodeExists(); + + m_pNode->set_data(*rhs.m_pNode); + m_pMemory->merge(*rhs.m_pMemory); +} + +inline void Node::AssignNode(const Node& rhs) { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + rhs.EnsureNodeExists(); + + if (!m_pNode) { + m_pNode = rhs.m_pNode; + m_pMemory = rhs.m_pMemory; + return; + } + + m_pNode->set_ref(*rhs.m_pNode); + m_pMemory->merge(*rhs.m_pMemory); + m_pNode = rhs.m_pNode; +} + +// size/iterator +inline std::size_t Node::size() const { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + return m_pNode ? m_pNode->size() : 0; +} + +inline const_iterator Node::begin() const { + if (!m_isValid) + return const_iterator(); + return m_pNode ? const_iterator(m_pNode->begin(), m_pMemory) + : const_iterator(); +} + +inline iterator Node::begin() { + if (!m_isValid) + return iterator(); + return m_pNode ? iterator(m_pNode->begin(), m_pMemory) : iterator(); +} + +inline const_iterator Node::end() const { + if (!m_isValid) + return const_iterator(); + return m_pNode ? const_iterator(m_pNode->end(), m_pMemory) : const_iterator(); +} + +inline iterator Node::end() { + if (!m_isValid) + return iterator(); + return m_pNode ? iterator(m_pNode->end(), m_pMemory) : iterator(); +} + +// sequence +template +inline void Node::push_back(const T& rhs) { + if (!m_isValid) + throw InvalidNode(m_invalidKey); + push_back(Node(rhs)); +} + +inline void Node::push_back(const Node& rhs) { + EnsureNodeExists(); + rhs.EnsureNodeExists(); + + m_pNode->push_back(*rhs.m_pNode, m_pMemory); + m_pMemory->merge(*rhs.m_pMemory); +} + +template +std::string key_to_string(const Key& key) { + return streamable_to_string::value>().impl(key); +} + +// indexing +template +inline const Node Node::operator[](const Key& key) const { + EnsureNodeExists(); + detail::node* value = + static_cast(*m_pNode).get(key, m_pMemory); + if (!value) { + return Node(ZombieNode, key_to_string(key)); + } + return Node(*value, m_pMemory); +} + +template +inline Node Node::operator[](const Key& key) { + EnsureNodeExists(); + detail::node& value = m_pNode->get(key, m_pMemory); + return Node(value, m_pMemory); +} + +template +inline bool Node::remove(const Key& key) { + EnsureNodeExists(); + return m_pNode->remove(key, m_pMemory); +} + +inline const Node Node::operator[](const Node& key) const { + EnsureNodeExists(); + key.EnsureNodeExists(); + m_pMemory->merge(*key.m_pMemory); + detail::node* value = + static_cast(*m_pNode).get(*key.m_pNode, m_pMemory); + if (!value) { + return Node(ZombieNode, key_to_string(key)); + } + return Node(*value, m_pMemory); +} + +inline Node Node::operator[](const Node& key) { + EnsureNodeExists(); + key.EnsureNodeExists(); + m_pMemory->merge(*key.m_pMemory); + detail::node& value = m_pNode->get(*key.m_pNode, m_pMemory); + return Node(value, m_pMemory); +} + +inline bool Node::remove(const Node& key) { + EnsureNodeExists(); + key.EnsureNodeExists(); + return m_pNode->remove(*key.m_pNode, m_pMemory); +} + +// map +template +inline void Node::force_insert(const Key& key, const Value& value) { + EnsureNodeExists(); + m_pNode->force_insert(key, value, m_pMemory); +} + +// free functions +inline bool operator==(const Node& lhs, const Node& rhs) { return lhs.is(rhs); } +} // namespace YAML + +#endif // NODE_IMPL_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/parse.h b/data/miniconda3/include/yaml-cpp/node/parse.h new file mode 100644 index 0000000000000000000000000000000000000000..7745fd7245bec055711877d13b5ea34d87395b20 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/parse.h @@ -0,0 +1,78 @@ +#ifndef VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +#include +#include +#include + +#include "yaml-cpp/dll.h" + +namespace YAML { +class Node; + +/** + * Loads the input string as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API Node Load(const std::string& input); + +/** + * Loads the input string as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API Node Load(const char* input); + +/** + * Loads the input stream as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API Node Load(std::istream& input); + +/** + * Loads the input file as a single YAML document. + * + * @throws {@link ParserException} if it is malformed. + * @throws {@link BadFile} if the file cannot be loaded. + */ +YAML_CPP_API Node LoadFile(const std::string& filename); + +/** + * Loads the input string as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API std::vector LoadAll(const std::string& input); + +/** + * Loads the input string as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API std::vector LoadAll(const char* input); + +/** + * Loads the input stream as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + */ +YAML_CPP_API std::vector LoadAll(std::istream& input); + +/** + * Loads the input file as a list of YAML documents. + * + * @throws {@link ParserException} if it is malformed. + * @throws {@link BadFile} if the file cannot be loaded. + */ +YAML_CPP_API std::vector LoadAllFromFile(const std::string& filename); +} // namespace YAML + +#endif // VALUE_PARSE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 diff --git a/data/miniconda3/include/yaml-cpp/node/type.h b/data/miniconda3/include/yaml-cpp/node/type.h new file mode 100644 index 0000000000000000000000000000000000000000..9d55ca96621619b8a47e204e0823080e52a41eb2 --- /dev/null +++ b/data/miniconda3/include/yaml-cpp/node/type.h @@ -0,0 +1,16 @@ +#ifndef VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 +#define VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66 + +#if defined(_MSC_VER) || \ + (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \ + (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4 +#pragma once +#endif + +namespace YAML { +struct NodeType { + enum value { Undefined, Null, Scalar, Sequence, Map }; +}; +} + +#endif // VALUE_TYPE_H_62B23520_7C8E_11DE_8A39_0800200C9A66