include/SDL_rwops.h
author Sam Lantinga <slouken@libsdl.org>
Wed, 09 Dec 2009 15:56:56 +0000
changeset 3536 0267b8b1595c
parent 3407 d3baf5ac4e37
child 3564 d264d99576c1
permissions -rw-r--r--
Added interfaces for batch drawing of points, lines and rects:
SDL_DrawPoints()
SDL_BlendPoints()
SDL_BlendLines()
SDL_DrawLines()
SDL_FillRects()
SDL_BlendRects()
SDL_RenderPoints()
SDL_RenderLines()
SDL_RenderRects()
Renamed SDL_RenderFill() to SDL_RenderRect()
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@2859
     3
    Copyright (C) 1997-2009 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@0
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@1895
    23
/**
slouken@3407
    24
 *  \file SDL_rwops.h
slouken@3407
    25
 *  
slouken@3407
    26
 *  This file provides a general interface for SDL to read and write
slouken@3407
    27
 *  data sources.  It can easily be extended to files, memory, etc.
slouken@1895
    28
 */
slouken@0
    29
slouken@1402
    30
#ifndef _SDL_rwops_h
slouken@1402
    31
#define _SDL_rwops_h
slouken@0
    32
slouken@1354
    33
#include "SDL_stdinc.h"
slouken@1358
    34
#include "SDL_error.h"
slouken@1330
    35
slouken@0
    36
#include "begin_code.h"
slouken@0
    37
/* Set up for C function definitions, even when using C++ */
slouken@0
    38
#ifdef __cplusplus
slouken@1895
    39
/* *INDENT-OFF* */
slouken@0
    40
extern "C" {
slouken@1895
    41
/* *INDENT-ON* */
slouken@0
    42
#endif
slouken@0
    43
slouken@3407
    44
/**
slouken@3407
    45
 * This is the read/write operation structure -- very basic.
slouken@3407
    46
 */
slouken@1895
    47
typedef struct SDL_RWops
slouken@1895
    48
{
slouken@3407
    49
    /**
slouken@3407
    50
     *  Seek to \c offset relative to \c whence, one of stdio's whence values:
slouken@3407
    51
     *  RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
slouken@3407
    52
     *  
slouken@3407
    53
     *  \return the final offset in the data source.
slouken@1895
    54
     */
slouken@2160
    55
    long (SDLCALL * seek) (struct SDL_RWops * context, long offset,
slouken@2160
    56
                           int whence);
slouken@0
    57
slouken@3407
    58
    /**
slouken@3407
    59
     *  Read up to \c num objects each of size \c objsize from the data
slouken@3407
    60
     *  source to the area pointed at by \c ptr.
slouken@3407
    61
     *  
slouken@3407
    62
     *  \return the number of objects read, or 0 at error or end of file.
slouken@1895
    63
     */
slouken@3407
    64
    size_t(SDLCALL * read) (struct SDL_RWops * context, void *ptr,
slouken@3407
    65
                            size_t size, size_t maxnum);
slouken@0
    66
slouken@3407
    67
    /**
slouken@3407
    68
     *  Write exactly \c num objects each of size \c objsize from the area
slouken@3407
    69
     *  pointed at by \c ptr to data source.
slouken@3407
    70
     *  
slouken@3407
    71
     *  \return the number of objects written, or 0 at error or end of file.
slouken@1895
    72
     */
slouken@3407
    73
    size_t(SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
slouken@3407
    74
                             size_t size, size_t num);
slouken@0
    75
slouken@3407
    76
    /**
slouken@3407
    77
     *  Close and free an allocated SDL_RWops structure.
slouken@3407
    78
     *  
slouken@3407
    79
     *  \return 0 if successful or -1 on write error when flushing data.
slouken@2160
    80
     */
slouken@1895
    81
    int (SDLCALL * close) (struct SDL_RWops * context);
slouken@0
    82
slouken@1895
    83
    Uint32 type;
slouken@1895
    84
    union
slouken@1895
    85
    {
slouken@1447
    86
#ifdef __WIN32__
slouken@1895
    87
        struct
slouken@1895
    88
        {
slouken@2160
    89
            SDL_bool append;
slouken@1895
    90
            void *h;
slouken@2159
    91
            struct
slouken@2159
    92
            {
slouken@2159
    93
                void *data;
slouken@3253
    94
                size_t size;
slouken@3253
    95
                size_t left;
slouken@2159
    96
            } buffer;
slouken@1895
    97
        } win32io;
slouken@1447
    98
#endif
slouken@1895
    99
#ifdef HAVE_STDIO_H
slouken@1895
   100
        struct
slouken@1895
   101
        {
slouken@2160
   102
            SDL_bool autoclose;
slouken@1895
   103
            FILE *fp;
slouken@1895
   104
        } stdio;
slouken@1330
   105
#endif
slouken@1895
   106
        struct
slouken@1895
   107
        {
slouken@1895
   108
            Uint8 *base;
slouken@1895
   109
            Uint8 *here;
slouken@1895
   110
            Uint8 *stop;
slouken@1895
   111
        } mem;
slouken@1895
   112
        struct
slouken@1895
   113
        {
slouken@1895
   114
            void *data1;
slouken@1895
   115
        } unknown;
slouken@1895
   116
    } hidden;
slouken@0
   117
slouken@0
   118
} SDL_RWops;
slouken@0
   119
slouken@0
   120
slouken@3407
   121
/**
slouken@3407
   122
 *  \name RWFrom functions
slouken@3407
   123
 *  
slouken@3407
   124
 *  Functions to create SDL_RWops structures from various data sources.
slouken@3407
   125
 */
slouken@3407
   126
/*@{*/
slouken@0
   127
slouken@1895
   128
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
slouken@1895
   129
                                                  const char *mode);
