Panda3D
pandaIOSystem.cxx
1 // Filename: pandaIOSystem.cxx
2 // Created by: rdb (29Mar11)
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 #include "pandaIOSystem.h"
16 #include "pandaIOStream.h"
17 
18 ////////////////////////////////////////////////////////////////////
19 // Function: PandaIOSystem::Constructor
20 // Access: Public
21 // Description: Initializes the object with the given VFS, or the
22 // global one if none was specified.
23 ////////////////////////////////////////////////////////////////////
25 PandaIOSystem(VirtualFileSystem *vfs) : _vfs(vfs) {
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: PandaIOSystem::Exists
30 // Access: Public
31 // Description: Returns true if the file exists, duh.
32 ////////////////////////////////////////////////////////////////////
33 bool PandaIOSystem::
34 Exists(const char *file) const {
36  return _vfs->exists(fn);
37 }
38 
39 ////////////////////////////////////////////////////////////////////
40 // Function: PandaIOSystem::Close
41 // Access: Public
42 // Description: Closes the indicated file stream.
43 ////////////////////////////////////////////////////////////////////
44 void PandaIOSystem::
45 Close(Assimp::IOStream *file) {
46  PandaIOStream *pstr = (PandaIOStream*) file;
47  _vfs->close_read_file(&pstr->_istream);
48 }
49 
50 ////////////////////////////////////////////////////////////////////
51 // Function: PandaIOSystem::ComparePaths
52 // Access: Public
53 // Description: Returns true if the two paths point to the same
54 // file, false if not.
55 ////////////////////////////////////////////////////////////////////
56 bool PandaIOSystem::
57 ComparePaths(const char *p1, const char *p2) const {
60  fn1.make_canonical();
61  fn2.make_canonical();
62  return fn1 == fn2;
63 }
64 
65 ////////////////////////////////////////////////////////////////////
66 // Function: PandaIOSystem::getOsSeparator
67 // Access: Public
68 // Description: Returns the path separator for this operating
69 // system.
70 ////////////////////////////////////////////////////////////////////
71 char PandaIOSystem::
72 getOsSeparator() const {
73 #ifdef _WIN32
74  return '\\';
75 #else
76  return '/';
77 #endif
78 }
79 
80 ////////////////////////////////////////////////////////////////////
81 // Function: PandaIOSystem::Open
82 // Access: Public
83 // Description: Opens the indicated file.
84 ////////////////////////////////////////////////////////////////////
85 Assimp::IOStream *PandaIOSystem::
86 Open(const char *file, const char *mode) {
88 
89  if (mode[0] == 'r') {
90  istream *stream = _vfs->open_read_file(file, true);
91  if (stream == NULL) {
92  return NULL;
93  }
94  return new PandaIOStream(*stream);
95 
96  } else {
97  nassertr(false, NULL); // Not implemented on purpose.
98  }
99 }
Assimp::IOStream * Open(const char *file, const char *mode)
Opens the indicated file.
char getOsSeparator() const
Returns the path separator for this operating system.
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's file system.
istream * open_read_file(const Filename &filename, bool auto_unwrap) const
Convenience function; returns a newly allocated istream if the file exists and can be read...
void Close(Assimp::IOStream *file)
Closes the indicated file stream.
bool ComparePaths(const char *p1, const char *p2) const
Returns true if the two paths point to the same file, false if not.
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Definition: filename.cxx:1072
static void close_read_file(istream *stream)
Closes a file opened by a previous call to open_read_file().
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists.
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:44
bool Exists(const char *file) const
Returns true if the file exists, duh.
PandaIOSystem(VirtualFileSystem *vfs=VirtualFileSystem::get_global_ptr())
Initializes the object with the given VFS, or the global one if none was specified.
Custom implementation of Assimp::IOStream.
Definition: pandaIOStream.h:30
static Filename from_os_specific(const string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes, and no drive letter) based on the supplied filename string that describes a filename in the local system conventions (for instance, on Windows, it may use backslashes or begin with a drive letter and a colon).
Definition: filename.cxx:332