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 */
21 PandaIOSystem::
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 {
30 Filename fn = Filename::from_os_specific(file);
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 {
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 */
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 */
70Assimp::IOStream *PandaIOSystem::
71 Open(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}
Filename
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
Filename::make_canonical
bool make_canonical()
Converts this filename to a canonical name by replacing the directory part with the fully-qualified d...
Definition filename.cxx:1011
PandaIOStream
Custom implementation of Assimp::IOStream.
Definition pandaIOStream.h:27
PandaIOSystem::Exists
bool Exists(const char *file) const
Returns true if the file exists, duh.
Definition pandaIOSystem.cxx:29
PandaIOSystem::getOsSeparator
char getOsSeparator() const
Returns the path separator for this operating system.
Definition pandaIOSystem.cxx:59
PandaIOSystem::ComparePaths
bool ComparePaths(const char *p1, const char *p2) const
Returns true if the two paths point to the same file, false if not.
Definition pandaIOSystem.cxx:47
PandaIOSystem::Open
Assimp::IOStream * Open(const char *file, const char *mode)
Opens the indicated file.
Definition pandaIOSystem.cxx:71
PandaIOSystem::Close
void Close(Assimp::IOStream *file)
Closes the indicated file stream.
Definition pandaIOSystem.cxx:38
PandaIOSystem::PandaIOSystem
PandaIOSystem(VirtualFileSystem *vfs=VirtualFileSystem::get_global_ptr())
Initializes the object with the given VFS, or the global one if none was specified.
Definition pandaIOSystem.cxx:22
VirtualFileSystem
A hierarchy of directories and files that appears to be one continuous file system,...
Definition virtualFileSystem.h:40
pandaIOStream.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandaIOSystem.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.