void CandidateMapReader::Read(const boost::filesystem::path& mapPath){ std::ifstream inputStream(mapPath.string(), std::ios::binary); cereal::BinaryInputArchive inputArchive(inputStream); inputArchive(candidatesMap); }
Message* RemoteMessagingSystem::deserialize (string data) { stringstream archivStream (data, ios_base::binary | ios_base::in); #ifdef REMOTE_XML boost::archive::xml_iarchive inputArchive( archivStream ); #else boost::archive::binary_iarchive inputArchive( archivStream ); #endif Message* msg = NULL; inputArchive >> msg; return msg; }
XmlNode LoadSave::loadFromXML(const std::string& dataFileName, const std::string& dataFileIdentifier) { XmlNode node; if(boost::filesystem::exists(dataFileName)) { toDebugLog("Loading node " + dataFileIdentifier + " from " + dataFileName); std::ifstream ifs(dataFileName.c_str()); InputArchive inputArchive(ifs); inputArchive >> node; ifs.close(); } else { throw FileException("Could not load node " + dataFileIdentifier + ", file " + dataFileName + " not found.");
int main() { std::ofstream os("out.cereal", std::ios::binary); cereal::BinaryOutputArchive archive(os); SomeData myData; MyRecord record; record.x = 5; record.y = 10; record.z = 2.5f; myData.data.insert(std::make_pair(1, record)); archive(myData); os.close(); std::ifstream is("out.cereal", std::ios::binary); cereal::BinaryInputArchive inputArchive(is); SomeData outData; inputArchive(outData); is.close(); return 0; }
Data::Bank& IQmol::parseFile(QString const& filePath) { std::ifstream ifs(filePath.toStdString().data(), std::ios_base::binary); if (ifs.is_open()) { boost::iostreams::filtering_istream filter; filter.push(boost::iostreams::gzip_decompressor()); filter.push(ifs); Data::InputArchive inputArchive(filter); m_dataBank.serialize(inputArchive); }else { QString msg("Failed to open file for read: "); msg += filePath; m_errors.append(msg); } return m_dataBank; }
bool IQmol::parseFile(QString const& filePath) { std::ifstream ifs(filePath.toStdString().data(), std::ios_base::binary); if (ifs.is_open()) { boost::iostreams::filtering_istream filter; #ifdef Q_OS_MAC // Can't get this working on Windows, or Linux filter.push(boost::iostreams::gzip_decompressor()); #endif filter.push(ifs); Data::InputArchive inputArchive(filter); m_dataBank.serialize(inputArchive); }else { QString msg("Failed to open file for read: "); msg += filePath; m_errors.append(msg); } return m_errors.isEmpty(); }
int main( int argc, char* argv[] ) { int resultCode = EXIT_SUCCESS; std::string input; std::string output; unsigned int iterations; boost::program_options::options_description description( "Allowed options" ); description.add_options() ( "help,h", "display this help" ) ( "input,i", boost::program_options::value< std::string >( &input ), "input model file" ) ( "output,o", boost::program_options::value< std::string >( &output ), "output model file" ) ( "iterations,n", boost::program_options::value< unsigned int >( &iterations ), "number of iterations" ) ; try { boost::program_options::variables_map variables; boost::program_options::store( boost::program_options::command_line_parser( argc, argv ).options( description ).run(), variables ); boost::program_options::notify( variables ); if ( variables.count( "help" ) ) { std::cout << "Optimizes the SVM problem contained in the input model file, saving the result" << std::endl << "to the output model file. Optimization will continue until the maximum number" << std::endl << "of iterations has been exceeded." << std::endl << std::endl << description << std::endl; } else { if ( ! variables.count( "input" ) ) throw std::runtime_error( "You must provide an input file" ); if ( ! variables.count( "output" ) ) throw std::runtime_error( "You must provide an output file" ); if ( ! variables.count( "iterations" ) ) throw std::runtime_error( "You must provide an iterations parameter" ); boost::shared_ptr< SVM::Optimizer::Base > pOptimizer; { std::ifstream inputFile( input.c_str(), std::ios::in | std::ios::binary ); if ( inputFile.fail() ) throw std::runtime_error( "Unable to open input file" ); boost::iostreams::filtering_streambuf< boost::iostreams::input > inputStream; inputStream.push( inputFile ); boost::archive::binary_iarchive inputArchive( inputStream ); inputArchive >> pOptimizer; } Random::Generator::LaggedFibonacci4<> generator; { Random::Generator::LinearCongruential<> seedGenerator; seedGenerator.Seed(); generator.Seed( seedGenerator ); } for ( unsigned int ii = 0; ii < iterations; ++ii ){ pOptimizer->Iterate( generator ); //std::cout << "1 IT" << std::endl; } { std::ofstream outputFile( output.c_str(), std::ios::out | std::ios::binary | std::ios::trunc ); if ( outputFile.fail() ) throw std::runtime_error( "Unable to open output file" ); boost::iostreams::filtering_streambuf< boost::iostreams::output > outputStream; outputStream.push( outputFile ); boost::archive::binary_oarchive outputArchive( outputStream ); outputArchive << pOptimizer; } pOptimizer->WriteSupport(output+"-SupportSet.txt"); } } catch( std::exception& error ) { std::cerr << "Error: " << error.what() << std::endl << std::endl << description << std::endl; resultCode = EXIT_FAILURE; } return resultCode; }
void Grammar::loadTreebankArchive() { ifstream file(archiveName.c_str()); boost::archive::xml_iarchive inputArchive(file); inputArchive & BOOST_SERIALIZATION_NVP(l2rTable); }
int main( int argc, char* argv[] ) { int resultCode = EXIT_SUCCESS; std::string input; std::string output; boost::program_options::options_description description( "Allowed options" ); description.add_options() ( "input,i", boost::program_options::value< std::string >( &input ), "input model file" ) ( "output,o", boost::program_options::value< std::string >( &output ), "output model file" ) ; try { boost::program_options::variables_map variables; boost::program_options::store( boost::program_options::command_line_parser( argc, argv ).options( description ).run(), variables ); boost::program_options::notify( variables ); if ( variables.count( "help" ) ) { std::cout << "During optimization, certain running sums are computed, which may, over time," << std::endl << "become out-of-sync with their true values. In practice, we have not found this" << std::endl << "to be a problem, but in case it pops up, this program will recalculate all of" << std::endl << "these sums from scratch." << std::endl << std::endl << description << std::endl; } else { if ( ! variables.count( "input" ) ) throw std::runtime_error( "You must provide an input file" ); if ( ! variables.count( "output" ) ) throw std::runtime_error( "You must provide an output file" ); boost::shared_ptr< SVM::Optimizer::Base > pOptimizer; { std::ifstream inputFile( input.c_str(), std::ios::in | std::ios::binary ); if ( inputFile.fail() ) throw std::runtime_error( "Unable to open input file" ); boost::iostreams::filtering_streambuf< boost::iostreams::input > inputStream; inputStream.push( inputFile ); boost::archive::binary_iarchive inputArchive( inputStream ); inputArchive >> pOptimizer; } pOptimizer->Recalculate(); { std::ofstream outputFile( output.c_str(), std::ios::out | std::ios::binary | std::ios::trunc ); if ( outputFile.fail() ) throw std::runtime_error( "Unable to open output file" ); boost::iostreams::filtering_streambuf< boost::iostreams::output > outputStream; outputStream.push( outputFile ); boost::archive::binary_oarchive outputArchive( outputStream ); outputArchive << pOptimizer; } } } catch( std::exception& error ) { std::cerr << "Error: " << error.what() << std::endl << std::endl << description << std::endl; resultCode = EXIT_FAILURE; } return resultCode; }