--- /dev/null
+// SuperTux
+// Copyright (C) 2015 Tobias Markus <tobbi@mozilla-uk.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_CPP
+#define HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_CPP
+
+#include "physfs/buffered_ifile_stream.hpp"
+
+BufferedIFileStream::BufferedIFileStream(const std::string& filename)
+{
+ buffer = new IFileStreambuf(filename);
+ stream = new IFileStream(buffer);
+}
+
+BufferedIFileStream::~BufferedIFileStream()
+{
+ delete buffer;
+ delete stream;
+ buffer = NULL;
+ stream = NULL;
+}
+
+IFileStream* BufferedIFileStream::get_stream()
+{
+ return stream;
+}
+
+#endif
+
+/* EOF */
--- /dev/null
+// SuperTux
+// Copyright (C) 2015 Tobias Markus <tobbi@mozilla-uk.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_HPP
+#define HEADER_SUPERTUX_PHYSFS_BUFFERED_IFILE_STREAM_HPP
+
+#include <ostream>
+#include <physfs.h>
+#include "physfs/ifile_stream.hpp"
+#include "physfs/ifile_streambuf.hpp"
+
+class BufferedIFileStream {
+
+private:
+ IFileStream* stream;
+ IFileStreambuf* buffer;
+
+public:
+ BufferedIFileStream(const std::string& filename);
+ ~BufferedIFileStream();
+
+ IFileStream* get_stream();
+};
+#endif
+
+/* EOF */
#include "physfs/ifile_stream.hpp"
-#include "physfs/ifile_streambuf.hpp"
-
-IFileStream::IFileStream(const std::string& filename) :
- std::istream(new IFileStreambuf(filename))
+IFileStream::IFileStream(IFileStreambuf* buf) :
+ std::istream(buf)
{
}
#include <istream>
#include <physfs.h>
+#include "physfs/ifile_streambuf.hpp"
+
class IFileStream : public std::istream
{
public:
- IFileStream(const std::string& filename);
+ IFileStream(IFileStreambuf* buf);
~IFileStream();
};
#include "physfs/physfs_file_system.hpp"
-#include "physfs/ifile_stream.hpp"
+#include "physfs/buffered_ifile_stream.hpp"
PhysFSFileSystem::PhysFSFileSystem()
{
std::unique_ptr<std::istream>
PhysFSFileSystem::open_file(const std::string& filename)
{
- return std::unique_ptr<std::istream>(new IFileStream(filename));
+ BufferedIFileStream* stream = new BufferedIFileStream(filename);
+ return std::unique_ptr<std::istream>(stream->get_stream());
}
/* EOF */
#include "math/random_generator.hpp"
#include "object/camera.hpp"
#include "object/player.hpp"
-#include "physfs/ifile_stream.hpp"
+#include "physfs/buffered_ifile_stream.hpp"
#include "supertux/fadeout.hpp"
#include "supertux/game_session.hpp"
#include "supertux/gameconfig.hpp"
void import(HSQUIRRELVM vm, const std::string& filename)
{
- IFileStream in(filename);
+ BufferedIFileStream* stream = new BufferedIFileStream(filename);
+ IFileStream* in = stream->get_stream();
if(SQ_FAILED(sq_compile(vm, squirrel_read_char, &in,
filename.c_str(), SQTrue)))
#include <stdarg.h>
#include <stdio.h>
-#include "physfs/ifile_stream.hpp"
+#include "physfs/buffered_ifile_stream.hpp"
#include "scripting/squirrel_error.hpp"
#include "scripting/wrapper.hpp"
#include "squirrel_util.hpp"
// try to load default script
try {
std::string filename = "scripts/default.nut";
- IFileStream stream(filename);
- scripting::compile_and_run(global_vm, stream, filename);
+ BufferedIFileStream* buffered_stream = new BufferedIFileStream(filename);
+ IFileStream* stream = buffered_stream->get_stream();
+ scripting::compile_and_run(global_vm, *stream, filename);
} catch(std::exception& e) {
log_warning << "Couldn't load default.nut: " << e.what() << std::endl;
}
#include <math.h>
#include <iostream>
-#include "physfs/ifile_stream.hpp"
+#include "physfs/buffered_ifile_stream.hpp"
#include "scripting/scripting.hpp"
#include "scripting/squirrel_util.hpp"
#include "supertux/gameconfig.hpp"
try {
std::string filename = "scripts/console.nut";
- IFileStream stream(filename);
- scripting::compile_and_run(m_vm, stream, filename);
+ BufferedIFileStream* buffered_stream = new BufferedIFileStream(filename);
+ IFileStream* stream = buffered_stream->get_stream();
+ scripting::compile_and_run(m_vm, *stream, filename);
} catch(std::exception& e) {
log_warning << "Couldn't load console.nut: " << e.what() << std::endl;
}