当前位置: 首页>>代码示例>>C++>>正文


C++ istream::gcount方法代码示例

本文整理汇总了C++中istream::gcount方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::gcount方法的具体用法?C++ istream::gcount怎么用?C++ istream::gcount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在istream的用法示例。


在下文中一共展示了istream::gcount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: checkpoint

void Simulation::checkpoint (istream& stream, int checkpointNum) {
    util::checkpoint::header (stream);
    util::CommandLine::staticCheckpoint (stream);
    Population::staticCheckpoint (stream);
    Surveys & stream;
    
    Global::simulationTime & stream;
    Global::timeStep & stream;
    simPeriodEnd & stream;
    totalSimDuration & stream;
    phase & stream;
    (*_population) & stream;
    
    // read last, because other loads may use random numbers:
    util::random::checkpoint (stream, checkpointNum);
    
    // Check scenario.xml and checkpoint files correspond:
    int oldWUID(workUnitIdentifier);
    util::Checksum oldCksum(cksum);
    workUnitIdentifier & stream;
    cksum & stream;
    if (workUnitIdentifier != oldWUID || cksum != oldCksum)
	throw util::checkpoint_error ("mismatched checkpoint");
    
    stream.ignore (numeric_limits<streamsize>::max()-1);	// skip to end of file
    if (stream.gcount () != 0) {
	ostringstream msg;
	msg << "Checkpointing file has " << stream.gcount() << " bytes remaining." << endl;
	throw util::checkpoint_error (msg.str());
    } else if (stream.fail())
	throw util::checkpoint_error ("stream read error");
}
开发者ID:dhardy,项目名称:openmalaria,代码行数:32,代码来源:Simulation.cpp

示例2: read_page

bool OggDecoder::read_page(istream& stream, ogg_sync_state* state, ogg_page* page) {
  int ret = 0;

  // If we've hit end of file we still need to continue processing
  // any remaining pages that we've got buffered.
  if (!stream.good())
    return ogg_sync_pageout(state, page) == 1;

  while((ret = ogg_sync_pageout(state, page)) != 1) {
    // Returns a buffer that can be written too
    // with the given size. This buffer is stored
    // in the ogg synchronisation structure.
    char* buffer = ogg_sync_buffer(state, 4096);
    assert(buffer);

    // Read from the file into the buffer
    stream.read(buffer, 4096);
    int bytes = stream.gcount();
    if (bytes == 0) {
      // End of file. 
      continue;
    }

    // Update the synchronisation layer with the number
    // of bytes written to the buffer
    ret = ogg_sync_wrote(state, bytes);
    assert(ret == 0);
  }
  return true;
}
开发者ID:JamesLinus,项目名称:plogg,代码行数:30,代码来源:plogg.cpp

示例3: dynv_xml_deserialize

int dynv_xml_deserialize(struct dynvSystem* dynv_system, istream& in){
	XML_Parser p = XML_ParserCreate("UTF-8");

	XML_SetElementHandler(p, (XML_StartElementHandler)start_element_handler, (XML_EndElementHandler)end_element_handler);
	XML_SetCharacterDataHandler(p, (XML_CharacterDataHandler)character_data_handler);

	XmlCtx ctx;
	ctx.entity.push(new XmlEntity(0, dynv_system, false));

	ctx.handler_map = dynv_system_get_handler_map(dynv_system);
	XML_SetUserData(p, &ctx);

	for (;;){
		void *buffer = XML_GetBuffer(p, 4096);

		in.read((char*)buffer, 4096);
		size_t bytes_read = in.gcount();

		if (!XML_ParseBuffer(p, bytes_read, bytes_read==0)) {

		}

		if (bytes_read == 0) break;

	}

	XML_ParserFree(p);
	return 0;
}
开发者ID:peter1000,项目名称:gpick,代码行数:29,代码来源:DynvXml.cpp

示例4: binary2source

