home *** CD-ROM | disk | FTP | other *** search
/ ring.yamanashi.ac.jp/pub/pc/freem/action/ / action.zip / a7xpg0_11.zip / a7xpg / import / SDL_rwops.d < prev    next >
Text File  |  2003-09-20  |  3KB  |  119 lines

  1. /*
  2.     SDL - Simple DirectMedia Layer
  3.     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
  4.  
  5.     This library is free software; you can redistribute it and/or
  6.     modify it under the terms of the GNU Library General Public
  7.     License as published by the Free Software Foundation; either
  8.     version 2 of the License, or (at your option) any later version.
  9.  
  10.     This library is distributed in the hope that it will be useful,
  11.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.     Library General Public License for more details.
  14.  
  15.     You should have received a copy of the GNU Library General Public
  16.     License along with this library; if not, write to the Free
  17.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  18.  
  19.     Sam Lantinga
  20.     slouken@devolution.com
  21. */
  22.  
  23. /* This file provides a general interface for SDL to read and write
  24.    data sources.  It can easily be extended to files, memory, etc.
  25. */
  26.  
  27. import SDL_types;
  28.  
  29. extern(C):
  30.  
  31. /* This is the read/write operation structure -- very basic */
  32.  
  33. struct SDL_RWops {
  34.     /* Seek to 'offset' relative to whence, one of stdio's whence values:
  35.         SEEK_SET, SEEK_CUR, SEEK_END
  36.        Returns the final offset in the data source.
  37.      */
  38.     int (*seek)(SDL_RWops *context, int offset, int whence);
  39.  
  40.     /* Read up to 'num' objects each of size 'objsize' from the data
  41.        source to the area pointed at by 'ptr'.
  42.        Returns the number of objects read, or -1 if the read failed.
  43.      */
  44.     int (*read)(SDL_RWops *context, void *ptr, int size, int maxnum);
  45.  
  46.     /* Write exactly 'num' objects each of size 'objsize' from the area
  47.        pointed at by 'ptr' to data source.
  48.        Returns 'num', or -1 if the write failed.
  49.      */
  50.     int (*write)(SDL_RWops *context, void *ptr, int size, int num);
  51.  
  52.     /* Close and free an allocated SDL_FSops structure */
  53.     int (*close)(SDL_RWops *context);
  54.  
  55.     Uint32 type;
  56.     union {
  57.         struct {
  58.             int autoclose;
  59.              void *fp;    // was FILE
  60.         } // stdio;
  61.         struct {
  62.             Uint8 *base;
  63.              Uint8 *here;
  64.             Uint8 *stop;
  65.         } // mem;
  66.         struct {
  67.             void *data1;
  68.         } // unknown;
  69.     } // hidden;
  70. }
  71.  
  72.  
  73. /* Functions to create SDL_RWops structures from various data sources */
  74.  
  75. SDL_RWops * SDL_RWFromFile(char *file, char *mode);
  76.  
  77. SDL_RWops * SDL_RWFromFP(void *fp, int autoclose);
  78.  
  79. SDL_RWops * SDL_RWFromMem(void *mem, int size);
  80.  
  81. SDL_RWops * SDL_AllocRW();
  82. void SDL_FreeRW(SDL_RWops *area);
  83.  
  84. /* Macros to easily read and write from an SDL_RWops structure */
  85. int SDL_RWseek(SDL_RWops *ctx, int offset, int whence)
  86. {
  87.     int (*seek)(SDL_RWops *context, int offset, int whence);
  88.     seek = ctx.seek;
  89.     return (*seek)(ctx, offset, whence);
  90. }
  91.  
  92. int SDL_RWtell(SDL_RWops *ctx)
  93. {
  94.     int (*seek)(SDL_RWops *context, int offset, int whence);
  95.     seek = ctx.seek;
  96.     return (*seek)(ctx, 0, 1);
  97. }
  98.  
  99. int SDL_RWread(SDL_RWops *ctx, void* ptr, int size, int n)
  100. {
  101.     int (*read)(SDL_RWops *context, void *ptr, int size, int maxnum);
  102.     read = ctx.read;
  103.     return (*read)(ctx, ptr, size, n);
  104. }
  105.  
  106. int SDL_RWwrite(SDL_RWops *ctx, void* ptr, int size, int n)
  107. {
  108.     int (*write)(SDL_RWops *context, void *ptr, int size, int num);
  109.     write = ctx.write;
  110.     return (*write)(ctx, ptr, size, n);
  111. }
  112.  
  113. int SDL_RWclose(SDL_RWops *ctx)
  114. {
  115.     int (*close)(SDL_RWops *context);
  116.     close = ctx.close;
  117.     return (*close)(ctx);
  118. }
  119.