Logger(string outFile) { fileName=outFile; std::filebuf* buf = is.rdbuf(); buf->open(fileName.c_str(),std::ios_base::out|std::ios_base::app); std::clog.rdbuf(buf); }
bool redirect_cin (const std::string& fn) { static std::ifstream alt_cin; alt_cin.open (fn.c_str(), std::ios::in | std::ios::binary); if (alt_cin.fail() ) return false; std::cin.rdbuf (alt_cin.rdbuf() ); return true; }
bool FileTemplater::appendSingleFile(std::ofstream* outputFile, const std::ifstream& inputFile) { // read input file into a string std::stringstream ss; ss << inputFile.rdbuf(); std::string str = ss.str(); // output it to file outputFile->write(str.c_str(), str.size()); return true; }
// This code reads up the file, discards the bookends, and saves only the gibberish itself. bool OTASCIIArmor::LoadFrom_ifstream(std::ifstream & fin) { std::stringstream buffer; buffer << fin.rdbuf(); std::string contents(buffer.str()); OTString theString; theString.Set(contents.c_str()); return LoadFromString(theString); }
StdHandleSaver(const char* in, const char* out) : cin(std::cin.rdbuf()), cout(std::cout.rdbuf()), cerr(std::cerr.rdbuf()), clog(std::clog.rdbuf()), csh(in, out), // NOTE: Using undocumented constructor accepting FILE* // Only constructor accepts FILE* and swap is specified since C++11, so we need to use constructor ifs(stdin), ofs(stdout) { std::cin.rdbuf(ifs.rdbuf()); std::cout.rdbuf(ofs.rdbuf()); std::cerr.rdbuf(ofs.rdbuf()); std::clog.rdbuf(ofs.rdbuf()); }
VirtualRobot::ObstaclePtr ObjectIO::loadObstacle(const std::ifstream& xmlFile, const std::string& basePath /*= ""*/) { // load file THROW_VR_EXCEPTION_IF(!xmlFile.is_open(), "Could not open XML file"); std::stringstream buffer; buffer << xmlFile.rdbuf(); std::string objectXML(buffer.str()); VirtualRobot::ObstaclePtr res = createObstacleFromString(objectXML, basePath); THROW_VR_EXCEPTION_IF(!res, "Error while parsing file."); return res; }
bool FileTemplater::appendToAllFiles(std::vector<std::ofstream*> outputFiles, const std::ifstream& inputFile) { // read input file into a string std::stringstream ss; ss << inputFile.rdbuf(); std::string str = ss.str(); // output it to file for (std::vector<std::ofstream*>::iterator it=outputFiles.begin(); it!=outputFiles.end(); ++it) { (*it)->write(str.c_str(), str.size()); } return true; }
Newick::Newick(const std::ifstream& file_stream) { if(file_stream) { // if file stream is open std::stringstream buffer; // create a buffer buffer << file_stream.rdbuf(); // and read into it if ( check_newick_format(buffer.str()) ) { // if string looks fine newick_string_m = buffer.str(); // copy the string } else { std::cout << "Newick string has the wrong format!" << std::endl; } } else { std::cout << "Could not open the file!" << std::endl; } }
void Targa::ReadRLE(std::ifstream &i) { assert(header.imageType == Header::RGBRLE); // For use loading run length encoded RGB files only assert(pixelData.size() == 0); unsigned bytesPerPixel = header.pixelSize/8; pixelData.resize( header.width * header.height * 4 ); assert(i.good()); assert(i.is_open()); int x = 0; int y = 0; std::vector<char> restOfFile(std::istreambuf_iterator<char>(i.rdbuf()), std::istreambuf_iterator<char>()); for (std::vector<char>::const_iterator itt = restOfFile.begin(); itt != restOfFile.end(); ) //for(std::istreambuf_iterator<char> itt(i.rdbuf()); itt != std::istreambuf_iterator<char>();) { const bool runLengthPacket = (*itt & 0x80) != 0; const int packetSize = 1 + (*itt & 0x7f); ++itt; if (runLengthPacket) { // get the pixel, and paste packetSize into the data const unsigned char b = *(itt++); const unsigned char g = *(itt++); const unsigned char r = *(itt++); const unsigned char a = (bytesPerPixel == 4) ? *(itt++) : 255; for (int p = 0; p < packetSize; ++p) { const int coord = x + y * 4; pixelData[ 0 + coord ] = r; pixelData[ 1 + coord ] = g; pixelData[ 2 + coord ] = b; pixelData[ 3 + coord ] = a; if (++x == header.width) { ++y; x = 0; } } } else { for (int p = 0; p < packetSize; ++p) { const unsigned char b = *(itt++); const unsigned char g = *(itt++); const unsigned char r = *(itt++); const unsigned char a = (bytesPerPixel == 4) ? *(itt++) : 255; const int coord = x + y * 4; pixelData[ 0 + coord ] = r; pixelData[ 1 + coord ] = g; pixelData[ 2 + coord ] = b; pixelData[ 3 + coord ] = a; if (++x == header.width) { ++y; x = 0; } } } } }
#include "vector_tile_util.hpp" #include "vector_tile_projection.hpp" #include "vector_tile_geometry_decoder.hpp" #include "vector_tile_datasource.hpp" #include "vector_tile_datasource_pbf.hpp" #include "protozero/pbf_reader.hpp" #include <boost/optional/optional_io.hpp> #include <fstream> TEST_CASE( "vector tile rasterize", "should try to decode windfail tile" ) { // open vtile std::ifstream stream("./test/data/0.0.0.vector.pbf",std::ios_base::in|std::ios_base::binary); REQUIRE(stream.is_open()); std::string buffer(std::istreambuf_iterator<char>(stream.rdbuf()),(std::istreambuf_iterator<char>())); REQUIRE(buffer.size() == 3812); // uncompress gzip data std::string uncompressed; mapnik::vector_tile_impl::zlib_decompress(buffer,uncompressed); REQUIRE(uncompressed.size() == 4934); typedef vector_tile::Tile tile_type; tile_type tile; unsigned tile_size = 256; mapnik::box2d<double> bbox(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789); // first we render the raw tile directly to an image { mapnik::Map map(tile_size,tile_size,"+init=epsg:3857");
/// Read the entire content of given file to string inline const std::string read_file(std::ifstream& a_in) { return static_cast<std::stringstream const&>(std::stringstream() << a_in.rdbuf()).str(); }
inline std::string readWholeFileStream(std::ifstream& fileStream) { std::stringstream stringStream; stringStream << fileStream.rdbuf(); fileStream.close(); return stringStream.str(); }
g_property_file_parser::g_property_file_parser(std::ifstream& t) { std::stringstream buffer; buffer << t.rdbuf(); initialize(buffer.str()); }
void PGPCleartextSignature::read(std::ifstream & file){ std::stringstream s; s << file.rdbuf(); std::string data = s.str(); read(data); }
std::string readFile(std::ifstream& in) { std::stringstream sstr; sstr << in.rdbuf(); return sstr.str(); }
std::string slurp(std::ifstream& in) { // file to binary string converter std::stringstream sstr; sstr << in.rdbuf(); return sstr.str(); }
std::string slurp(std::ifstream& in) { std::stringstream sstr; sstr << in.rdbuf(); return sstr.str(); }
HTML::HtmlParser::HtmlParser(const std::ifstream& file){ std::stringstream out; out<<file.rdbuf(); mHtmlTree = parseTree(out.str()); }