void binary2source(ostream &os,istream &is)
{
	os.setf(ios::hex,ios::basefield);

	os << '{' << endl;
	
	bool begin = true;
	while (is.good() && !is.eof())
	{
		unsigned char buffer[16];
		is.read((char *) buffer,16);
		
		int size = is.gcount();
		if (size>0 && !begin)
		{
			os << ',';
			os << endl;
		}

		begin = false;

		for (int i=0; i<size;i++)
		{
			os << "0x" << setw(2) << setfill('0') << (unsigned int)buffer[i];
			if (i<size-1)
				os << ',';
		}

	}

	os << endl << "};" << endl;
}
开发者ID:funkjunky,项目名称:Demos-and-Tutorials,代码行数:32,代码来源:text2src.cpp

示例5: run

void run(exploder & e, istream& in)
{
   // any larger, and we may try to write to a multi_frame that never has enough space
   static const int BUF_SIZE = multi_frame::MAX_SIZE - frame::FRAME_SIZE;
   scoped_array<char> buffer(new char[BUF_SIZE]);

   ios::sync_with_stdio(false); // makes a big difference on buffered i/o

   for (int line = 1; !in.eof(); ++line)
   {
      in.getline(buffer.get(), BUF_SIZE - 1); // leave 1 for us to inject back the newline
      if (buffer[0] == '\0')
         continue;
      if (in.fail()) // line was too long?
      {
         cerr << "Skipping line <" << line << ">: line is probably too long" << endl;
         in.clear(); // clear state
         in.ignore(numeric_limits<streamsize>::max(), '\n');
         continue;
      }
      buffer[in.gcount() - 1] = '\n'; // inject back the newline
      buffer[in.gcount()] = '\0';
      e << buffer.get();
   }
}
开发者ID:kyle-johnson,项目名称:spread,代码行数:25,代码来源:explode_app.cpp

示例6: transfer

streamsize cb::transfer(istream &in, ostream &out, streamsize length,
                        SmartPointer<TransferCallback> callback) {
  char buffer[BUFFER_SIZE];
  streamsize total = 0;

  while (!in.fail() && !out.fail()) {
    in.read(buffer, length ? min(length, BUFFER_SIZE) : BUFFER_SIZE);
    streamsize bytes = in.gcount();
    out.write(buffer, bytes);

    total += bytes;
    if (!callback.isNull() && !callback->transferCallback(bytes)) break;

    if (length) {
      length -= bytes;
      if (!length) break;
    }
  }

  out.flush();

  if (out.fail() || length) THROW("Transfer failed");

  return total;
}
开发者ID:kbernhagen,项目名称:cbang,代码行数:25,代码来源:Transfer.cpp

示例7: getSLine

string getSLine(istream &str)
{ char line[1024];
  str.getline(line, 1024);
  if (str.gcount()==1024-1)
    raiseError("line too long");
  return line;
}
开发者ID:electricFeel,项目名称:BeatKeeperHRM,代码行数:7,代码来源:getarg.cpp

示例8: getLineExt

//extends fstream::getline with check on exceeding the buffer size
std::streamsize getLineExt(istream& fin, char* buf)
{
    fin.getline(buf, LINE_LEN);
    std::streamsize bufLen = fin.gcount();
    if(bufLen == LINE_LEN - 1)
        throw LONG_LINE_ERR;
    return bufLen;
}
开发者ID:dariasor,项目名称:ag_predict_stream,代码行数:9,代码来源:functions.cpp

示例9: createErrorString

/**
 *  Parses the given input stream and returns a DOM Document.
 *  A NULL pointer will be returned if errors occurred
 */
