/*
 * This file defines the atc_results C struct, as well as the supporting atc_timing C struct.
 * Naturally, atc_results's destructor, atc_destroy_results, is also declared here.
 */

#pragma once

#include <stddef.h>
#include <math.h>

/// Represents a single timing tuple.
typedef struct atc_timing {
	const char* name; /// The name of the section that was timed.
	double timing; /// The duration of the section that was timed (in seconds).
} atc_timing;

struct atc_results_impl;
typedef struct atc_results_impl atc_results_impl;

/// C equivalent of `atc::Results`. Although its fields should not be modified, even if they are this should normally not lead to memory errors.
typedef struct atc_results {
	bool success; ///< Normally ``true``, set to ``false`` in case this struct is the result of a failed ATC function call (an exception was thrown). If ``false``, the other values in this struct are meaningless.
	size_t compressed_size;
	const char* compressed_data; ///< If not NULL, represents an array of length ``compressed_size``.
	double compression_factor;
	size_t decompressed_sizes_length;
	const size_t* decompressed_sizes; ///< If not NULL, represents an array of length ``decompressed_sizes_length``.
	double error;
	size_t timings_length;
	const atc_timing* timings; ///< Instead of an ``std::map<std::string, double>``, timings in the C API are stored as an array of `atc_timing` structs of length ``timings_length``.
	atc_results_impl* impl; ///< An opaque pointer to the private implementation, should not be used by the user. **Modifying this field almost certainly leads to crashes and/or memory corruption upon calling** `atc_destroy_results` <b>.</b> 
} atc_results;


#ifdef __cplusplus
extern "C" {
#endif
	
	/// Destroys all resources associated with this `atc_results` struct. **Must be explicitly called by the user for each** `atc_results` **struct received from ATC to avoid memory leaks. The struct should never be used anymore after destruction.**
	void atc_destroy_results(atc_results* results);
	
#ifdef __cplusplus
}
#endif
