binfile.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * This library is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU Lesser General Public
  4. * License as published by the Free Software Foundation; either
  5. * version 2.1 of the License, or (at your option) any later version.
  6. *
  7. * This library is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. * Lesser General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU Lesser General Public
  13. * License along with this library; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  15. *
  16. * binfile.h - Binary file I/O
  17. * Copyright (C) 2002, 2003 Simon Peter <dn.tlp@gmx.net>
  18. */
  19. #ifndef H_BINIO_BINFILE
  20. #define H_BINIO_BINFILE
  21. #include <stdio.h>
  22. #include "binio.h"
  23. #ifdef _MSC_VER
  24. #pragma warning (disable:4244)
  25. #pragma warning (disable:4996)
  26. #endif
  27. class binfbase: virtual public binio {
  28. public:
  29. typedef enum {
  30. Append = 1 << 0,
  31. NoCreate = 1 << 1
  32. } ModeFlags;
  33. typedef int Mode;
  34. binfbase();
  35. virtual ~binfbase();
  36. virtual void open(const char *filename, const Mode mode) = 0;
  37. #if BINIO_ENABLE_STRING
  38. virtual void open(const std::string &filename, const Mode mode) = 0;
  39. #endif
  40. void close();
  41. virtual void seek(long pos, Offset offs = Set);
  42. virtual long pos();
  43. protected:
  44. FILE *f;
  45. };
  46. class binifstream: public binistream, virtual public binfbase {
  47. public:
  48. binifstream();
  49. binifstream(const char *filename, const Mode mode = NoCreate);
  50. #if BINIO_ENABLE_STRING
  51. binifstream(const std::string &filename, const Mode mode = NoCreate);
  52. #endif
  53. virtual ~binifstream();
  54. virtual void open(const char *filename, const Mode mode = NoCreate);
  55. #if BINIO_ENABLE_STRING
  56. virtual void open(const std::string &filename, const Mode mode = NoCreate);
  57. #endif
  58. protected:
  59. virtual Byte getByte();
  60. };
  61. class binofstream: public binostream, virtual public binfbase {
  62. public:
  63. binofstream();
  64. binofstream(const char *filename, const Mode mode = 0);
  65. #if BINIO_ENABLE_STRING
  66. binofstream(const std::string &filename, const Mode mode = 0);
  67. #endif
  68. virtual ~binofstream();
  69. virtual void open(const char *filename, const Mode mode = 0);
  70. #if BINIO_ENABLE_STRING
  71. virtual void open(const std::string &filename, const Mode mode = 0);
  72. #endif
  73. protected:
  74. virtual void putByte(Byte b);
  75. };
  76. class binfstream: public binifstream, public binofstream {
  77. public:
  78. binfstream();
  79. binfstream(const char *filename, const Mode mode = 0);
  80. #if BINIO_ENABLE_STRING
  81. binfstream(const std::string &filename, const Mode mode = 0);
  82. #endif
  83. virtual ~binfstream();
  84. virtual void open(const char *filename, const Mode mode = 0);
  85. #if BINIO_ENABLE_STRING
  86. virtual void open(const std::string &filename, const Mode mode = 0);
  87. #endif
  88. };
  89. #endif