From d352d0f42db60084f3ab0e230277621ca6d50790 Mon Sep 17 00:00:00 2001 From: Casey Link Date: Thu, 27 Nov 2014 14:23:54 +0100 Subject: [PATCH] stockpiles: remove dependency on full protobuf --- plugins/stockpiles.cpp | 52 +++++++++++------------------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/plugins/stockpiles.cpp b/plugins/stockpiles.cpp index f9f54a717..9996d5d1c 100644 --- a/plugins/stockpiles.cpp +++ b/plugins/stockpiles.cpp @@ -41,7 +41,6 @@ // protobuf #include "proto/stockpiles.pb.h" -#include // os #include @@ -476,20 +475,6 @@ public: return mBuffer.SerializeToOstream ( &output ); } - /** - * Serializes the stockpile settings to a string. - * @return empty string on error - */ - std::string serialize_to_string() - { - mBuffer.Clear(); - write(); - std::string str; - if ( !TextFormat::PrintToString ( mBuffer, &str ) ) - return std::string(); - return str; - } - /** * Read stockpile settings from file */ @@ -502,15 +487,6 @@ public: return res; } - /** - * Read text_format stockpile settings from string - */ - bool unserialize_from_string ( const std::string & data ) - { - mBuffer.Clear(); - return TextFormat::ParseFromString ( data, &mBuffer ); - } - private: bool mDebug; @@ -2762,23 +2738,21 @@ static command_result savestock ( color_ostream &out, vector & paramete file = o; } } + if ( file.empty() ) + { + out.printerr("You must supply a valid filename.\n"); + return CR_WRONG_USAGE; + } StockpileSerializer cereal ( sp ); if ( debug ) cereal.enable_debug ( out ); - if ( file.empty() ) - { - std::string data = cereal.serialize_to_string(); - out << data << endl; - } - else + + if ( !is_dfstockfile ( file ) ) file += ".dfstock"; + if ( !cereal.serialize_to_file ( file ) ) { - if ( !is_dfstockfile ( file ) ) file += ".dfstock"; - if ( !cereal.serialize_to_file ( file ) ) - { - out.printerr ( "serialize failed\n" ); - return CR_FAILURE; - } + out.printerr ( "serialize failed\n" ); + return CR_FAILURE; } return CR_OK; } @@ -2802,9 +2776,9 @@ static command_result loadstock ( color_ostream &out, vector & paramete bool debug = false; std::string file; - for( size_t i = 0; i < parameters.size(); ++i ) - { - const std::string o = parameters.at(i); + for( size_t i = 0; i < parameters.size(); ++i ) + { + const std::string o = parameters.at(i); if ( o == "--debug" || o == "-d" ) debug = true; else if ( !o.empty() && o[0] != '-' )