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