nsresult
txDriver::parse(istream& aInputStream, const nsAString& aUri)
{
    mErrorString.Truncate();
    if (!aInputStream) {
        mErrorString.AppendLiteral("unable to parse xml: invalid or unopen stream encountered.");
        return NS_ERROR_FAILURE;
    }

    static const XML_Memory_Handling_Suite memsuite = {
        (void *(*)(size_t))PR_Malloc,
        (void *(*)(void *, size_t))PR_Realloc,
        PR_Free
    };
    static const PRUnichar expatSeparator = kExpatSeparatorChar;
    mExpatParser = XML_ParserCreate_MM(nsnull, &memsuite, &expatSeparator);
    if (!mExpatParser) {
        return NS_ERROR_OUT_OF_MEMORY;
    }

    XML_SetReturnNSTriplet(mExpatParser, XML_TRUE);
    XML_SetUserData(mExpatParser, this);
    XML_SetElementHandler(mExpatParser, startElement, endElement);
    XML_SetCharacterDataHandler(mExpatParser, charData);
#ifdef XML_DTD
    XML_SetParamEntityParsing(mExpatParser, XML_PARAM_ENTITY_PARSING_ALWAYS);
#endif
    XML_SetExternalEntityRefHandler(mExpatParser, externalEntityRefHandler);
    XML_SetExternalEntityRefHandlerArg(mExpatParser, this);
    XML_SetBase(mExpatParser,
                (const XML_Char*)(PromiseFlatString(aUri).get()));

    const int bufferSize = 1024;
    char buf[bufferSize];
    PRBool done;
    int success;
    mRV = NS_OK;
    do {
        aInputStream.read(buf, bufferSize);
        done = aInputStream.eof();
        success = XML_Parse(mExpatParser, buf, aInputStream.gcount(), done);
        // mRV is set in onDoneCompiling in case of an error
        if (!success || NS_FAILED(mRV)) {
            createErrorString();
            done = MB_TRUE;
        }
    } while (!done);
    aInputStream.clear();

    // clean up
    XML_ParserFree(mExpatParser);
    mCompiler->doneLoading();
    if (!success) {
        return NS_ERROR_FAILURE;
    }
    return mRV;
}
开发者ID:MozillaOnline,项目名称:gecko-dev,代码行数:61,代码来源:txStandaloneStylesheetCompiler.cpp

示例10: checkpoint_error

    void operator& (string& x, istream& stream) {
	size_t len;
	len & stream;
	validateListSize (len);
	x.resize (len);
	stream.read (&x[0], x.length());
	if (!stream || stream.gcount() != streamsize(len))
	    throw checkpoint_error ("stream read error string");
    }
开发者ID:dhardy,项目名称:openmalaria,代码行数:9,代码来源:checkpoint.cpp

示例11: read

void GLibXMLAdapter::read(istream &stream) {
  typedef void (*start_element_func_t)(GMarkupParseContext *, const gchar *,
                                       const gchar **, const gchar **,
                                       gpointer data, GError **error);
  typedef void (*end_element_func_t)(GMarkupParseContext *, const gchar *,
                                     gpointer, GError **);
  typedef void (*text_func_t)(GMarkupParseContext *, const gchar *,
                              gsize, gpointer, GError **);

  GMarkupParser parser = {
    (start_element_func_t)&GLibXMLAdapter::startElement,
    (end_element_func_t)&GLibXMLAdapter::endElement,
    (text_func_t)&GLibXMLAdapter::text,
    0, // passthrough
    0, // error
  };

  GMarkupParseContext *context =
    g_markup_parse_context_new(&parser, (GMarkupParseFlags)0, (void *)this, 0);
  if (!context) THROW("Failed to create XML parser.");

  try {
    while (!stream.eof() && !stream.fail()) {
      char buf[BUFFER_SIZE];

      stream.read(buf, BUFFER_SIZE);
      streamsize count = stream.gcount();

      GError *gerror = 0;
      if (count) {
        g_markup_parse_context_parse(context, buf, count, &gerror);

        if (error.get()) {
          Exception e(*error);
          error = 0;
          throw;
        }

        if (gerror)
          THROW("Parse failed " << g_quark_to_string(gerror->domain) << ": "
                 << gerror->code << ": " << gerror->message);
      }
    }

  } catch (const Exception &e) {
    int line;
    int column;
    g_markup_parse_context_get_position(context, &line, &column);

    g_free(context);


    throw Exception(e.getMessage(),
                    FileLocation(getFilename(), line - 1, column), e);
  }
}
开发者ID:CauldronDevelopmentLLC,项目名称:cbang,代码行数:56,代码来源:GLibXMLAdapter.cpp

