Commit 98963233 authored by twanvl's avatar twanvl

Replace shared_ptr<OutputStream> in Writer class with a regular reference, the...

Replace shared_ptr<OutputStream> in Writer class with a regular reference, the thing that calls writer can take care of the lifetime of the stream.
parent b7784d43
......@@ -321,7 +321,7 @@ void ApprDistroDatabase::doRead(InputStream& in) {
}
}
void ApprDistroDatabase::doWrite(OutputStream& out) {
void ApprDistroDatabase::doWrite(wxOutputStream& out) {
wxTextOutputStream tout(out, wxEOL_DOS);
// write in order
FOR_EACH(c, order) {
......
......@@ -23,11 +23,13 @@
/// Serialize an object to a string, clipboard_package will be set to the given package.
template <typename T>
String serialize_for_clipboard(Package& package, T& object) {
shared_ptr<wxStringOutputStream> stream( new wxStringOutputStream );
Writer writer(stream, file_version_clipboard);
WITH_DYNAMIC_ARG(clipboard_package, &package);
writer.handle(object);
return stream->GetString();
wxStringOutputStream stream;
{
Writer writer(stream, file_version_clipboard);
WITH_DYNAMIC_ARG(clipboard_package, &package);
writer.handle(object);
}
return stream.GetString();
}
template <typename T>
......
......@@ -221,8 +221,11 @@ void Set::reflect_cards<Writer> (Writer& reflector) {
// writeFile won't quite work because we'd need
// include file: card: filename
// to do that
Writer writer(openOut(full_name), app_version);
writer.handle(_("card"), card);
{
OutputStreamP stream = openOut(full_name);
Writer writer(*stream, app_version);
writer.handle(_("card"), card);
}
referenceFile(full_name);
REFLECT_N("include_file", full_name);
}
......
......@@ -303,6 +303,7 @@ void Settings::read() {
}
void Settings::write() {
Writer writer(shared(new wxFileOutputStream(settingsFile())), app_version);
wxFileOutputStream stream(settingsFile());
Writer writer(stream, app_version);
writer.handle(*this);
}
......@@ -239,7 +239,8 @@ void SymbolWindow::onFileSaveAs(wxCommandEvent& ev) {
String name = wxFileSelector(_("Save symbol"),settings.default_set_dir,_(""),_(""),_("Symbol files (*.mse-symbol)|*.mse-symbol"),wxSAVE, this);
if (!name.empty()) {
settings.default_set_dir = wxPathOnly(name);
Writer writer(shared(new wxFileOutputStream(name)), file_version_symbol);
wxFileOutputStream stream(name);
Writer writer(stream, file_version_symbol);
writer.handle(control->getSymbol());
}
}
......@@ -249,7 +250,8 @@ void SymbolWindow::onFileStore(wxCommandEvent& ev) {
SymbolValueP value = static_pointer_cast<SymbolValue>(performer->value);
Package& package = performer->getLocalPackage();
FileName new_filename = package.newFileName(value->field().name,_(".mse-symbol")); // a new unique name in the package
Writer writer(package.openOut(new_filename), file_version_symbol);
OutputStreamP stream = package.openOut(new_filename);
Writer writer(*stream, file_version_symbol);
writer.handle(control->getSymbol());
performer->addAction(value_action(value, new_filename));
}
......
......@@ -26,6 +26,10 @@ DECLARE_DYNAMIC_ARG(Package*, writing_package);
/// The package that is being put onto/read from the clipboard
DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
typedef shared_ptr<wxOutputStream> OutputStreamP;
// ----------------------------------------------------------------------------- : Package
/// A package is a container for files. On disk it is either a directory or a zip file.
......@@ -141,7 +145,8 @@ class Package : public IntrusivePtrVirtualBase {
template <typename T>
void writeFile(const String& file, const T& obj, Version file_version) {
Writer writer(openOut(file), file_version);
OutputStreamP stream = openOut(file);
Writer writer(*stream, file_version);
writer.handle(obj);
}
......
......@@ -348,7 +348,8 @@ void PackageDirectory::loadDatabase() {
}
void PackageDirectory::saveDatabase() {
Writer writer(shared(new wxFileOutputStream(databaseFile())), app_version);
wxFileOutputStream stream(databaseFile());
Writer writer(stream, app_version);
writer.handle(*this);
}
String PackageDirectory::databaseFile() {
......
......@@ -17,9 +17,9 @@ using boost::tribool;
// ----------------------------------------------------------------------------- : Writer
Writer::Writer(const OutputStreamP& output, Version file_app_version)
Writer::Writer(wxOutputStream& output, Version file_app_version)
: indentation(0)
, output(output), stream(*output)
, stream(output)
{
stream.WriteString(BYTE_ORDER_MARK);
handle(_("mse_version"), file_app_version);
......
......@@ -19,14 +19,11 @@ DECLARE_POINTER_TYPE(StyleSheet);
// ----------------------------------------------------------------------------- : Writer
typedef wxOutputStream OutputStream;
typedef shared_ptr<wxOutputStream> OutputStreamP;
/// The Writer can be used for writing (serializing) objects
class Writer {
public:
/// Construct a writer that writes to the given output stream
Writer(const OutputStreamP& output, Version file_app_version);
Writer(wxOutputStream& output, Version file_app_version);
/// Tell the reflection code we are not reading
inline bool isReading() const { return false; }
......@@ -79,9 +76,7 @@ class Writer {
/// Blocks opened to which nothing has been written
vector<const Char*> pending_opened;
/// Output stream we are writing to
OutputStreamP output;
/// Text stream wrapping the output stream
/// Text stream wrapping the output stream we are writing to
wxTextOutputStream stream;
// --------------------------------------------------- : Writing to the stream
......
......@@ -52,8 +52,6 @@ typedef wxDC DC;
typedef wxDateTime DateTime;
typedef wxOutputStream OutputStream;
// ----------------------------------------------------------------------------- : Compatability fixes
#if wxVERSION_NUMBER < 2805
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment