hfile.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ////////////////////////////////////////////////////////////////////////////////////////
  2. // RAVEN STANDARD USEFUL FUNCTION LIBRARY
  3. // (c) 2002 Activision
  4. //
  5. //
  6. // Handle File
  7. // -----------
  8. //
  9. ////////////////////////////////////////////////////////////////////////////////////////
  10. #if !defined(RUFL_HFILE_INC)
  11. #define RUFL_HFILE_INC
  12. ////////////////////////////////////////////////////////////////////////////////////////
  13. // HFile Bindings
  14. //
  15. // These are the standard C hfile bindings, copy these function wrappers to your .cpp
  16. // before including hfile, and modify them if needed to support a different file
  17. // system.
  18. ////////////////////////////////////////////////////////////////////////////////////////
  19. //bool HFILEopen_read(int& handle, const char* filepath) {handle=(int)fopen(filepath, "rb"); return (handle!=0);}
  20. //bool HFILEopen_write(int& handle, const char* filepath) {handle=(int)fopen(filepath, "wb"); return (handle!=0);}
  21. //bool HFILEread(int& handle, void* data, int size) {return (fread(data, size, 1, (FILE*)(handle))>0);}
  22. //bool HFILEwrite(int& handle, const void* data, int size) {return (fwrite(data, size, 1, (FILE*)(handle))>0);}
  23. //bool HFILEclose(int& handle) {return (fclose((FILE*)handle)==0);}
  24. ////////////////////////////////////////////////////////////////////////////////////////
  25. // The Handle String Class
  26. ////////////////////////////////////////////////////////////////////////////////////////
  27. class hfile
  28. {
  29. public:
  30. ////////////////////////////////////////////////////////////////////////////////////
  31. // Constructors
  32. ////////////////////////////////////////////////////////////////////////////////////
  33. hfile(const char *file);
  34. ~hfile();
  35. bool load(void* data, int datasize);
  36. bool save(void* data, int datasize);
  37. bool is_open(void) const;
  38. bool is_open_for_read(void) const;
  39. bool is_open_for_write(void) const;
  40. bool open_read(float version=1.0f, int checksum=0) {return open(version, checksum, true);}
  41. bool open_write(float version=1.0f, int checksum=0) {return open(version, checksum, false);}
  42. bool close();
  43. private:
  44. bool open(float version, int checksum, bool read);
  45. int mHandle;
  46. };
  47. #endif // hfile_H