visualtest/include/SDL_visualtest_rwhelper.h
changeset 7924 fcb86d323770
child 11382 2c50e79b19e0
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/visualtest/include/SDL_visualtest_rwhelper.h	Sun Nov 10 00:32:23 2013 -0500
     1.3 @@ -0,0 +1,85 @@
     1.4 +/* See COPYING.txt for the full license governing this code. */
     1.5 +/**
     1.6 + * \file rwhelper.c
     1.7 + *
     1.8 + * Header file with some helper functions for working with SDL_RWops.
     1.9 + */
    1.10 +
    1.11 +#include <SDL_rwops.h>
    1.12 +
    1.13 +#ifndef _SDL_visualtest_rwhelper_h
    1.14 +#define _SDL_visualtest_rwhelper_h
    1.15 +
    1.16 +/** Length of the buffer in SDLVisualTest_RWHelperBuffer */
    1.17 +#define RWOPS_BUFFER_LEN 256
    1.18 +
    1.19 +/* Set up for C function definitions, even when using C++ */
    1.20 +#ifdef __cplusplus
    1.21 +extern "C" {
    1.22 +#endif
    1.23 +
    1.24 +/**
    1.25 + * Struct that is used as a buffer by the RW helper functions. Should be initialized by calling
    1.26 + * SDLVisualTest_RWHelperResetBuffer() before being used.
    1.27 + */
    1.28 +typedef struct SDLVisualTest_RWHelperBuffer
    1.29 +{
    1.30 +    /*! Character buffer that data is read into */
    1.31 +    char buffer[RWOPS_BUFFER_LEN];
    1.32 +    /*! buffer[buffer_pos] is the next character to be read from the buffer */
    1.33 +    int buffer_pos;
    1.34 +    /*! Number of character read into the buffer */
    1.35 +    int buffer_width;
    1.36 +} SDLVisualTest_RWHelperBuffer;
    1.37 +
    1.38 +/**
    1.39 + * Resets the buffer pointed to by \c buffer used by some of the helper functions.
    1.40 + * This function should be called when you're using one of the helper functions 
    1.41 + * with a new SDL_RWops object.
    1.42 + */
    1.43 +void SDLVisualTest_RWHelperResetBuffer(SDLVisualTest_RWHelperBuffer* buffer);
    1.44 +
    1.45 +/**
    1.46 + * Reads a single character using the SDL_RWops object pointed to by \c rw.
    1.47 + * This function reads data in blocks and stores them in the buffer pointed to by
    1.48 + * \c buffer, so other SDL_RWops functions should not be used in conjunction 
    1.49 + * with this function.
    1.50 + *
    1.51 + * \return The character that was read.
    1.52 + */
    1.53 +char SDLVisualTest_RWHelperReadChar(SDL_RWops* rw,
    1.54 +                                    SDLVisualTest_RWHelperBuffer* buffer);
    1.55 +
    1.56 +/**
    1.57 + * Reads characters using the SDL_RWops object pointed to by \c rw into the
    1.58 + * character array pointed to by \c str (of size \c size) until either the 
    1.59 + * array is full or a new line is encountered. If \c comment_char is encountered,
    1.60 + * all characters from that position till the end of the line are ignored. The new line
    1.61 + * is not included as part of the buffer. Lines with only whitespace and comments
    1.62 + * are ignored. This function reads data in blocks and stores them in the buffer
    1.63 + * pointed to by \c buffer, so other SDL_RWops functions should not be used in
    1.64 + * conjunction with this function.
    1.65 + * 
    1.66 + * \return pointer to the string on success, NULL on failure or EOF.
    1.67 + */
    1.68 +char* SDLVisualTest_RWHelperReadLine(SDL_RWops* rw, char* str, int size,
    1.69 +                                     SDLVisualTest_RWHelperBuffer* buffer,
    1.70 +                                     char comment_char);
    1.71 +
    1.72 +/**
    1.73 + * Counts the number of lines that are not all whitespace and comments using the
    1.74 + * SDL_RWops object pointed to by \c rw. \c comment_char indicates the character
    1.75 + * used for comments. Uses the buffer pointed to by \c buffer to read data in blocks.
    1.76 + *
    1.77 + * \return Number of lines on success, -1 on failure.
    1.78 + */
    1.79 +int SDLVisualTest_RWHelperCountNonEmptyLines(SDL_RWops* rw,
    1.80 +                                             SDLVisualTest_RWHelperBuffer* buffer,
    1.81 +                                             char comment_char);
    1.82 +
    1.83 +/* Ends C function definitions when using C++ */
    1.84 +#ifdef __cplusplus
    1.85 +}
    1.86 +#endif
    1.87 +
    1.88 +#endif /* _SDL_visualtest_rwhelper_h */
    1.89 \ No newline at end of file