buffer.h
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:3k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*****************************************************************************
  2.  *
  3.  * This program is free software ; you can redistribute it and/or modify
  4.  * it under the terms of the GNU General Public License as published by
  5.  * the Free Software Foundation; either version 2 of the License, or
  6.  * (at your option) any later version.
  7.  *
  8.  * This program is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11.  * GNU General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU General Public License
  14.  * along with this program; if not, write to the Free Software
  15.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  16.  *
  17.  * $Id: buffer.h 432 2005-12-28 16:39:13Z picard $
  18.  *
  19.  * The Core Pocket Media Player
  20.  * Copyright (c) 2004-2005 Gabor Kovacs
  21.  *
  22.  ****************************************************************************/
  23. #ifndef __BUFFER_H
  24. #define __BUFFER_H
  25. #define SAFETAIL 256
  26. struct stream;
  27. typedef struct buffer
  28. {
  29. uint8_t* Data;
  30. int WritePos;
  31. int ReadPos;
  32. int Allocated;
  33. } buffer;
  34. DLL void BufferClear(buffer*);
  35. DLL void BufferDrop(buffer*);
  36. DLL bool_t BufferAlloc(buffer* p, size_t Size, size_t Align);
  37. DLL bool_t BufferWrite(buffer*, const void* Ptr, size_t Length, size_t Align);
  38. DLL bool_t BufferRead(buffer*, const uint8_t** Ptr, size_t Length);
  39. DLL void BufferPack(buffer*, size_t Readed);
  40. DLL bool_t BufferStream(buffer*, struct stream*);
  41. typedef struct array
  42. {
  43. // these are private members
  44. uint8_t* _Begin;
  45. uint8_t* _End;
  46. size_t _Allocated;
  47. block _Block;
  48. } array;
  49. typedef int (*arraycmp)(const void* a,const void* b);
  50. DLL void ArrayClear(array*);
  51. DLL void ArrayDrop(array*);
  52. DLL int ArrayFind(const array* p, int Count, size_t Width, const void* Data, arraycmp Cmp, bool_t* Found);
  53. DLL bool_t ArrayAlloc(array* p,size_t Total,size_t Align);
  54. DLL bool_t ArrayAppend(array* p, const void* Ptr, size_t Length, size_t Align);
  55. DLL bool_t ArrayAdd(array* p, int Count, size_t Width, const void* Data, arraycmp Cmp,size_t Align);
  56. DLL bool_t ArrayRemove(array* p, int Count, size_t Width, const void* Data, arraycmp Cmp);
  57. DLL void ArraySort(array* p, int Count, size_t Width, arraycmp Cmp);
  58. DLL void ArrayLock(array*);
  59. DLL bool_t ArrayUnlock(array*,size_t Align);
  60. #define ARRAYEMPTY(Array) ((Array)._Begin==(Array)._End)
  61. #define ARRAYBEGIN(Array,Type) ((Type*)((Array)._Begin))
  62. #define ARRAYEND(Array,Type) ((Type*)((Array)._End))
  63. #define ARRAYCOUNT(Array,Type) ((int)(ARRAYEND(Array,Type)-ARRAYBEGIN(Array,Type)))
  64. #define ARRAYALLOCATED(Array,Type) ((int)((Array)._Allocated/sizeof(Type)))
  65. #endif