1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
|
/*
* file_io.h -- part of FractalNow
*
* Copyright (c) 2012 Marc Pegon <pe.marc@free.fr>
*
* This program 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 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
/**
* \file file_io.h
* \brief Header file related to file IO.
* \author Marc Pegon
*/
#ifndef __FILE_IO_H__
#define __FILE_IO_H__
#include "color.h"
#include "float_precision.h"
#include <stdint.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* \fn int readString(FILE *file, char *dst)
* \brief Read string from file.
*
* \param file File from which to read string.
* \param dst Destination string.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readString(FILE *file, char *dst);
/**
* \fn int readUint32(FILE *file, uint32_t *dst)
* \brief Read uint32 from file.
*
* \param file File from which to read uint32.
* \param dst Destination uint32.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readUint32(FILE *file, uint32_t *dst);
/**
* \fn int readDouble(FILE *file, double *dst)
* \brief Read double from file.
*
* \param file File from which to read long double.
* \param dst Destination double.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readDouble(FILE *file, double *dst);
/**
* \fn int readBiggestFloat(FILE *file, BiggestFloat *dst)
* \brief Read BiggestFloat from file.
*
* \param file File from which to read float.
* \param dst Destination.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readBiggestFloat(FILE *file, BiggestFloat *dst);
/**
* \fn int readColor(FILE *file, int_fast8_t bytesPerComponent, Color *dst)
* \brief Read color from file as a hexadecimal number.
*
* Exit program with error if bytesPerComponent is not 1 or 2.
*
* \param file File from which to read color.
* \param bytesPerComponent Bytes per component for color to read (either 1 for RGB8 or 2 for RGB16).
* \param dst Destination color.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readColor(FILE *file, int_fast8_t bytesPerComponent, Color *dst);
/**
* \fn int writeString(FILE *file, const char *src, const char *suffix)
* \brief Write string into file.
*
* \param file File to write into.
* \param src Source string.
* \param suffix Suffix to add after source string.
* \return Number of characters written, negative in case of error (like fprintf).
*/
int writeString(FILE *file, const char *src, const char *suffix);
/**
* \fn int writeUint32(FILE *file, uint32_t src, const char *suffix)
* \brief Write uint32 into file.
*
* \param file File to write into.
* \param src Source uint32.
* \param suffix Suffix to add after uint32.
* \return Number of characters written, negative in case of error (like fprintf).
*/
int writeUint32(FILE *file, uint32_t src, const char *suffix);
/**
* \fn int writeDouble(FILE *file, double src, const char *suffix)
* \brief Write double into file.
*
* \param file File to write into.
* \param src Source double.
* \param suffix Suffix to add after double.
* \return Number of characters written, negative in case of error (like fprintf).
*/
int writeDouble(FILE *file, const double src, const char *suffix);
/**
* \fn int writeBiggestFloat(FILE *file, const BiggestFloat src, const char *suffix)
* \brief Write BiggestFloat into file.
*
* \param file File to write into.
* \param src Source float.
* \param suffix Suffix to add after float.
* \return Number of characters written, negative in case of error (like fprintf).
*/
int writeBiggestFloat(FILE *file, const BiggestFloat src, const char *suffix);
/**
* \fn int writeBiggestFloat(FILE *file, cBiggestFloat *dst)
* \brief Read BiggestFloat from file.
*
* \param file File from which to read float.
* \param dst Destination.
* \return Number of elements successfully read or EOF (like fscanf).
*/
int readBiggestFloat(FILE *file, BiggestFloat *dst);
/**
* \fn int writeColor(FILE *file, Color src, const char *suffix)
* \brief Write color into file as a hexadecimal number.
*
* Exit program with error if color bytesPerComponent is not 1 or 2.
* \param file File to write into.
* \param src Source color.
* \param suffix Suffix to add after source color.
* \return Number of characters written, negative in case of error (like fprintf).
*/
int writeColor(FILE *file, Color src, const char *suffix);
#ifdef __cplusplus
}
#endif
#endif
|