Ejemplo n.º 1
0
void BinaryRecord::read(std::istream &in) throw(Core::StreamException) {
	BinaryArchive ar(in.rdbuf(), true);
	ar & NAMED_OBJECT("GenericRecord", *this);
	// Setting the eof bit causes the input to abort the reading
	if ( in.rdbuf()->sgetc() == EOF )
		in.setstate(std::ios_base::eofbit);
}
Ejemplo n.º 2
0
bool equal_streams(std::istream& s1, std::istream& s2)
{
    typedef std::istreambuf_iterator<char, std::char_traits<char> > iterator;
    iterator begin1(s1.rdbuf());
    iterator begin2(s2.rdbuf());
    iterator end;
    
    for(; begin1 != end && begin2 != end; ++begin1, ++begin2)
        if(*begin1 != *begin2)
            return false;
            
    return begin1 == end && begin2 == end;
}
Ejemplo n.º 3
0
Reference<Bitmap> StreamerSDL::loadBitmap(std::istream & input) {
	// Save the bitmap to a file temporarily.
	static TemporaryDirectory tempDir("StreamerSDL");

	FileName fileName(tempDir.getPath());
	do {
		fileName.setFile(StringUtils::createRandomString(16) + ".bmp");
	} while(FileUtils::isFile(fileName));

	std::ofstream fileOutput(fileName.getPath().c_str(), std::ios_base::binary);
	if(!fileOutput.good()) {
		fileOutput.close();
		FileUtils::remove(fileName);
		return nullptr;
	}
	fileOutput << input.rdbuf();
	fileOutput.close();

	SDL_Surface * surface = SDL_LoadBMP(fileName.getPath().c_str());
	if (surface == nullptr) {
		FileUtils::remove(fileName);
		return nullptr;
	}
	auto bitmap = BitmapUtils::createBitmapFromSDLSurface(surface);
	SDL_FreeSurface(surface);

	FileUtils::remove(fileName);

	return bitmap;
}
Ejemplo n.º 4
0
std::string ImageCoder::storeStreamToTempFile(std::istream & stream)
{
	std::string fileName;
	{
		char fileNameBuffer[L_tmpnam];
		char * result = tmpnam(fileNameBuffer);
		if (result == nullptr)
			return fileName;	// empty file name indicates a problem ...
		fileName.assign(result);
	}

	std::ofstream file(fileName, std::ofstream::binary);
	if (file.fail())
		std::runtime_error("failed to create temp file: '" + fileName + "'");

	try
	{
		file << stream.rdbuf();
		if (file.fail() || stream.fail())
			std::runtime_error("failed to write to temp file: '" + fileName + "'");
	}
	catch (const std::iostream::failure &)
	{
		std::runtime_error("failed to write to temp file: '" + fileName + "', caught failure");
	}
	return fileName;
}
Ejemplo n.º 5
0
gzistream::gzistream( std::istream & src,
                      unsigned int buffer_size )
    : std::istream( static_cast< std::streambuf * >( 0 ) )
    , M_gzstreambuf( *(src.rdbuf()), buffer_size )
{
    this->init( &M_gzstreambuf );
}
Ejemplo n.º 6
0
void bear::visual::shader_program::restore( std::istream& fragment )
{
  std::ostringstream oss;
  oss << fragment.rdbuf();

  restore( oss.str(), detail::get_default_vertex_shader_code() );
}
Ejemplo n.º 7
0
        virtual ReadResult readShader(std::istream& fin,const Options* options) const
        {
            // create shader
            osg::ref_ptr<osg::Shader> shader = new osg::Shader();

            {
                std::stringstream ss;
                ss << fin.rdbuf();
                shader->setShaderSource( ss.str() );
            }

            // check options which can define the type of the shader program
            if (options)
            {
                if (options->getOptionString().find("fragment")!=std::string::npos) shader->setType(osg::Shader::FRAGMENT);
                if (options->getOptionString().find("vertex")!=std::string::npos) shader->setType(osg::Shader::VERTEX);
                if (options->getOptionString().find("geometry")!=std::string::npos) shader->setType(osg::Shader::GEOMETRY);
                if (options->getOptionString().find("tesscontrol")!=std::string::npos) shader->setType(osg::Shader::TESSCONTROL);
                if (options->getOptionString().find("tessevaluation")!=std::string::npos) shader->setType(osg::Shader::TESSEVALUATION);
                if (options->getOptionString().find("compute")!=std::string::npos) shader->setType(osg::Shader::COMPUTE);
            }

            // return valid shader
            return processIncludes( shader.get(), options );
        }