slouken@0
   130
slouken@1330
   131
#ifdef HAVE_STDIO_H
slouken@2161
   132
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
slouken@2161
   133
                                                SDL_bool autoclose);
slouken@1330
   134
#endif
slouken@0
   135
slouken@1895
   136
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
slouken@1895
   137
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
slouken@1895
   138
                                                      int size);
slouken@0
   139
slouken@3407
   140
/*@}*//*RWFrom functions*/
slouken@3407
   141
slouken@3407
   142
slouken@1895
   143
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
slouken@1895
   144
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
slouken@0
   145
slouken@3407
   146
#define RW_SEEK_SET	0       /**< Seek from the beginning of data */
slouken@3407
   147
#define RW_SEEK_CUR	1       /**< Seek relative to current read point */
slouken@3407
   148
#define RW_SEEK_END	2       /**< Seek relative to the end of data */
slouken@1330
   149
slouken@3407
   150
/**
slouken@3407
   151
 *  \name Read/write macros
slouken@3407
   152
 *  
slouken@3407
   153
 *  Macros to easily read and write from an SDL_RWops structure.
slouken@3407
   154
 */
slouken@3407
   155
/*@{*/
slouken@0
   156
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
slouken@1330
   157
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, RW_SEEK_CUR)
slouken@0
   158
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
slouken@0
   159
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
slouken@0
   160
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
slouken@3407
   161
/*@}*//*Read/write macros*/
slouken@0
   162
slouken@0
   163
slouken@3407
   164
/** 
slouken@3407
   165
 *  \name Read endian functions
slouken@3407
   166
 *  
slouken@3407
   167
 *  Read an item of the specified endianness and return in native format.
slouken@3407
   168
 */
slouken@3407
   169
/*@{*/
slouken@1895
   170
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
slouken@1895
   171
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
slouken@1895
   172
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
slouken@1895
   173
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
slouken@1895
   174
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
slouken@1895
   175
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
slouken@3407
   176
/*@}*//*Read endian functions*/
slouken@1354
   177
slouken@3407
   178
/** 
slouken@3407
   179
 *  \name Write endian functions
slouken@3407
   180
 *  
slouken@3407
   181
 *  Write an item of native format to the specified endianness.
slouken@3407
   182
 */
slouken@3407
   183
/*@{*/
slouken@3253
   184
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   185
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   186
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   187
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   188
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
slouken@3253
   189
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
slouken@3407
   190
/*@}*//*Write endian functions*/
slouken@1354
   191
slouken@1354
   192
slouken@0
   193
/* Ends C function definitions when using C++ */
slouken@0
   194
#ifdef __cplusplus
slouken@1895
   195
/* *INDENT-OFF* */
slouken@0
   196
}
slouken@1895
   197
/* *INDENT-ON* */
slouken@0
   198
#endif
slouken@0
   199
#include "close_code.h"
slouken@0
   200
slouken@1402
   201
#endif /* _SDL_rwops_h */
slouken@1895
   202
slouken@1895
   203
/* vi: set ts=4 sw=4 expandtab: */