include/SDL_rwops.h
author Gabriel Jacobo <gabomdq@gmail.com>
Fri, 16 Nov 2012 09:23:18 -0300
changeset 6674 45a21e50ba5e
parent 6655 6a3e741ea70d
child 6806 9e57ff36fd7a
permissions -rw-r--r--
Adds CMake build system by Marcus Von Appen (bug #1597)
slouken@0
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6138
     3
  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
slouken@0
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@0
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@0
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@0
    20
*/
slouken@0
    21
slouken@1895
    22
/**
slouken@3407
    23
 *  \file SDL_rwops.h
slouken@3407
    24
 *  
slouken@3407
    25
 *  This file provides a general interface for SDL to read and write
slouken@4971
    26
 *  data streams.  It can easily be extended to files, memory, etc.
slouken@1895
    27
 */
slouken@0
    28
slouken@1402
    29
#ifndef _SDL_rwops_h
slouken@1402
    30
#define _SDL_rwops_h
slouken@0
    31
slouken@1354
    32
#include "SDL_stdinc.h"
slouken@1358
    33
#include "SDL_error.h"
slouken@1330
    34
slouken@0
    35
#include "begin_code.h"
slouken@0
    36
/* Set up for C function definitions, even when using C++ */
slouken@0
    37
#ifdef __cplusplus
slouken@1895
    38
/* *INDENT-OFF* */
slouken@0
    39
extern "C" {
slouken@1895
    40
/* *INDENT-ON* */
slouken@0
    41
#endif
slouken@0
    42
slouken@3407
    43
/**
slouken@3407
    44
 * This is the read/write operation structure -- very basic.
slouken@3407
    45
 */
slouken@1895
    46
typedef struct SDL_RWops
slouken@1895
    47
{
slouken@3407
    48
    /**
slouken@6642
    49
     *  Return the size of the file in this rwops, or -1 if unknown
slouken@6642
    50
     */
slouken@6642
    51
    Sint64 (SDLCALL * size) (struct SDL_RWops * context);
slouken@6642
    52
slouken@6642
    53
    /**
slouken@3407
    54
     *  Seek to \c offset relative to \c whence, one of stdio's whence values:
slouken@3407
    55
     *  RW_SEEK_SET, RW_SEEK_CUR, RW_SEEK_END
slouken@3407
    56
     *  
slouken@4971
    57
     *  \return the final offset in the data stream.
slouken@1895
    58
     */
slouken@6642
    59
    Sint64 (SDLCALL * seek) (struct SDL_RWops * context, Sint64 offset,
slouken@6642
    60
                             int whence);
slouken@0
    61
slouken@3407
    62
    /**
icculus@3614
    63
     *  Read up to \c maxnum objects each of size \c size from the data
slouken@4971
    64
     *  stream to the area pointed at by \c ptr.
slouken@3407
    65
     *  
slouken@3407
    66
     *  \return the number of objects read, or 0 at error or end of file.
slouken@1895
    67
     */
slouken@6642
    68
    size_t (SDLCALL * read) (struct SDL_RWops * context, void *ptr,
slouken@6642
    69
                             size_t size, size_t maxnum);
slouken@0
    70
slouken@3407
    71
    /**
slouken@4864
    72
     *  Write exactly \c num objects each of size \c size from the area
slouken@4971
    73
     *  pointed at by \c ptr to data stream.
slouken@3407
    74
     *  
slouken@3407
    75
     *  \return the number of objects written, or 0 at error or end of file.
slouken@1895
    76
     */
slouken@6642
    77
    size_t (SDLCALL * write) (struct SDL_RWops * context, const void *ptr,
slouken@6642
    78
                              size_t size, size_t num);
slouken@0
    79
slouken@3407
    80
    /**
slouken@3407
    81
     *  Close and free an allocated SDL_RWops structure.
slouken@3407
    82
     *  
slouken@3407
    83
     *  \return 0 if successful or -1 on write error when flushing data.
slouken@2160
    84
     */
slouken@1895
    85
    int (SDLCALL * close) (struct SDL_RWops * context);
slouken@0
    86
slouken@1895
    87
    Uint32 type;
slouken@1895
    88
    union
slouken@1895
    89
    {
icculus@5582
    90
#if defined(ANDROID)
icculus@5582
    91
        struct
icculus@5582
    92
        {
icculus@5582
    93
            void *fileNameRef;
icculus@5582
    94
            void *inputStreamRef;
icculus@5582
    95
            void *readableByteChannelRef;
icculus@5582
    96
            void *readMethod;
icculus@5582
    97
            long position;
icculus@5582
    98
            int size;
icculus@5582
    99
        } androidio;
icculus@5582
   100
#elif defined(__WIN32__)
slouken@1895
   101
        struct
slouken@1895
   102
        {
slouken@2160
   103
            SDL_bool append;
slouken@1895
   104
            void *h;
slouken@2159
   105
            struct
slouken@2159
   106
            {
slouken@2159
   107
                void *data;
slouken@3253
   108
                size_t size;
slouken@3253
   109
                size_t left;
slouken@2159
   110
            } buffer;
slouken@5062
   111
        } windowsio;
slouken@1447
   112
#endif
icculus@5582
   113
slouken@1895
   114
#ifdef HAVE_STDIO_H
slouken@1895
   115
        struct
slouken@1895
   116
        {
slouken@2160
   117
            SDL_bool autoclose;
slouken@1895
   118
            FILE *fp;
slouken@1895
   119
        } stdio;
slouken@1330
   120
#endif
slouken@1895
   121
        struct
slouken@1895
   122
        {
slouken@1895
   123
            Uint8 *base;
slouken@1895
   124
            Uint8 *here;
slouken@1895
   125
            Uint8 *stop;
slouken@1895
   126
        } mem;
slouken@1895
   127
        struct
slouken@1895
   128
        {
slouken@1895
   129
            void *data1;
slouken@1895
   130
        } unknown;
slouken@1895
   131
    } hidden;
slouken@0
   132
slouken@0
   133
} SDL_RWops;
slouken@0
   134
slouken@0
   135
slouken@3407
   136
/**
slouken@3407
   137
 *  \name RWFrom functions
slouken@3407
   138
 *  
slouken@4971
   139
 *  Functions to create SDL_RWops structures from various data streams.
slouken@3407
   140
 */
slouken@3407
   141
/*@{*/
slouken@0
   142
slouken@1895
   143
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFile(const char *file,
slouken@1895
   144
                                                  const char *mode);
slouken@0
   145
slouken@1330
   146
#ifdef HAVE_STDIO_H
slouken@2161
   147
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(FILE * fp,
slouken@2161
   148
                                                SDL_bool autoclose);
slouken@3564
   149
#else
slouken@3564
   150
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromFP(void * fp,
slouken@3564
   151
                                                SDL_bool autoclose);
slouken@1330
   152
#endif
slouken@0
   153
slouken@1895
   154
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromMem(void *mem, int size);
slouken@1895
   155
extern DECLSPEC SDL_RWops *SDLCALL SDL_RWFromConstMem(const void *mem,
slouken@1895
   156
                                                      int size);
slouken@0
   157
slouken@3407
   158
/*@}*//*RWFrom functions*/
slouken@3407
   159
slouken@3407
   160
slouken@1895
   161
extern DECLSPEC SDL_RWops *SDLCALL SDL_AllocRW(void);
slouken@1895
   162
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops * area);
slouken@0
   163
slouken@3407
   164
#define RW_SEEK_SET	0       /**< Seek from the beginning of data */
slouken@3407
   165
#define RW_SEEK_CUR	1       /**< Seek relative to current read point */
slouken@3407
   166
#define RW_SEEK_END	2       /**< Seek relative to the end of data */
slouken@1330
   167
slouken@3407
   168
/**
slouken@3407
   169
 *  \name Read/write macros
slouken@3407
   170
 *  
slouken@3407
   171
 *  Macros to easily read and write from an SDL_RWops structure.
slouken@3407
   172
 */
slouken@3407
   173
/*@{*/
slouken@6642
   174
#define SDL_RWsize(ctx)	        (ctx)->size(ctx)
slouken@0
   175
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
slouken@1330
   176
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, RW_SEEK_CUR)
slouken@0
   177
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
slouken@0
   178
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
slouken@0
   179
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
slouken@3407
   180
