Panda3D
pandaIOSystem.cxx
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 pandaIOSystem.cxx
10  * @author rdb
11  * @date 2011-03-29
12  */
13 
14 #include "pandaIOSystem.h"
15 #include "pandaIOStream.h"
16 
17 /**
18  * Initializes the object with the given VFS, or the global one if none was
19  * specified.
20  */
22 PandaIOSystem(VirtualFileSystem *vfs) : _vfs(vfs) {
23 }
24 
25 /**
26  * Returns true if the file exists, duh.
27  */
28 bool PandaIOSystem::
29 Exists(const char *file) const {
31  return _vfs->exists(fn);
32 }
33 
34 /**
35  * Closes the indicated file stream.
36  */
37 void PandaIOSystem::
38 Close(Assimp::IOStream *file) {
39  PandaIOStream *pstr = (PandaIOStream*) file;
40  _vfs->close_read_file(&pstr->_istream);
41 }
42 
43 /**
44  * Returns true if the two paths point to the same file, false if not.
45  */
46 bool PandaIOSystem::
47 ComparePaths(const char *p1, const char *p2) const {
50  fn1.make_canonical();
51  fn2.make_canonical();
52  return fn1 == fn2;
53 }
54 
55 /**
56  * Returns the path separator for this operating system.
57  */
58 char PandaIOSystem::
59 getOsSeparator() const {
60 #ifdef _WIN32
61  return '\\';
62 #else
63  return '/';
64 #endif
65 }
66 
67 /**
68  * Opens the indicated file.
69  */
70 Assimp::IOStream *PandaIOSystem::
71 Open(const char *file, const char *mode) {
73 
74  if (mode[0] == 'r') {
75  std::istream *stream = _vfs->open_read_file(file, true);
76  if (stream == nullptr) {
77  return nullptr;
78  }
79  return new PandaIOStream(*stream);
80 
81  } else {
82  nassert_raise("write mode not implemented");
83  return nullptr;
84  }
85 }
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,...
std::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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Definition: filename.cxx:1011
static void close_read_file(std::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:39
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.
static Filename from_os_specific(const std::string &os_specific, Type type=T_general)
This named constructor returns a Panda-style filename (that is, using forward slashes,...
Definition: filename.cxx:328
Custom implementation of Assimp::IOStream.
Definition: pandaIOStream.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.