include/SDL_rwops.h
author Ryan C. Gordon <icculus@icculus.org>
Thu, 19 Jan 2006 08:43:00 +0000
changeset 1251 86d0d01290ea
parent 930 02759105b989
child 1312 c9b51268668f
permissions -rw-r--r--
Updated Windows CE/PocketPC support...adds GAPI driver, landscape mode,
updated project files, VS2005 support, VGA mode, more device support, etc,
etc, etc.

Fixes Bugzilla #47 and #28.

--ryan.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 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@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@251
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* This file provides a general interface for SDL to read and write
slouken@0
    29
   data sources.  It can easily be extended to files, memory, etc.
slouken@0
    30
*/
slouken@0
    31
slouken@0
    32
#ifndef _SDL_RWops_h
slouken@0
    33
#define _SDL_RWops_h
slouken@0
    34
slouken@0
    35
#include <stdio.h>
slouken@0
    36
slouken@0
    37
#include "SDL_types.h"
slouken@0
    38
slouken@0
    39
#include "begin_code.h"
slouken@0
    40
/* Set up for C function definitions, even when using C++ */
slouken@0
    41
#ifdef __cplusplus
slouken@0
    42
extern "C" {
slouken@0
    43
#endif
slouken@0
    44
slouken@0
    45
/* This is the read/write operation structure -- very basic */
slouken@0
    46
slouken@0
    47
typedef struct SDL_RWops {
slouken@0
    48
	/* Seek to 'offset' relative to whence, one of stdio's whence values:
slouken@0
    49
		SEEK_SET, SEEK_CUR, SEEK_END
slouken@0
    50
	   Returns the final offset in the data source.
slouken@0
    51
	 */
slouken@930
    52
	int (SDLCALL *seek)(struct SDL_RWops *context, int offset, int whence);
slouken@0
    53
slouken@0
    54
	/* Read up to 'num' objects each of size 'objsize' from the data
slouken@0
    55
	   source to the area pointed at by 'ptr'.
slouken@0
    56
	   Returns the number of objects read, or -1 if the read failed.
slouken@0
    57
	 */
slouken@930
    58
	int (SDLCALL *read)(struct SDL_RWops *context, void *ptr, int size, int maxnum);
slouken@0
    59
slouken@0
    60
	/* Write exactly 'num' objects each of size 'objsize' from the area
slouken@0
    61
	   pointed at by 'ptr' to data source.
slouken@0
    62
	   Returns 'num', or -1 if the write failed.
slouken@0
    63
	 */
slouken@930
    64
	int (SDLCALL *write)(struct SDL_RWops *context, const void *ptr, int size, int num);
slouken@0
    65
slouken@0
    66
	/* Close and free an allocated SDL_FSops structure */
slouken@930
    67
	int (SDLCALL *close)(struct SDL_RWops *context);
slouken@0
    68
slouken@0
    69
	Uint32 type;
slouken@0
    70
	union {
slouken@0
    71
	    struct {
slouken@0
    72
		int autoclose;
slouken@0
    73
	 	FILE *fp;
slouken@0
    74
	    } stdio;
slouken@0
    75
	    struct {
slouken@0
    76
		Uint8 *base;
slouken@0
    77
	 	Uint8 *here;
slouken@0
    78
		Uint8 *stop;
slouken@0
    79
	    } mem;
slouken@0
    80
	    struct {
slouken@0
    81
		void *data1;
slouken@0
    82
	    } unknown;
slouken@0
    83
	} hidden;
slouken@0
    84
slouken@0
    85
} SDL_RWops;
slouken@0
    86
slouken@0
    87
slouken@0
    88
/* Functions to create SDL_RWops structures from various data sources */
slouken@0
    89
slouken@337
    90
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFile(const char *file, const char *mode);
slouken@0
    91
slouken@337
    92
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromFP(FILE *fp, int autoclose);
slouken@0
    93
slouken@337
    94
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromMem(void *mem, int size);
slouken@764
    95
extern DECLSPEC SDL_RWops * SDLCALL SDL_RWFromConstMem(const void *mem, int size);
slouken@0
    96
slouken@337
    97
extern DECLSPEC SDL_RWops * SDLCALL SDL_AllocRW(void);
slouken@337
    98
extern DECLSPEC void SDLCALL SDL_FreeRW(SDL_RWops *area);
slouken@0
    99
slouken@0
   100
/* Macros to easily read and write from an SDL_RWops structure */
slouken@0
   101
#define SDL_RWseek(ctx, offset, whence)	(ctx)->seek(ctx, offset, whence)
slouken@0
   102
#define SDL_RWtell(ctx)			(ctx)->seek(ctx, 0, SEEK_CUR)
slouken@0
   103
#define SDL_RWread(ctx, ptr, size, n)	(ctx)->read(ctx, ptr, size, n)
slouken@0
   104
#define SDL_RWwrite(ctx, ptr, size, n)	(ctx)->write(ctx, ptr, size, n)
slouken@0
   105
#define SDL_RWclose(ctx)		(ctx)->close(ctx)
slouken@0
   106
slouken@0
   107
slouken@0
   108
/* Ends C function definitions when using C++ */
slouken@0
   109
#ifdef __cplusplus
slouken@0
   110
}
slouken@0
   111
#endif
slouken@0
   112
#include "close_code.h"
slouken@0
   113
slouken@0
   114
#endif /* _SDL_RWops_h */