📄 endianrw_8h-source.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>MiniGUI V1.6.10 API Reference: endianrw.h Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.2 --><div class="qindex"><a class="qindex" href="index.htm">Main Page</a> | <a class="qindex" href="modules.htm">Modules</a> | <a class="qindex" href="classes.htm">Alphabetical List</a> | <a class="qindex" href="annotated.htm">Data Structures</a> | <a class="qindex" href="dirs.htm">Directories</a> | <a class="qindex" href="files.htm">File List</a> | <a class="qindex" href="functions.htm">Data Fields</a> | <a class="qindex" href="globals.htm">Globals</a> | <a class="qindex" href="pages.htm">Related Pages</a></div><div class="nav"><a class="el" href="dir_000003.htm">include</a></div><h1>endianrw.h</h1><a href="endianrw_8h.htm">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 00024 <span class="comment">/*</span>00025 <span class="comment"> * $Id: endianrw.h 7364 2007-08-16 05:20:20Z xgwang $</span>00026 <span class="comment"> * </span>00027 <span class="comment"> * MiniGUI for Linux/uClinux, eCos, uC/OS-II, VxWorks, </span>00028 <span class="comment"> * pSOS, ThreadX, NuCleus, OSE, and Win32.</span>00029 <span class="comment"> *</span>00030 <span class="comment"> * Copyright (C) 2002-2007 Feynman Software.</span>00031 <span class="comment"> * Copyright (C) 1998-2002 Wei Yongming.</span>00032 <span class="comment"> *</span>00033 <span class="comment"> * The idea comes from LGPL'ed SDL by Sam Lantinga.</span>00034 <span class="comment"> */</span>00035 00036 <span class="preprocessor">#ifndef _MGUI_ENDIAN_RW_H</span>00037 <span class="preprocessor"></span><span class="preprocessor">#define _MGUI_ENDIAN_RW_H</span>00038 <span class="preprocessor"></span>00039 <span class="comment">/* Set up for C function definitions, even when using C++ */</span>00040 <span class="preprocessor">#ifdef __cplusplus</span>00041 <span class="preprocessor"></span><span class="keyword">extern</span> <span class="stringliteral">"C"</span> {00042 <span class="preprocessor">#endif</span>00043 <span class="preprocessor"></span>00044 <span class="comment">/************************** General RW operations ****************************/</span>00045 00066 <span class="preprocessor">#define RWAREA_TYPE_UNKNOWN 0</span>00067 <span class="preprocessor"></span><span class="preprocessor">#define RWAREA_TYPE_STDIO 1</span>00068 <span class="preprocessor"></span><span class="preprocessor">#define RWAREA_TYPE_MEM 2</span>00069 <span class="preprocessor"></span><a name="l00073"></a><a class="code" href="struct__MG__RWops.htm">00073</a> <span class="keyword">typedef</span> <span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> {00079 int (*<a class="code" href="struct__MG__RWops.htm#o0">seek</a>)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context, <span class="keywordtype">int</span> offset, <span class="keywordtype">int</span> whence);00080 00086 int (*<a class="code" href="struct__MG__RWops.htm#o1">read</a>)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context, <span class="keywordtype">void</span> *ptr, <span class="keywordtype">int</span> objsize, <span class="keywordtype">int</span> num);00087 00093 int (*<a class="code" href="struct__MG__RWops.htm#o2">write</a>)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context, <span class="keyword">const</span> <span class="keywordtype">void</span> *ptr, <span class="keywordtype">int</span> objsize, 00094 <span class="keywordtype">int</span> num);00095 00096 <span class="preprocessor">#ifdef _USE_OWN_STDIO</span>00097 <span class="preprocessor"></span> <span class="comment">/* */</span>00098 int (*ungetc)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);00099 <span class="preprocessor">#endif</span>00100 <span class="preprocessor"></span>00104 int (*<a class="code" href="struct__MG__RWops.htm#o3">close</a>)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context);00105 00109 int (*<a class="code" href="struct__MG__RWops.htm#o4">eof</a>)(<span class="keyword">struct </span><a class="code" href="struct__MG__RWops.htm">_MG_RWops</a> *context);00110 <a name="l00121"></a><a class="code" href="struct__MG__RWops.htm#o5">00121</a> <a class="code" href="group__basic__types.htm#ga4">Uint32</a> <a class="code" href="struct__MG__RWops.htm#o5">type</a>;00122 00123 <span class="keyword">union </span>{00124 <span class="keyword">struct </span>{00125 <span class="keywordtype">int</span> autoclose;00126 FILE *fp;00127 } stdio;00128 <span class="keyword">struct </span>{00129 <a class="code" href="group__basic__types.htm#ga0">Uint8</a> *base;00130 <a class="code" href="group__basic__types.htm#ga0">Uint8</a> *here;00131 <a class="code" href="group__basic__types.htm#ga0">Uint8</a> *stop;00132 } mem;00133 <span class="keyword">struct </span>{00134 <span class="keywordtype">void</span> *data1;00135 } unknown;00136 } hidden;00137 } <a class="code" href="struct__MG__RWops.htm">MG_RWops</a>;00138 00153 MG_EXPORT <a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* <a class="code" href="group__general__rw__fns.htm#ga1">MGUI_RWFromFile</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *file, <span class="keyword">const</span> <span class="keywordtype">char</span> *mode);00154 00169 MG_EXPORT <a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* <a class="code" href="group__general__rw__fns.htm#ga2">MGUI_RWFromFP</a>(FILE *fp, <span class="keywordtype">int</span> autoclose);00170 00185 MG_EXPORT <a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* <a class="code" href="group__general__rw__fns.htm#ga3">MGUI_RWFromMem</a>(<span class="keywordtype">void</span> *mem, <span class="keywordtype">int</span> size);00186 00202 MG_EXPORT <span class="keywordtype">void</span> <a class="code" href="group__general__rw__fns.htm#ga4">MGUI_InitMemRW</a> (<a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* area, <span class="keywordtype">void</span> *mem, <span class="keywordtype">int</span> size);00203 00215 MG_EXPORT <a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* <a class="code" href="group__general__rw__fns.htm#ga5">MGUI_AllocRW</a>(<span class="keywordtype">void</span>);00216 00227 MG_EXPORT <span class="keywordtype">void</span> <a class="code" href="group__general__rw__fns.htm#ga6">MGUI_FreeRW</a>(<a class="code" href="struct__MG__RWops.htm">MG_RWops</a> *area);00228 <a name="l00250"></a><a class="code" href="group__general__rw__fns.htm#ga11">00250</a> <span class="preprocessor">#define MGUI_RWseek(ctx, offset, whence) (ctx)->seek(ctx, offset, whence)</span>00251 <span class="preprocessor"></span><a name="l00265"></a><a class="code" href="group__general__rw__fns.htm#ga12">00265</a> <span class="preprocessor">#define MGUI_RWtell(ctx) (ctx)->seek(ctx, 0, SEEK_CUR)</span>00266 <span class="preprocessor"></span><a name="l00282"></a><a class="code" href="group__general__rw__fns.htm#ga13">00282</a> <span class="preprocessor">#define MGUI_RWread(ctx, ptr, size, n) (ctx)->read(ctx, ptr, size, n)</span>00283 <span class="preprocessor"></span><a name="l00299"></a><a class="code" href="group__general__rw__fns.htm#ga14">00299</a> <span class="preprocessor">#define MGUI_RWwrite(ctx, ptr, size, n) (ctx)->write(ctx, ptr, size, n)</span>00300 <span class="preprocessor"></span><a name="l00314"></a><a class="code" href="group__general__rw__fns.htm#ga15">00314</a> <span class="preprocessor">#define MGUI_RWclose(ctx) (ctx)->close(ctx)</span>00315 <span class="preprocessor"></span><a name="l00329"></a><a class="code" href="group__general__rw__fns.htm#ga16">00329</a> <span class="preprocessor">#define MGUI_RWeof(ctx) (ctx)->eof(ctx)</span>00330 <span class="preprocessor"></span>00345 MG_EXPORT <span class="keywordtype">int</span> <a class="code" href="group__general__rw__fns.htm#ga7">MGUI_RWgetc</a> (<a class="code" href="struct__MG__RWops.htm">MG_RWops</a>* area);00346 00349 <span class="comment">/****************** Endian specific read/write interfaces *********************/</span>00350 00373 <span class="comment">/* The macros used to swap values */</span>00374 <span class="comment">/* Try to use superfast macros on systems that support them */</span>00375 <span class="preprocessor">#ifdef linux</span>00376 <span class="preprocessor"></span><span class="preprocessor">#include <endian.h></span>00377 <span class="preprocessor">#ifdef __arch__swab16</span>00378 <span class="preprocessor"></span><span class="preprocessor">#define ArchSwap16 __arch__swab16</span>00379 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00380 <span class="preprocessor"></span><span class="preprocessor">#ifdef __arch__swab32</span>00381 <span class="preprocessor"></span><span class="preprocessor">#define ArchSwap32 __arch__swab32</span>00382 <span class="preprocessor"></span><span class="preprocessor">#endif</span>00383 <span class="preprocessor"></span><span class="preprocessor">#endif </span><span class="comment">/* linux */</span>00384 00385 <span class="comment">/* Use inline functions for compilers that support them, and static</span>00386 <span class="comment"> functions for those that do not. Because these functions become</span>00387 <span class="comment"> static for compilers that do not support inline functions, this</span>00388 <span class="comment"> header should only be included in files that actually use them.</span>00389 <span class="comment">*/</span>00390 <span class="preprocessor">#ifndef ArchSwap16</span>00391 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="group__basic__types.htm#ga2">Uint16</a> ArchSwap16(<a class="code" href="group__basic__types.htm#ga2">Uint16</a> D) {00392 <span class="keywordflow">return</span>((D<<8)|(D>>8));00393 }00394 <span class="preprocessor">#endif</span>00395 <span class="preprocessor"></span><span class="preprocessor">#ifndef ArchSwap32</span>00396 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="group__basic__types.htm#ga4">Uint32</a> ArchSwap32(<a class="code" href="group__basic__types.htm#ga4">Uint32</a> D) {00397 <span class="keywordflow">return</span>((D<<24)|((D<<8)&0x00FF0000)|((D>>8)&0x0000FF00)|(D>>24));00398 }00399 <span class="preprocessor">#endif</span>00400 <span class="preprocessor"></span><span class="preprocessor">#ifdef MGUI_HAS_64BIT_TYPE</span>00401 <span class="preprocessor"></span><span class="preprocessor">#ifndef ArchSwap64</span>00402 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keyword">inline</span> <a class="code" href="group__basic__types.htm#ga6">Uint64</a> ArchSwap64(<a class="code" href="group__basic__types.htm#ga6">Uint64</a> val) {00403 <a class="code" href="group__basic__types.htm#ga4">Uint32</a> hi, lo;00404 00405 <span class="comment">/* Separate into high and low 32-bit values and swap them */</span>00406 lo = (<a class="code" href="group__basic__types.htm#ga4">Uint32</a>)(val&0xFFFFFFFF);00407 val >>= 32;00408 hi = (<a class="code" href="group__basic__types.htm#ga4">Uint32</a>)(val&0xFFFFFFFF);00409 val = ArchSwap32(lo);00410 val <<= 32;00411 val |= ArchSwap32(hi);00412 <span class="keywordflow">return</span>(val);00413 }00414 <span class="preprocessor">#endif</span>00415 <span class="preprocessor"></span><span class="preprocessor">#else</span>00416 <span class="preprocessor"></span><span class="preprocessor">#ifndef ArchSwap64</span>00417 <span class="preprocessor"></span><span class="comment">/* This is mainly to keep compilers from complaining in MGUI code.</span>00418 <span class="comment"> If there is no real 64-bit datatype, then compilers will complain about</span>00419 <span class="comment"> the fake 64-bit datatype that MGUI provides when it compiles user code.</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -