Panda3D
virtualFileSimple.h
1 // Filename: virtualFileSimple.h
2 // Created by: drose (03Aug02)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef VIRTUALFILESIMPLE_H
16 #define VIRTUALFILESIMPLE_H
17 
18 #include "pandabase.h"
19 
20 #include "virtualFile.h"
21 
22 ////////////////////////////////////////////////////////////////////
23 // Class : VirtualFileSimple
24 // Description : A simple file or directory within the
25 // VirtualFileSystem: this maps to exactly one file on
26 // one mount point. Most directories, and all regular
27 // files, are of this kind.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDAEXPRESS VirtualFileSimple : public VirtualFile {
30 public:
31  INLINE VirtualFileSimple(VirtualFileMount *mount,
32  const Filename &local_filename,
33  bool implicit_pz_file,
34  int open_flags);
35 
36 PUBLISHED:
37  virtual VirtualFileSystem *get_file_system() const;
38  INLINE VirtualFileMount *get_mount() const;
39  virtual Filename get_filename() const;
40 
41  virtual bool has_file() const;
42  virtual bool is_directory() const;
43  virtual bool is_regular_file() const;
44  virtual bool is_writable() const;
45  INLINE bool is_implicit_pz_file() const;
46 
47  virtual bool delete_file();
48  virtual bool rename_file(VirtualFile *new_file);
49  virtual bool copy_file(VirtualFile *new_file);
50 
51  virtual istream *open_read_file(bool auto_unwrap) const;
52  virtual void close_read_file(istream *stream) const;
53  virtual ostream *open_write_file(bool auto_wrap, bool truncate);
54  virtual ostream *open_append_file();
55  virtual void close_write_file(ostream *stream);
56  virtual iostream *open_read_write_file(bool truncate);
57  virtual iostream *open_read_append_file();
58  virtual void close_read_write_file(iostream *stream);
59 
60  virtual streamsize get_file_size(istream *stream) const;
61  virtual streamsize get_file_size() const;
62  virtual time_t get_timestamp() const;
63  virtual bool get_system_info(SubfileInfo &info);
64 
65 public:
66  virtual bool atomic_compare_and_exchange_contents(string &orig_contents, const string &old_contents, const string &new_contents);
67  virtual bool atomic_read_contents(string &contents) const;
68 
69  virtual bool read_file(pvector<unsigned char> &result, bool auto_unwrap) const;
70  virtual bool write_file(const unsigned char *data, size_t data_size, bool auto_wrap);
71 
72 protected:
73  virtual bool scan_local_directory(VirtualFileList *file_list,
74  const ov_set<string> &mount_points) const;
75 
76 private:
77  VirtualFileMount *_mount;
78  Filename _local_filename;
79  bool _implicit_pz_file;
80  int _open_flags;
81 
82 public:
83  virtual TypeHandle get_type() const {
84  return get_class_type();
85  }
86  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
87 
88 PUBLISHED:
89  static TypeHandle get_class_type() {
90  return _type_handle;
91  }
92 
93 public:
94  static void init_type() {
95  VirtualFile::init_type();
96  register_type(_type_handle, "VirtualFileSimple",
97  VirtualFile::get_class_type());
98  }
99 
100 private:
101  static TypeHandle _type_handle;
102 };
103 
104 #include "virtualFileSimple.I"
105 
106 #endif
virtual void close_read_file(istream *stream) const
Closes a file opened by a previous call to open_read_file().
virtual ostream * open_append_file()
Works like open_write_file(), but the file is opened in append mode.
virtual void close_read_write_file(iostream *stream)
Closes a file opened by a previous call to open_read_write_file().
A hierarchy of directories and files that appears to be one continuous file system, even though the files may originate from several different sources that may not be related to the actual OS&#39;s file system.
virtual ostream * open_write_file(bool auto_wrap, bool truncate)
Opens the file for writing.
virtual bool is_writable() const
Returns true if this file may be written to, which implies write_file() may be called (unless it is a...
Definition: virtualFile.cxx:64
virtual bool copy_file(VirtualFile *new_file)
Attempts to copy the contents of this file to the indicated file.
virtual time_t get_timestamp() const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
virtual void close_write_file(ostream *stream)
Closes a file opened by a previous call to open_write_file().
The abstract base class for a file or directory within the VirtualFileSystem.
Definition: virtualFile.h:37
A specialization of ordered_vector that emulates a standard STL set: one copy of each element is allo...
virtual bool get_system_info(SubfileInfo &info)
Populates the SubfileInfo structure with the data representing where the file actually resides on dis...
virtual iostream * open_read_write_file(bool truncate)
Opens the file for writing.
virtual bool atomic_read_contents(string &contents) const
See Filename::atomic_read_contents().
A list of VirtualFiles, as returned by VirtualFile::scan_directory().
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
virtual bool is_directory() const
Returns true if this file represents a directory (and scan_directory() may be called), false otherwise.
Definition: virtualFile.cxx:41
virtual iostream * open_read_append_file()
Works like open_read_write_file(), but the file is opened in append mode.
virtual bool delete_file()
Attempts to delete this file or directory.
Definition: virtualFile.cxx:77
virtual bool has_file() const
Returns true if this file exists, false otherwise.
Definition: virtualFile.cxx:30
virtual istream * open_read_file(bool auto_unwrap) const
Opens the file for reading.
bool write_file(const string &data, bool auto_wrap)
Writes the entire contents of the file as a string, if it is writable.
Definition: virtualFile.I:56
The abstract base class for a mount definition used within a VirtualFileSystem.
string read_file(bool auto_unwrap) const
Returns the entire contents of the file as a string.
Definition: virtualFile.I:43
virtual bool rename_file(VirtualFile *new_file)
Attempts to move or rename this file or directory.
Definition: virtualFile.cxx:99
virtual bool atomic_compare_and_exchange_contents(string &orig_contents, const string &old_contents, const string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
This class records a particular byte sub-range within an existing file on disk.
Definition: subfileInfo.h:29
virtual streamsize get_file_size() const
Returns the current size on disk (or wherever it is) of the file before it has been opened...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
virtual bool is_regular_file() const
Returns true if this file represents a regular file (and read_file() may be called), false otherwise.
Definition: virtualFile.cxx:52
A simple file or directory within the VirtualFileSystem: this maps to exactly one file on one mount p...