00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef VERTEXDATASAVEFILE_H
00016 #define VERTEXDATASAVEFILE_H
00017
00018 #include "pandabase.h"
00019 #include "simpleAllocator.h"
00020 #include "filename.h"
00021 #include "pmutex.h"
00022
00023 #if defined(_WIN32)
00024 #define WIN32_LEAN_AND_MEAN
00025 #include <windows.h>
00026 #endif
00027
00028 class VertexDataSaveBlock;
00029
00030
00031
00032
00033
00034
00035
00036
00037 class EXPCL_PANDA_GOBJ VertexDataSaveFile : public SimpleAllocator {
00038 public:
00039 VertexDataSaveFile(const Filename &directory, const string &prefix,
00040 size_t max_size);
00041 ~VertexDataSaveFile();
00042
00043 PUBLISHED:
00044 INLINE bool is_valid() const;
00045
00046 INLINE size_t get_total_file_size() const;
00047 INLINE size_t get_used_file_size() const;
00048
00049 public:
00050 PT(VertexDataSaveBlock) write_data(const unsigned char *data, size_t size,
00051 bool compressed);
00052 bool read_data(unsigned char *data, size_t size,
00053 VertexDataSaveBlock *block);
00054
00055 protected:
00056 virtual SimpleAllocatorBlock *make_block(size_t start, size_t size);
00057
00058 private:
00059 Filename _filename;
00060 bool _is_valid;
00061 size_t _total_file_size;
00062 Mutex _lock;
00063
00064 #ifdef _WIN32
00065 HANDLE _handle;
00066 #else
00067 int _fd;
00068 #endif // _WIN32
00069 };
00070
00071
00072
00073
00074
00075 class EXPCL_PANDA_GOBJ VertexDataSaveBlock : public SimpleAllocatorBlock, public ReferenceCount {
00076 protected:
00077 INLINE VertexDataSaveBlock(VertexDataSaveFile *file,
00078 size_t start, size_t size);
00079
00080 public:
00081 INLINE void set_compressed(bool compressed);
00082 INLINE bool get_compressed() const;
00083
00084 private:
00085 bool _compressed;
00086
00087 public:
00088 INLINE unsigned char *get_pointer() const;
00089
00090 friend class VertexDataSaveFile;
00091 };
00092
00093 #include "vertexDataSaveFile.I"
00094
00095 #endif