Ejemplo n.º 8
0
void entropy_decoder_kernel_2::
set_stream (
    std::istream& in_
)
{
    r        = 0;
    low      = initial_low;
    high     = initial_high;
    target   = 0x00000000;

    in = &in_;
    streambuf = in_.rdbuf();



    unsigned char ch;

    
    streambuf->sgetn((char*)&ch,1);
    target = ch;
    
    target <<= 8;
    if (streambuf->sgetn((char*)&ch,1))
        target += ch;


    target <<= 8;
    if (streambuf->sgetn((char*)&ch,1))
        target += ch;


    target <<= 8;
    if (streambuf->sgetn((char*)&ch,1))
        target += ch;
}
Ejemplo n.º 9
0
Item ItemFactoryImpl::createBase64Binary(std::istream& aEncodedStream)
{
  std::ostringstream oss;
  oss << aEncodedStream.rdbuf();
  std::string const temp( oss.str() );
  return createBase64Binary( temp.data(), temp.size(), true );
}
Ejemplo n.º 10
0
// virtual
S32 LLSDJSONParser::doParse(std::istream& istr, LLSD& data) const
{
	// Read into string buffer first
	//
	std::stringstream my_buf;
	my_buf << istr.rdbuf();
	std::string str_buf = my_buf.str();
	std::cout << "GoogleDetectResponder: " << str_buf.c_str() << std::endl;
	//
	S32 object_count = 0;
	//
	try
	{
		variant_t	var = json::parse( str_buf.begin(), str_buf.end() );
		object_t	obj = boost::any_cast<object_t>(*var);
		//
		object_count = parseObject( obj, data );
	}
	catch( const std::exception& x )
	{
		std::cout << "caught exception: " << x.what() << std::endl;
	}

	return object_count;
}
Ejemplo n.º 11
0
bool CPlayList::LoadData(std::istream &stream)
{
  // try to read as a string
  std::ostringstream ostr;
  ostr << stream.rdbuf();
  return LoadData(ostr.str());
}
Ejemplo n.º 12
0
void InputProvider::addStreamInput(std::istream& i, const std::string& contentname)
{
    // read the input before adding it to pimpl->stream (otherwise empty input seems to make the overall stream corrupt)
    std::stringstream inp;
    inp << i.rdbuf();
    pimpl->stream << inp.str();
    pimpl->contentNames.push_back(contentname);
}
Ejemplo n.º 13
0
void ConstraintParametersLexerBase::switchStream__(std::istream &in, size_t lineNr)
{
    d_input.close();
    d_state = 0;
    d_input = Input(new std::istream(in.rdbuf()), lineNr);
    d_sawEOF = false;
    d_atBOL = true;
}
Ejemplo n.º 14
0
void
CodeCache::InstallLibrary(const std::string& name, std::istream& istr)
{
  //BERRY_INFO << "Installing library " << name << " to " << this->GetPathForLibrary(name).toString() << std::endl;
  std::ofstream ostr(this->GetPathForLibrary(name).toString().c_str(), std::ios::binary | std::ios::trunc);

  ostr << istr.rdbuf();
}
Ejemplo n.º 15
0
std::string getDataFromIStream(std::istream& stream) {
    std::stringstream data;
    data << stream.rdbuf();

    stream.clear();

    return data.str();
}
Ejemplo n.º 16
0
 void tokenizer_kernel_1::
 set_stream (
     std::istream& in_
 )
 {
     in = &in_;
     streambuf = in_.rdbuf();
     have_peeked = false;
 }
ZipInputStream::ZipInputStream( std::istream &is, std::streampos pos )
    : std::istream( 0 ),
// SGIs basic_ifstream calls istream with 0, but calls basic_ios constructor first??
      ifs( 0 )
{
    izf = new ZipInputStreambuf( is.rdbuf(), pos ) ;
//  this->rdbuf( izf ) ; is replaced by:
    this->init( izf ) ;
}
Ejemplo n.º 18
0
/*!

*/
gzifilterstream::gzifilterstream( std::istream & src,
                                  int level,
                                  std::size_t buf_size )
    : std::istream( static_cast< std::streambuf * >( 0 ) )
    , M_filter_buf( *(src.rdbuf()), level, buf_size )
{
    // std::basic_ios::init( basic_streambuf<charT,traits>* sb );
    this->init( &M_filter_buf );
}
Ejemplo n.º 19
0
void bash_ast::read_script(const std::istream& source, bool trim)
{
  std::stringstream stream;
  stream << source.rdbuf();
  script = stream.str();
  boost::algorithm::erase_all(script, "\\\n");
  if(trim)
    boost::trim_if(script, boost::is_any_of(" \t\n"));
}
Ejemplo n.º 20
0
bool OSGA_Archive::open(std::istream& fin)
{
    SERIALIZER();

    _archiveFileName = "";

    OSG_NOTICE<<"OSGA_Archive::open"<<std::endl;
    static_cast<std::istream&>(_input).rdbuf(fin.rdbuf());
    return _open(_input);
}
Ejemplo n.º 21
0
    void set(std::istream& in, std::ostream& out, std::ostream& err) {
      if (not activated) {
	using namespace std;
	in_buf = cin.rdbuf(); out_buf = cout.rdbuf(); err_buf = cerr.rdbuf();
	in_state = cin.rdstate(); out_state = cin.rdstate(); err_state = cerr.rdstate();
	cin.rdbuf(in.rdbuf()); cout.rdbuf(out.rdbuf()); cerr.rdbuf(err.rdbuf());
	cin.exceptions(ios_base::goodbit); cout.exceptions(ios_base::goodbit); cerr.exceptions(ios_base::goodbit);
	cin.clear(in.rdstate()); cout.clear(out.rdstate()); cerr.clear(err.rdstate());
      }
    }
Ejemplo n.º 22
0
 portable_binary_iarchive(std::istream & is, unsigned flags = 0) :
     primitive_base_t(
         * is.rdbuf(), 
         0 != (flags & boost::archive::no_codecvt)
     ),
     archive_base_t(flags),
     m_flags(0)
 {
     init(flags);
 }
Ejemplo n.º 23
0
bool enigma::writeToZip(std::ostream &zipStream, std::string filename, unsigned size, std::istream &contents) {
    ZipOutputStreambuf zos(zipStream.rdbuf());
    ZipCDirEntry ze(filename);
    ze.setSize(size);
    ze.setTime(time(NULL));  // seems not to be implemented in zipios !
    zos.putNextEntry(ze);
    std::ostream ozs( &zos );
    ozs << contents.rdbuf();
    return true;
}
Ejemplo n.º 24
0
IniFilePtr IniFile::ConstructFromStream(std::istream& stream)
{
  // Read the whole stream into a string
  std::string buffer;
  std::ostringstream ors;
  ors << stream.rdbuf();
  buffer = ors.str();
    
  return ConstructFromString(buffer);
}
Ejemplo n.º 25
0
void load_file(std::string& s, std::istream& is)
{
   s.erase();
   if(is.bad()) return;
   s.reserve(static_cast<std::string::size_type>(is.rdbuf()->in_avail()));
   char c;
   while(is.get(c))
   {
      if(s.capacity() == s.size())
         s.reserve(s.capacity() * 3);
      s.append(1, c);
   }
}
Ejemplo n.º 26
0
bool parseFromStream(
    CharReader::Factory const& fact, std::istream& sin,
    Value* root, std::string* errs)
{
  std::ostringstream ssin;
  ssin << sin.rdbuf();
  std::string doc = ssin.str();
  char const* begin = doc.data();
  char const* end = begin + doc.size();
  // Note that we do not actually need a null-terminator.
  CharReaderPtr const reader(fact.newCharReader());
  return reader->parse(begin, end, root, errs);
}
Ejemplo n.º 27
0
	void MemoryTriplet::fromStream(std::istream &is) {

		KLVStream kis(is.rdbuf());

		this->key = kis.readAUID();

		size_t len = kis.readBERLength();

		value.resize(len);

		kis.readBytes(this->value.data(), value.size());

	}
intermediate_type parse_intermediate(std::istream &stream) {
	std::shared_ptr<spv_context_t> context(
		spvContextCreate(SPV_ENV_VULKAN_1_0), spvContextDestroy);
	assert(context);

	const std::string content(std::istreambuf_iterator<char>(stream.rdbuf()),
			std::istreambuf_iterator<char>());
	intermediate_type intermediate;
	spv_diagnostic diagnostic;
	spvBinaryParse(context.get(), &intermediate, (uint32_t *) content.c_str(),
			content.size() / sizeof(uint32_t), &parsed_header, &parsed_instruction, &diagnostic);
	return intermediate;
}
Ejemplo n.º 29
0
void property_tree::from_unknown( std::istream& stream, boost::property_tree::ptree& ptree, property_tree::path_value::check_repeated_paths check_type, char equal_sign, char delimiter, bool use_index )
{
    if( is_seekable( stream ) )
    {
        from_unknown_seekable( stream, ptree, check_type, equal_sign, delimiter, use_index );
    }
    else
    {
        std::stringstream buffer;
        buffer << stream.rdbuf();
        from_unknown_seekable( buffer, ptree, check_type, equal_sign, delimiter, use_index );
    }
}
Ejemplo n.º 30
0
void istream_or_ifstream::open(std::istream& is, const std::string& is_name, const std::string& filename, const std::string& description)
{
  if (buf)
    throw myexception()<<"Cannot reopen file!\n";

  if (filename == is_name)
    this->init(is.rdbuf());
  else
  {
    buf = claim(new checked_filebuf(description));
    this->init(buf.get());
    buf->open(filename, ios_base::in);
  }
}