/*@}*//*Read/write macros*/
slouken@0
   181
slouken@0
   182
slouken@3407
   183
/** 
slouken@3407
   184
 *  \name Read endian functions
slouken@3407
   185
 *  
slouken@3407
   186
 *  Read an item of the specified endianness and return in native format.
slouken@3407
   187
 */
slouken@3407
   188
/*@{*/
slouken@6655
   189
extern DECLSPEC Uint8 SDLCALL SDL_ReadU8(SDL_RWops * src);
slouken@1895
   190
extern DECLSPEC Uint16 SDLCALL SDL_ReadLE16(SDL_RWops * src);
slouken@1895
   191
extern DECLSPEC Uint16 SDLCALL SDL_ReadBE16(SDL_RWops * src);
slouken@1895
   192
extern DECLSPEC Uint32 SDLCALL SDL_ReadLE32(SDL_RWops * src);
slouken@1895
   193
extern DECLSPEC Uint32 SDLCALL SDL_ReadBE32(SDL_RWops * src);
slouken@1895
   194
extern DECLSPEC Uint64 SDLCALL SDL_ReadLE64(SDL_RWops * src);
slouken@1895
   195
extern DECLSPEC Uint64 SDLCALL SDL_ReadBE64(SDL_RWops * src);
slouken@3407
   196
/*@}*//*Read endian functions*/
slouken@1354
   197
slouken@3407
   198
/** 
slouken@3407
   199
 *  \name Write endian functions
slouken@3407
   200
 *  
slouken@3407
   201
 *  Write an item of native format to the specified endianness.
slouken@3407
   202
 */
slouken@3407
   203
/*@{*/
slouken@6655
   204
extern DECLSPEC size_t SDLCALL SDL_WriteU8(SDL_RWops * dst, Uint8 value);
slouken@3253
   205
extern DECLSPEC size_t SDLCALL SDL_WriteLE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   206
extern DECLSPEC size_t SDLCALL SDL_WriteBE16(SDL_RWops * dst, Uint16 value);
slouken@3253
   207
extern DECLSPEC size_t SDLCALL SDL_WriteLE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   208
extern DECLSPEC size_t SDLCALL SDL_WriteBE32(SDL_RWops * dst, Uint32 value);
slouken@3253
   209
extern DECLSPEC size_t SDLCALL SDL_WriteLE64(SDL_RWops * dst, Uint64 value);
slouken@3253
   210
extern DECLSPEC size_t SDLCALL SDL_WriteBE64(SDL_RWops * dst, Uint64 value);
slouken@3407
   211
/*@}*//*Write endian functions*/
slouken@1354
   212
slouken@1354
   213
slouken@0
   214
/* Ends C function definitions when using C++ */
slouken@0
   215
#ifdef __cplusplus
slouken@1895
   216
/* *INDENT-OFF* */
slouken@0
   217
}
slouken@1895
   218
/* *INDENT-ON* */
slouken@0
   219
#endif
slouken@0
   220
#include "close_code.h"
slouken@0
   221
slouken@1402
   222
#endif /* _SDL_rwops_h */
slouken@1895
   223
slouken@1895
   224
/* vi: set ts=4 sw=4 expandtab: */