示例12: readline

std::string readline(istream &is) {
    std::string out;
    char c=0;
    while (!is.eof() && c!='\n') {
	is.read(&c, 1);
	if (is.gcount())
	    out+=c;
    }
    return out;
}
开发者ID:BBBSnowball,项目名称:simulavr,代码行数:10,代码来源:helper.cpp

示例13: FrFileType

FrFILETYPE FrFileType(istream &in)
{
   char buf[BUFFER_SIZE] ;
   long pos = in.tellg() ;
   in.seekg(0) ;
   (void)in.read(buf,sizeof(buf)) ;
   FrFILETYPE type = check_type(buf,in.gcount()) ;
   in.seekg(pos) ;
   return type ;
}
开发者ID:ralfbrown,项目名称:framepac,代码行数:10,代码来源:frfilut3.C

示例14:

/**
 * Read a specified number of characters from file.
 *
 * @param aIS Input stream.
 * @param aNChar Number of characters in the description.
 * @return read string.
 */
string IO::
ReadCharacters(istream &aIS,int aNChar)
{
    char *buffer=new char[aNChar+1];
    aIS.read(buffer,aNChar);
    buffer[aIS.gcount()] = '\0';
    string str = buffer;
    delete[] buffer;
    return str;
}
开发者ID:ANKELA,项目名称:opensim-core,代码行数:17,代码来源:IO.cpp

示例15: addFile

/**
 * Add new file to ZIP container. The file is actually archived to ZIP container after <code>save()</code>
 * method is called.
 *
 * @param containerPath file path inside ZIP file.
 * @param path full path of the file that should be added to ZIP file.
 * @see create()
 * @see save()
 */
void ZipSerialize::addFile(const string& containerPath, istream &is, const Properties &prop, Flags flags)
{
    if(!d->create)
        THROW("Zip file is not open");

    DEBUG("ZipSerialize::addFile(%s)", containerPath.c_str());
    zip_fileinfo info = {
        { uInt(prop.time.tm_sec), uInt(prop.time.tm_min), uInt(prop.time.tm_hour),
          uInt(prop.time.tm_mday), uInt(prop.time.tm_mon), uInt(prop.time.tm_year) },
        0, 0, 0 };

    // Create new file inside ZIP container.
    int method = flags & DontCompress ? Z_NULL : Z_DEFLATED;
    int level = flags & DontCompress ? Z_NO_COMPRESSION : Z_DEFAULT_COMPRESSION;
    uLong UTF8_encoding = 1 << 11; // general purpose bit 11 for unicode
    int zipResult = zipOpenNewFileInZip4(d->create, containerPath.c_str(),
        &info, nullptr, 0, nullptr, 0, prop.comment.c_str(), method, level, 0,
        -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, nullptr, 0, 0, UTF8_encoding);
    if(zipResult != ZIP_OK)
        THROW("Failed to create new file inside ZIP container. ZLib error: %d", zipResult);

    is.clear();
    is.seekg(0);
    char buf[10240];
    while( is )
    {
        is.read(buf, 10240);
        if(is.gcount() <= 0)
            break;

        zipResult = zipWriteInFileInZip(d->create, buf, unsigned(is.gcount()));
        if(zipResult != ZIP_OK)
        {
            zipCloseFileInZip(d->create);
            THROW("Failed to write bytes to current file inside ZIP container. ZLib error: %d", zipResult);
        }
    }

    zipResult = zipCloseFileInZip(d->create);
    if(zipResult != ZIP_OK)
        THROW("Failed to close current file inside ZIP container. ZLib error: %d", zipResult);
}
开发者ID:open-eid,项目名称:libdigidocpp,代码行数:51,代码来源:ZipSerialize.cpp


注:本文中的istream::gcount方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。