Panda3D
Loading...
Searching...
No Matches
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 */
24
25/**
26 * Returns true if the file exists, duh.
27 */
29Exists(const char *file) const {
30 Filename fn = Filename::from_os_specific(file);
31 return _vfs->exists(fn);
32}
33
34/**
35 * Closes the indicated file stream.
36 */
38Close(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 */
47ComparePaths(const char *p1, const char *p2) const {
48 Filename fn1 = Filename::from_os_specific(p1);
49 Filename fn2 = Filename::from_os_specific(p2);
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 */
59getOsSeparator() const {
60#ifdef _WIN32
61 return '\\';
62#else
63 return '/';
64#endif
65}
66
67/**
68 * Opens the indicated file.
69 */
70Assimp::IOStream *PandaIOSystem::
71Open(const char *file, const char *mode) {
72 Filename fn = Filename::from_os_specific(file);
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}
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Custom implementation of Assimp::IOStream.
bool Exists(const char *file) const
Returns true if the file exists, duh.
char getOsSeparator() const
Returns the path separator for this operating system.
bool ComparePaths(const char *p1, const char *p2) const
Returns true if the two paths point to the same file, false if not.
Assimp::IOStream * Open(const char *file, const char *mode)
Opens the indicated file.
void Close(Assimp::IOStream *file)
Closes the indicated file stream.
PandaIOSystem(VirtualFileSystem *vfs=VirtualFileSystem::get_global_ptr())
Initializes the object with the given VFS, or the global one if none was specified.
A hierarchy of directories and files that appears to be one continuous file system,...
bool exists(const Filename &filename) const
Convenience function; returns true if the named file exists in the virtual file system hierarchy.
static void close_read_file(std::istream *stream)
Closes a file opened by a previous call to open_read_file().
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,...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.