stockpiles: remove dependency on full protobuf

develop
Casey Link 2014-11-27 14:23:54 +01:00
parent de919050b1
commit d352d0f42d
1 changed files with 13 additions and 39 deletions

@ -41,7 +41,6 @@
// protobuf
#include "proto/stockpiles.pb.h"
#include <google/protobuf/text_format.h>
// os
#include <sys/stat.h>
@ -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 <string> & 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 <string> & 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] != '-' )