/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* map_utils.h :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: mcolonna +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/03 15:05:13 by mc #+# #+# */ /* Updated: 2024/10/17 17:58:23 by mcolonna ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef MAP_UTILS_H # define MAP_UTILS_H # include "stream.h" # include "map.h" # include # include /// @brief Read a parameter of the map which has a color as an argument. /// Color format: [0-255],[0-255],[0-255] /// @param name Name of the parameter. /// @param dest Will be set to the value of the parameter. /// Unchanged if error. /// If success but *dest is not 0xFF000000, throws an error. /// @param stream Stream to use. /// Unchanged if error. /// @param redefined Set to true if the parameter was already defined. /// @return true if success or redefined, false if non-fatal error. bool read_color_parameter(const char *name, t_color *dest, t_stream *stream, bool *redefined); /// @brief Read a parameter of the map which has a string as an argument. /// @param name Name of the parameter. /// @param dest Will be set to an alloc'd pointer to the value of the parameter. /// Unchanged if error. /// If success but *dest is not null, throws an error. /// @param stream Stream to use. /// Unchanged if error. /// @param redefined Set to true if the parameter was already defined. /// @return true if success or redefined, false if non-fatal error. bool read_string_parameter(const char *name, const char **dest, t_stream *stream, bool *redefined); /// @brief Read a map-formatted string. /// If an error occurs, write an error message on stderr. /// @param dest Will be set to the map. /// @param stream Stream to use. /// @return true if success, false if error. bool read_map(t_map *dest, t_stream *stream); /// @brief Get the case associated with the char. /// /// @param dest Will be set to the char. /// @param name Name of the case. /// @return true if success, false if error. bool get_case(t_map_case *dest, char name); /// @brief Fill the pointer with 'size' null bytes. /// /// @param dest The pointer to set. /// @param size The number of bytes. void fill_zeros(void *dest, size_t size); /// @brief Read the map description part of the map. /// Read until the end of the file. /// /// @param map The .width, .height and .cases members will be set. /// @param stream Stream to use. /// @return true if success, false if error. bool read_map_description(t_map *map, t_stream *stream); /// @brief Initialize all objects of the map. /// @param map Map to use. void map_init_objects(t_map *map); #endif