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