23 TypeHandle VirtualFileMountRamdisk::_type_handle;
24 TypeHandle VirtualFileMountRamdisk::FileBase::_type_handle;
25 TypeHandle VirtualFileMountRamdisk::File::_type_handle;
26 TypeHandle VirtualFileMountRamdisk::Directory::_type_handle;
31 VirtualFileMountRamdisk::
32 VirtualFileMountRamdisk() : _root(
"") {
41 PT(FileBase) f = _root.do_find_file(file);
43 return (f !=
nullptr);
54 PT(File) f = _root.do_create_file(file);
56 return (f !=
nullptr);
67 PT(FileBase) f = _root.do_delete_file(file);
69 return (f !=
nullptr);
81 PT(FileBase) orig_fb = _root.do_find_file(orig_filename);
82 if (orig_fb ==
nullptr) {
87 if (orig_fb->is_directory()) {
89 Directory *orig_d = DCAST(Directory, orig_fb);
90 PT(Directory) new_d = _root.do_make_directory(new_filename);
91 if (new_d ==
nullptr || !new_d->_files.empty()) {
96 if (express_cat.is_debug()) {
98 <<
"Renaming ramdisk directory " << orig_filename <<
" to " << new_filename <<
"\n";
101 new_d->_files.swap(orig_d->_files);
102 _root.do_delete_file(orig_filename);
108 File *orig_f = DCAST(File, orig_fb);
109 PT(File) new_f = _root.do_create_file(new_filename);
110 if (new_f ==
nullptr) {
115 if (express_cat.is_debug()) {
117 <<
"Renaming ramdisk file " << orig_filename <<
" to " << new_filename <<
"\n";
120 new_f->_data.str(orig_f->_data.str());
121 _root.do_delete_file(orig_filename);
136 PT(FileBase) orig_fb = _root.do_find_file(orig_filename);
137 if (orig_fb ==
nullptr || orig_fb->is_directory()) {
143 File *orig_f = DCAST(File, orig_fb);
144 PT(File) new_f = _root.do_create_file(new_filename);
145 if (new_f ==
nullptr) {
150 if (express_cat.is_debug()) {
152 <<
"Copying ramdisk file " << orig_filename <<
" to " << new_filename <<
"\n";
155 new_f->_data.str(orig_f->_data.str());
170 PT(Directory) f = _root.do_make_directory(file);
172 return (f !=
nullptr);
182 PT(FileBase) f = _root.do_find_file(file);
184 return (f !=
nullptr && f->is_directory());
194 PT(FileBase) f = _root.do_find_file(file);
196 return (f !=
nullptr && !f->is_directory());
216 PT(FileBase) f = _root.do_find_file(file);
218 if (f ==
nullptr || f->is_directory()) {
222 File *f2 = DCAST(File, f);
234 PT(File) f = _root.do_create_file(file);
242 f->_data.str(
string());
249 f->_timestamp = std::max(f->_timestamp + 1, time(
nullptr));
263 PT(File) f = _root.do_create_file(file);
269 return new OSubStream(&f->_wrapper, 0, 0,
true);
280 PT(File) f = _root.do_create_file(file);
288 f->_data.str(
string());
291 f->_timestamp = std::max(f->_timestamp + 1, time(
nullptr));
294 return new SubStream(&f->_wrapper, 0, 0);
305 PT(FileBase) f = _root.do_find_file(file);
307 if (f ==
nullptr || f->is_directory()) {
311 File *f2 = DCAST(File, f);
312 return new SubStream(&f2->_wrapper, 0, 0,
true);
323 PT(FileBase) f = _root.do_find_file(file);
325 if (f ==
nullptr || f->is_directory()) {
329 File *f2 = DCAST(File, f);
330 return f2->_data.str().length();
340 PT(FileBase) f = _root.do_find_file(file);
342 if (f ==
nullptr || f->is_directory()) {
346 File *f2 = DCAST(File, f);
347 return f2->_data.str().length();
363 PT(FileBase) f = _root.do_find_file(file);
368 time_t timestamp = f->_timestamp;
381 PT(FileBase) f = _root.do_find_file(dir);
382 if (f ==
nullptr || !f->is_directory()) {
387 Directory *f2 = DCAST(Directory, f);
388 bool result = f2->do_scan_directory(contents);
399 const string &old_contents,
400 const string &new_contents) {
402 PT(FileBase) f = _root.do_find_file(file);
403 if (f ==
nullptr || f->is_directory()) {
409 File *f2 = DCAST(File, f);
410 orig_contents = f2->_data.str();
411 if (orig_contents == old_contents) {
412 f2->_data.str(new_contents);
413 f2->_timestamp = time(
nullptr);
427 PT(FileBase) f = _root.do_find_file(file);
428 if (f ==
nullptr || f->is_directory()) {
433 File *f2 = DCAST(File, f);
434 contents = f2->_data.str();
444 void VirtualFileMountRamdisk::
445 output(ostream &out)
const {
446 out <<
"VirtualFileMountRamdisk";
452 VirtualFileMountRamdisk::FileBase::
459 bool VirtualFileMountRamdisk::FileBase::
460 is_directory()
const {
467 bool VirtualFileMountRamdisk::Directory::
468 is_directory()
const {
476 PT(VirtualFileMountRamdisk::FileBase) VirtualFileMountRamdisk::Directory::
477 do_find_file(
const string &filename)
const {
478 size_t slash = filename.find(
'/');
479 if (slash == string::npos) {
481 FileBase tfile(filename);
482 tfile.local_object();
483 Files::const_iterator fi = _files.find(&tfile);
484 if (fi != _files.end()) {
491 string dirname = filename.substr(0, slash);
492 string remainder = filename.substr(slash + 1);
493 FileBase tfile(dirname);
494 tfile.local_object();
495 Files::const_iterator fi = _files.find(&tfile);
496 if (fi != _files.end()) {
497 PT(FileBase) file = (*fi);
498 if (file->is_directory()) {
499 return DCAST(Directory, file.p())->do_find_file(remainder);
510 PT(VirtualFileMountRamdisk::File) VirtualFileMountRamdisk::Directory::
511 do_create_file(
const string &filename) {
512 size_t slash = filename.find(
'/');
513 if (slash == string::npos) {
515 FileBase tfile(filename);
516 tfile.local_object();
517 Files::iterator fi = _files.find(&tfile);
518 if (fi != _files.end()) {
519 PT(FileBase) file = (*fi);
520 if (!file->is_directory()) {
521 return DCAST(File, file.p());
528 if (express_cat.is_debug()) {
530 <<
"Making ramdisk file " << filename <<
"\n";
532 PT(File) file =
new File(filename);
533 _files.insert(file.p());
534 _timestamp = time(
nullptr);
539 string dirname = filename.substr(0, slash);
540 string remainder = filename.substr(slash + 1);
541 FileBase tfile(dirname);
542 tfile.local_object();
543 Files::iterator fi = _files.find(&tfile);
544 if (fi != _files.end()) {
545 PT(FileBase) file = (*fi);
546 if (file->is_directory()) {
547 return DCAST(Directory, file.p())->do_create_file(remainder);
558 PT(VirtualFileMountRamdisk::Directory) VirtualFileMountRamdisk::Directory::
559 do_make_directory(
const string &filename) {
560 size_t slash = filename.find(
'/');
561 if (slash == string::npos) {
563 FileBase tfile(filename);
564 tfile.local_object();
565 Files::iterator fi = _files.find(&tfile);
566 if (fi != _files.end()) {
567 PT(FileBase) file = (*fi);
568 if (file->is_directory()) {
569 return DCAST(Directory, file.p());
576 if (express_cat.is_debug()) {
578 <<
"Making ramdisk directory " << filename <<
"\n";
580 PT(Directory) file =
new Directory(filename);
581 _files.insert(file.p());
582 _timestamp = time(
nullptr);
587 string dirname = filename.substr(0, slash);
588 string remainder = filename.substr(slash + 1);
589 FileBase tfile(dirname);
590 tfile.local_object();
591 Files::iterator fi = _files.find(&tfile);
592 if (fi != _files.end()) {
593 PT(FileBase) file = (*fi);
594 if (file->is_directory()) {
595 return DCAST(Directory, file.p())->do_make_directory(remainder);
606 PT(VirtualFileMountRamdisk::FileBase) VirtualFileMountRamdisk::Directory::
607 do_delete_file(
const string &filename) {
608 size_t slash = filename.find(
'/');
609 if (slash == string::npos) {
611 FileBase tfile(filename);
612 tfile.local_object();
613 Files::iterator fi = _files.find(&tfile);
614 if (fi != _files.end()) {
615 PT(FileBase) file = (*fi);
616 if (file->is_directory()) {
617 Directory *dir = DCAST(Directory, file.p());
618 if (!dir->_files.empty()) {
624 _timestamp = time(
nullptr);
631 string dirname = filename.substr(0, slash);
632 string remainder = filename.substr(slash + 1);
633 FileBase tfile(dirname);
634 tfile.local_object();
635 Files::iterator fi = _files.find(&tfile);
636 if (fi != _files.end()) {
637 PT(FileBase) file = (*fi);
638 if (file->is_directory()) {
639 return DCAST(Directory, file.p())->do_delete_file(remainder);
649 bool VirtualFileMountRamdisk::Directory::
650 do_scan_directory(vector_string &contents)
const {
651 Files::const_iterator fi;
652 for (fi = _files.begin(); fi != _files.end(); ++fi) {
653 FileBase *file = (*fi);
654 contents.push_back(file->_basename);
virtual bool atomic_compare_and_exchange_contents(const Filename &file, std::string &orig_contents, const std::string &old_contents, const std::string &new_contents)
See Filename::atomic_compare_and_exchange_contents().
virtual std::iostream * open_read_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual std::istream * open_read_file(const Filename &file) const
Opens the file for reading, if it exists.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool create_file(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
virtual bool atomic_read_contents(const Filename &file, std::string &contents) const
See Filename::atomic_read_contents().
virtual time_t get_timestamp(const Filename &file) const
Returns a time_t value that represents the time the file was last modified, to within whatever precis...
virtual bool copy_file(const Filename &orig_filename, const Filename &new_filename)
Attempts to copy the contents of the indicated file to the indicated file.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual std::ostream * open_write_file(const Filename &file, bool truncate)
Opens the file for writing.
virtual bool has_file(const Filename &file) const
Returns true if the indicated file exists within the mount system.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An istream object that presents a subwindow into another istream.
virtual bool make_directory(const Filename &file)
Attempts to create the indicated file within the mount, if it does not already exist.
The name of a file, such as a texture file or an Egg file.
virtual bool is_writable(const Filename &file) const
Returns true if the named file or directory may be written to, false otherwise.
virtual std::ostream * open_append_file(const Filename &file)
Works like open_write_file(), but the file is opened in append mode.
virtual std::iostream * open_read_append_file(const Filename &file)
Works like open_read_write_file(), but the file is opened in append mode.
virtual bool is_regular_file(const Filename &file) const
Returns true if the indicated file exists within the mount system and is a regular file.
virtual bool is_directory(const Filename &file) const
Returns true if the indicated file exists within the mount system and is a directory.
virtual std::streamsize get_file_size(const Filename &file, std::istream *stream) const
Returns the current size on disk (or wherever it is) of the already-open file.
virtual bool rename_file(const Filename &orig_filename, const Filename &new_filename)
Attempts to rename the contents of the indicated file to the indicated file.
virtual bool delete_file(const Filename &file)
Attempts to delete the indicated file or directory within the mount.
virtual bool scan_directory(vector_string &contents, const Filename &dir) const
Fills the given vector up with the list of filenames that are local to this directory,...
TypeHandle is the identifier used to differentiate C++ class types.
An ostream object that presents a subwindow into another ostream.
Combined ISubStream and OSubStream for bidirectional I/O.