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


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

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


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

示例1: readString

	void Value::readString(std::istream &input, std::string &result) {
		bool noErrors = true, noUnicodeError = true;
		char currentCharacter, tmpCharacter;
		std::stringstream constructing;
		std::string tmpStr(4, ' ');
		std::stringstream tmpSs;
		int32_t tmpInt;
		String32 tmpStr32;
		unsigned int tmpCounter;

		// As long as there aren't any errors and that we haven't reached the
		// end of the input stream.
		while (noErrors && !input.eof()) {
			input.get(currentCharacter);

			if (input.good()) {
				if (currentCharacter & 0x80) { // 0x80 --> 10000000
					// The character is part of an utf8 character.
					constructing << currentCharacter;

				} else if (currentCharacter == Strings::Json::Escape::BEGIN_ESCAPE) {
					if (!input.eof()) {
						input.get(tmpCharacter);

						switch (tmpCharacter) {
						case Strings::Json::Escape::QUOTATION_MARK:
							constructing << Strings::Std::QUOTATION_MARK;
							break;

						case Strings::Json::Escape::REVERSE_SOLIDUS:
							constructing << Strings::Std::REVERSE_SOLIDUS;
							break;

						case Strings::Json::Escape::SOLIDUS:
							constructing << Strings::Std::SOLIDUS;
							break;

						case Strings::Json::Escape::BACKSPACE:
							constructing << Strings::Std::BACKSPACE;
							break;

						case Strings::Json::Escape::FORM_FEED:
							constructing << Strings::Std::FORM_FEED;
							break;

						case Strings::Json::Escape::LINE_FEED:
							constructing << Strings::Std::LINE_FEED;
							break;

						case Strings::Json::Escape::CARRIAGE_RETURN:
							constructing << Strings::Std::CARRIAGE_RETURN;
							break;

						case Strings::Json::Escape::TAB:
							constructing << Strings::Std::TAB;
							break;

						case Strings::Json::Escape::BEGIN_UNICODE:
							// TODO: Check for utf16 surrogate pairs.
							tmpCounter = 0;
							tmpStr.clear();
							tmpStr = "    ";
							noUnicodeError = true;

							while (tmpCounter < 4 && !input.eof()) {
								input.get(tmpCharacter);

								if (isHexDigit(tmpCharacter)) {
									tmpStr[tmpCounter] = tmpCharacter;

								} else {
									noUnicodeError = false;
									std::cout << "Invalid \\u character, skipping it." << std::endl;
								}

								++tmpCounter;
							}

							if (noUnicodeError) {
								tmpSs.clear();
								tmpSs.str("");
								tmpSs << std::hex << tmpStr;
								tmpSs >> tmpInt;
								tmpStr32.clear();
								tmpStr32.push_back(tmpInt);
								tmpStr = Convert::encodeToUTF8(tmpStr32);
								constructing << tmpStr;
							}

							break;

						default:
							break;
						}
					}

				} else if (currentCharacter == '"') {
					result = constructing.str();
					noErrors = false;

//.........这里部分代码省略.........
开发者ID:vitordossantos,项目名称:programa-estagio-vendas-descontos,代码行数:101,代码来源:Value.cpp

示例2: read_unv_implementation

void MeshData::read_unv_implementation (std::istream & in_file)
{
  /*
   * This is the actual implementation of
   * reading in UNV format.  This enables
   * to read either through the conventional
   * C++ stream, or through a stream that
   * allows to read .gz'ed files.
   */
  if ( !in_file.good() )
    libmesh_error_msg("ERROR: Input file not good.");

  const std::string _label_dataset_mesh_data = "2414";

  /*
   * locate the beginning of data set
   * and read it.
   */
  {
    std::string olds, news;

    while (true)
      {
        in_file >> olds >> news;

        /*
         * Yes, really dirty:
         *
         * When we found a dataset, and the user does
         * not want this dataset, we jump back here
         */
      go_and_find_the_next_dataset:

        /*
         * a "-1" followed by a number means the beginning of a dataset
         * stop combing at the end of the file
         */
        while( ((olds != "-1") || (news == "-1") ) && !in_file.eof() )
          {
            olds = news;
            in_file >> news;
          }

        if(in_file.eof())
          break;

        /*
         * if beginning of dataset
         */
        if (news == _label_dataset_mesh_data)
          {

            /*
             * Now read the data of interest.
             * Start with the header.  For
             * explanation of the variable
             * dataset_location, see below.
             */
            unsigned int dataset_location;

            /*
             * the type of data (complex, real,
             * float, double etc, see below)
             */
            unsigned int data_type;

            /*
             * the number of floating-point values per entity
             */
            unsigned int NVALDC;


            /*
             * If there is no MeshDataUnvHeader object
             * attached
             */
            if (_unv_header == libmesh_nullptr)
              {
                /*
                 * Ignore the first lines that stand for
                 * analysis dataset label and name.
                 */
                for(unsigned int i=0; i<3; i++)
                  in_file.ignore(256,'\n');

                /*
                 * Read the dataset location, where
                 * 1: Data at nodes
                 * 2: Data on elements
                 * other sets are currently not supported.
                 */
                in_file >> dataset_location;

                /*
                 * Ignore five ID lines.
                 */
                for(unsigned int i=0; i<6; i++)
                  in_file.ignore(256,'\n');

                /*
//.........这里部分代码省略.........
开发者ID:YSB330,项目名称:libmesh,代码行数:101,代码来源:mesh_data_unv_support.C

示例3: importLegacyStream

// virtual
BOOL LLInventoryCategory::importLegacyStream(std::istream& input_stream)
{
	// *NOTE: Changing the buffer size will require changing the scanf
	// calls below.
	char buffer[MAX_STRING];	/* Flawfinder: ignore */
	char keyword[MAX_STRING];	/* Flawfinder: ignore */
	char valuestr[MAX_STRING];	/* Flawfinder: ignore */

	keyword[0] = '\0';
	valuestr[0] = '\0';
	while(input_stream.good())
	{
		input_stream.getline(buffer, MAX_STRING);
		sscanf(	/* Flawfinder: ignore */
			buffer,
			" %254s %254s",
			keyword, valuestr);
		if(0 == strcmp("{",keyword))
		{
			continue;
		}
		if(0 == strcmp("}", keyword))
		{
			break;
		}
		else if(0 == strcmp("cat_id", keyword))
		{
			mUUID.set(valuestr);
		}
		else if(0 == strcmp("parent_id", keyword))
		{
			mParentUUID.set(valuestr);
		}
		else if(0 == strcmp("type", keyword))
		{
			mType = LLAssetType::lookup(valuestr);
		}
		else if(0 == strcmp("pref_type", keyword))
		{
			mPreferredType = LLFolderType::lookup(valuestr);
		}
		else if(0 == strcmp("name", keyword))
		{
			//strcpy(valuestr, buffer + strlen(keyword) + 3);
			// *NOTE: Not ANSI C, but widely supported.
			sscanf(	/* Flawfinder: ignore */
				buffer,
				" %254s %254[^|]",
				keyword, valuestr);
			mName.assign(valuestr);
			LLStringUtil::replaceNonstandardASCII(mName, ' ');
			LLStringUtil::replaceChar(mName, '|', ' ');
		}
		else
		{
			llwarns << "unknown keyword '" << keyword
					<< "' in inventory import category "  << mUUID << llendl;
		}
	}
	return TRUE;
}
开发者ID:jimjesus,项目名称:kittyviewer,代码行数:62,代码来源:llinventory.cpp

示例4: LLSD

S32 LLSDXMLParser::Impl::parseLines(std::istream& input, LLSD& data)
{
	XML_Status status = XML_STATUS_OK;

	data = LLSD();

	static const int BUFFER_SIZE = 1024;

	//static char last_buffer[ BUFFER_SIZE ];
	//std::streamsize last_num_read;

	// Must get rid of any leading \n, otherwise the stream gets into an error/eof state
	clear_eol(input);

	while( !mGracefullStop
		&& input.good() 
		&& !input.eof())
	{
		void* buffer = XML_GetBuffer(mParser, BUFFER_SIZE);
		/*
		 * If we happened to end our last buffer right at the end of the llsd, but the
		 * stream is still going we will get a null buffer here.  Check for mGracefullStop.
		 * -- I don't think this is actually true - zero 2008-05-09
		 */
		if (!buffer)
		{
			break;
		}
		
		// Get one line
		input.getline((char*)buffer, BUFFER_SIZE);
		std::streamsize num_read = input.gcount();

		//memcpy( last_buffer, buffer, num_read );
		//last_num_read = num_read;

		if ( num_read > 0 )
		{
			if (!input.good() )
			{	// Clear state that's set when we run out of buffer
				input.clear();
			}
		
			// Re-insert with the \n that was absorbed by getline()
			char * text = (char *) buffer;
			if ( text[num_read - 1] == 0)
			{
				text[num_read - 1] = '\n';
			}
		}

		status = XML_ParseBuffer(mParser, (int)num_read, false);
		if (status == XML_STATUS_ERROR)
		{
			break;
		}
	}

	if (status != XML_STATUS_ERROR
		&& !mGracefullStop)
	{	// Parse last bit
		status = XML_ParseBuffer(mParser, 0, true);
	}
	
	if (status == XML_STATUS_ERROR  
		&& !mGracefullStop)
	{
		if (mEmitErrors)
		{
		LL_INFOS() << "LLSDXMLParser::Impl::parseLines: XML_STATUS_ERROR" << LL_ENDL;
		}
		return LLSDParser::PARSE_FAILURE;
	}

	clear_eol(input);
	data = mResult;
	return mParseCount;
}
开发者ID:Belxjander,项目名称:Kirito,代码行数:78,代码来源:llsdserialize_xml.cpp

示例5: doParse

// virtual
S32 LLSDBinaryParser::doParse(std::istream& istr, LLSD& data) const
{
/**
 * Undefined: '!'<br>
 * Boolean: 't' for true 'f' for false<br>
 * Integer: 'i' + 4 bytes network byte order<br>
 * Real: 'r' + 8 bytes IEEE double<br>
 * UUID: 'u' + 16 byte unsigned integer<br>
 * String: 's' + 4 byte integer size + string<br>
 *  strings also secretly support the notation format
 * Date: 'd' + 8 byte IEEE double for seconds since epoch<br>
 * URI: 'l' + 4 byte integer size + string uri<br>
 * Binary: 'b' + 4 byte integer size + binary data<br>
 * Array: '[' + 4 byte integer size  + all values + ']'<br>
 * Map: '{' + 4 byte integer size  every(key + value) + '}'<br>
 *  map keys are serialized as s + 4 byte integer size + string or in the
 *  notation format.
 */
	char c;
	c = get(istr);
	if(!istr.good())
	{
		return 0;
	}
	S32 parse_count = 1;
	switch(c)
	{
	case '{':
	{
		S32 child_count = parseMap(istr, data);
		if((child_count == PARSE_FAILURE) || data.isUndefined())
		{
			parse_count = PARSE_FAILURE;
		}
		else
		{
			parse_count += child_count;
		}
		if(istr.fail())
		{
			llinfos << "STREAM FAILURE reading binary map." << llendl;
			parse_count = PARSE_FAILURE;
		}
		break;
	}

	case '[':
	{
		S32 child_count = parseArray(istr, data);
		if((child_count == PARSE_FAILURE) || data.isUndefined())
		{
			parse_count = PARSE_FAILURE;
		}
		else
		{
			parse_count += child_count;
		}
		if(istr.fail())
		{
			llinfos << "STREAM FAILURE reading binary array." << llendl;
			parse_count = PARSE_FAILURE;
		}
		break;
	}

	case '!':
		data.clear();
		break;

	case '0':
		data = false;
		break;

	case '1':
		data = true;
		break;

	case 'i':
	{
		U32 value_nbo = 0;
		read(istr, (char*)&value_nbo, sizeof(U32));	 /*Flawfinder: ignore*/
		data = (S32)ntohl(value_nbo);
		if(istr.fail())
		{
			llinfos << "STREAM FAILURE reading binary integer." << llendl;
		}
		break;
	}

	case 'r':
	{
		F64 real_nbo = 0.0;
		read(istr, (char*)&real_nbo, sizeof(F64));	 /*Flawfinder: ignore*/
		data = ll_ntohd(real_nbo);
		if(istr.fail())
		{
			llinfos << "STREAM FAILURE reading binary real." << llendl;
		}
		break;
//.........这里部分代码省略.........
开发者ID:Nora28,项目名称:imprudence,代码行数:101,代码来源:llsdserialize.cpp

示例6: strip_rn

 void FileMap::strip_rn( std::istream & file ) {
     while( file.good() && ( file.peek() == '\n' || file.peek() == '\r' ) )
         file.get(); // strip out all newlines and carriage returns
 }
开发者ID:Boffee,项目名称:Data-structure,代码行数:4,代码来源:filemap.cpp

示例7: buffer

std::shared_ptr< Expression> parse(std::istream& input, int& line_no, bool topLevel) {
	std::string buffer("");
	char c;
	
	while (input.good()) {
		input.get(c);
		if (whitespace(c)) {
			if (c == '\n') {
				line_no++;
			}
			if (buffer.empty()) {
				;//nothing to do
			} else {
				if (digit(buffer[0])) {
					return std::make_shared<Float>(buffer);
				} else if (doubleQuote(buffer[0])) {
					buffer += c;
				} else if (colon(buffer[0])) {
					return std::make_shared<Atom>(buffer.substr(1));
				} else if (alphanumeric(buffer[0])) {
					return std::make_shared<Identifier>(buffer);
				//} else {
				//	return new Identifier(buffer);
				}
			}
		} else if (digit(c)) {
			buffer += c;
		} else if (dot(c)) {
			if (buffer.empty()) {
				buffer += c;
			} else {
				if (digit(buffer[0])) {
					if (!dotIn(buffer)) {
						buffer += c;
					} else {
						SYNTAX_ERROR(line_no, "Second dot found in Float literal " << buffer + c );
					}
				} else {
					buffer += c;
				}
			}
		} else if (colon(c)) {
			if (buffer.empty()) {
				buffer += c;
			} else {
				SYNTAX_ERROR(line_no, "Colon found in the middle of token " << buffer + c );
			}
		} else if (doubleQuote(c)) {
			if (buffer.empty()) {
				buffer += c;
			} else {
				if (doubleQuote(buffer[0])) {
					buffer += c;
					return std::make_shared<String>(buffer);
				} else {
					SYNTAX_ERROR(line_no, "Double-quote found in the middle of token " << buffer + c );
				}
			}
		} else if (parenthenesis(c)) { //BEWARE - THE TRICKY PART //TODO refactor to smaller functions
			if (buffer.empty()) {
				if (openParenthenesis(c)) {
					std::vector< std::shared_ptr<Expression>> list;
					char c2;
					input.get(c2);
					while (!closeParenthenesis(c2)) {
						input.unget();
						std::shared_ptr<Expression> tmpExp = parse(input, line_no, false);
						if (tmpExp) {
						    list.push_back(tmpExp);
						} else {
						    input.unget();
						}
						input.get(c2);
					}
					if (!parenMatches(c, c2)) {
						SYNTAX_ERROR(line_no, "Parenthenesis " << c << " is closed by not matching paren : " << c2);
					}
					return std::make_shared<List>(list);
				} else {//closeParenthenesis(c)
					if (topLevel) {
					    SYNTAX_ERROR(line_no, "Found unmatched close parenthenesis " << c);
					} else {
					    return NULL;//oznacza, ze trzeba wyjsc
					}
				}
			} else {
				//end of some token
				//return c back to the ctream and return expression as a result
				//or possibly it was ending paren inside a string and we add it simply
                          
				if (digit(buffer[0])) {
					input.unget();
					return std::make_shared<Float>(buffer);
				} else if (doubleQuote(buffer[0])) {
					buffer += c; //no unget, cause it's inside a string literal
                                } else if (colon(buffer[0])) {
					input.unget();
					return std::make_shared<Atom>(buffer);
				} else if (alphanumeric(buffer[0])) {
					input.unget();
//.........这里部分代码省略.........
开发者ID:ajuc,项目名称:c--_lisp_sexp_parser,代码行数:101,代码来源:lispparser.cpp

示例8: read_stream

void OFFIO::read_stream(std::istream& in)
{
  // This is a serial-only process for now;
  // the Mesh should be read on processor 0 and
  // broadcast later
  libmesh_assert_equal_to (this->mesh().processor_id(), 0);

  // Get a reference to the mesh
  MeshBase& the_mesh = MeshInput<MeshBase>::mesh();

  // Clear any existing mesh data
  the_mesh.clear();

  // Check the input buffer
  libmesh_assert (in.good());

  unsigned int nn, ne, nf;

  std::string label;

  // Read the first string.  It should say "OFF"
  in >> label;

  libmesh_assert_equal_to (label, "OFF");

  // read the number of nodes, faces, and edges
  in >> nn >> nf >> ne;


  Real x=0., y=0., z=0.;

  // Read the nodes
  for (unsigned int n=0; n<nn; n++)
    {
      libmesh_assert (in.good());

      in >> x
         >> y
         >> z;

      the_mesh.add_point ( Point(x,y,z), n );
    }

  unsigned int nv, nid;

  // Read the elements
  for (unsigned int e=0; e<nf; e++)
    {
      libmesh_assert (in.good());

      // The number of vertices in the element
      in >> nv;

      libmesh_assert(nv == 2 || nv == 3);
      if (e == 0)
        {
          the_mesh.set_mesh_dimension(nv-1);
          if (nv == 3)
            {
#if LIBMESH_DIM < 2
              libmesh_error_msg("Cannot open dimension 2 mesh file when configured without 2D support.");
#endif
            }
        }

      Elem* elem;
      switch (nv)
        {
        case 2:
          elem = new Edge2;
          break;

        case 3:
          elem = new Tri3;
          break;

        default:
          libmesh_error_msg("Unsupported nv = " << nv);
        }

      elem->set_id(e);
      the_mesh.add_elem (elem);

      for (unsigned int i=0; i<nv; i++)
        {
          in >> nid;
          elem->set_node(i) = the_mesh.node_ptr(nid);
        }
    }
}
开发者ID:dongliangchu,项目名称:libmesh,代码行数:90,代码来源:off_io.C

示例9: updateConfigObject

bool Settings::updateConfigObject(std::istream &is, std::ostream &os,
	const std::string &end, u32 tab_depth)
{
	std::map<std::string, SettingsEntry>::const_iterator it;
	std::set<std::string> present_entries;
	std::string line, name, value;
	bool was_modified = false;
	bool end_found = false;

	// Add any settings that exist in the config file with the current value
	// in the object if existing
	while (is.good() && !end_found) {
		std::getline(is, line);
		SettingsParseEvent event = parseConfigObject(line, end, name, value);

		switch (event) {
		case SPE_END:
			os << line << (is.eof() ? "" : "\n");
			end_found = true;
			break;
		case SPE_MULTILINE:
			value = getMultiline(is);
			/* FALLTHROUGH */
		case SPE_KVPAIR:
			it = m_settings.find(name);
			if (it != m_settings.end() &&
				(it->second.is_group || it->second.value != value)) {
				printEntry(os, name, it->second, tab_depth);
				was_modified = true;
			} else {
				os << line << "\n";
				if (event == SPE_MULTILINE)
					os << value << "\n\"\"\"\n";
			}
			present_entries.insert(name);
			break;
		case SPE_GROUP:
			it = m_settings.find(name);
			if (it != m_settings.end() && it->second.is_group) {
				os << line << "\n";
				sanity_check(it->second.group != NULL);
				was_modified |= it->second.group->updateConfigObject(is, os,
					"}", tab_depth + 1);
			} else {
				printEntry(os, name, it->second, tab_depth);
				was_modified = true;
			}
			present_entries.insert(name);
			break;
		default:
			os << line << (is.eof() ? "" : "\n");
			break;
		}
	}

	// Add any settings in the object that don't exist in the config file yet
	for (it = m_settings.begin(); it != m_settings.end(); ++it) {
		if (present_entries.find(it->first) != present_entries.end())
			continue;

		printEntry(os, it->first, it->second, tab_depth);
		was_modified = true;
	}

	return was_modified;
}
开发者ID:EUGD,项目名称:minetest,代码行数:66,代码来源:settings.cpp

示例10: read_implementation

void UNVIO::read_implementation (std::istream& in_stream)
{
  // clear everything, so that
  // we can start from scratch
  this->clear ();

  // Keep track of what kinds of elements this file contains
  elems_of_dimension.clear();
  elems_of_dimension.resize(4, false);

  // Note that we read this file
  // @e twice.  First time to
  // detect the number of nodes
  // and elements (and possible
  // conversion tasks like D_to_e)
  // and the order of datasets
  // (nodes first, then elements,
  // or the other way around),
  // and second to do the actual
  // read.
  std::vector<std::string> order_of_datasets;
  order_of_datasets.reserve(2);

  {
    // the first time we read the file,
    // merely to obtain overall info
    if ( !in_stream.good() )
      {
        libMesh::err << "ERROR: Input file not good."
                     << std::endl;
        libmesh_error();
      }


    // Count nodes and elements, then let
    // other methods read the element and
    // node data.  Also remember which
    // dataset comes first: nodes or elements
    if (this->verbose())
      libMesh::out << "  Counting nodes and elements" << std::endl;


    //    bool reached_eof = false;
    bool found_node  = false;
    bool found_elem  = false;


    std::string olds, news;

    while (in_stream.good())
      {
        in_stream >> olds >> news;

        // a "-1" followed by a number means the beginning of a dataset
        // stop combing at the end of the file
        while ( ((olds != "-1") || (news == "-1") ) && !in_stream.eof() )
          {
            olds = news;
            in_stream >> news;
          }

        //  if (in_stream.eof())
        //    {
        //      reached_eof = true;
        //      break;
        //    }


        // if beginning of dataset, buffer it in
        // temp_buffer, if desired
        if (news == _label_dataset_nodes)
          {
            found_node = true;
            order_of_datasets.push_back (_label_dataset_nodes);
            this->count_nodes (in_stream);

            // we can save some time scanning the file
            // when we know we already have everything
            // we want
            if (found_elem)
              break;
          }

        else if (news == _label_dataset_elements)
          {
            found_elem = true;
            order_of_datasets.push_back (_label_dataset_elements);
            this->count_elements (in_stream);

            // we can save some time scanning the file
            // when we know we already have everything
            // we want
            if (found_node)
              break;
          }
      }


    // Here we should better have found
    // the datasets for nodes and elements,
//.........这里部分代码省略.........
开发者ID:bwspenc,项目名称:libmesh,代码行数:101,代码来源:unv_io.C

示例11: count_nodes

void UNVIO::count_nodes (std::istream& in_file)
{
  START_LOG("count_nodes()","UNVIO");

  // if this->_n_nodes is not 0 the dataset
  // has already been scanned
  if (this->_n_nodes != 0)
    {
      libMesh::err << "Error: Trying to scan nodes twice!"
                   << std::endl;
      libmesh_error();
    }


  // Read from file, count nodes,
  // check if floats have to be converted
  std::string data;

  in_file >> data; // read the first node label


  if (data == "-1")
    {
      libMesh::err << "ERROR: Bad, already reached end of dataset before even starting to read nodes!"
                   << std::endl;
      libmesh_error();
    }


  // ignore the misc data for this node
  in_file.ignore(256,'\n');



  // Now we are there to verify whether we need
  // to convert from D to e or not
  in_file >> data;

  // When this "data" contains a "D", then
  // we have to convert each and every float...
  // But also assume when _this_ specific
  // line does not contain a "D", then the
  // other lines won't, too.
  {
    // #ifdef __HP_aCC
    //     // Use an "int" instead of unsigned int,
    //     // otherwise HP aCC may crash!
    //     const int position          = data.find("D",6);
    // #else
    //     const unsigned int position = data.find("D",6);
    // #endif
    std::string::size_type position = data.find("D",6);

    if (position!=std::string::npos) // npos means no position
      {
        this->_need_D_to_e = true;

        if (this->verbose())
          libMesh::out << "  Convert from \"D\" to \"e\"" << std::endl;
      }
    else
      this->_need_D_to_e = false;
  }

  // read the remaining two coordinates
  in_file >> data;
  in_file >> data;


  // this was our first node
  this->_n_nodes++;



  // proceed _counting_ the remaining
  // nodes.
  while (in_file.good())
    {
      // read the node label
      in_file >> data;

      if (data == "-1")
        // end of dataset is reached
        break;

      // ignore the remaining data (coord_sys_label, color etc)
      in_file.ignore (256, '\n');
      // ignore the coordinates
      in_file.ignore (256, '\n');

      this->_n_nodes++;
    }


  if (in_file.eof())
    {
      libMesh::err << "ERROR: File ended before end of node dataset!"
                   << std::endl;
      libmesh_error();
    }
//.........这里部分代码省略.........
开发者ID:bwspenc,项目名称:libmesh,代码行数:101,代码来源:unv_io.C

示例12: loadFrom

void cPCXFile::loadFrom(std::istream & file) throw()
{
	if (!file.good())
		throw exceptions::io();

	int start_pos = (int)file.tellg();

	file.seekg(0, std::ios::end);
	int length = (int)file.tellg() - start_pos;
	file.seekg(start_pos);

	if(length < (int)sizeof(m_Header))
		throw exceptions::load_resource();

	if (!file.good())
		throw exceptions::load_resource();

	file.read((char*)&m_Header, sizeof(m_Header));

	if (file.gcount()!=sizeof(m_Header))
		throw exceptions::load_resource();

	if(m_Header.m_Bpp == 4)
	{
		file.seekg(start_pos + (int)offsetof(SPCXHeader, m_Palette));
		m_Palette.loadFrom(file, 16);
	}
	else if(m_Header.m_Bpp == 8)
	{
		if((unsigned int)length > sizeof(m_Header) + 768)
		{
			file.seekg(-769, std::ios::end);

			if (file.get() != 0xC)
				throw exceptions::load_resource();

			m_Palette.loadFrom(file);

			file.seekg(start_pos + sizeof(m_Header));
		}
		else
			throw exceptions::load_resource();
	} else
		throw exceptions::load_resource();

	m_Bitmap.create(m_Header.m_EndX - m_Header.m_StartX + 1, m_Header.m_EndY - m_Header.m_StartY + 1);

	int line_lgt = m_Header.m_BPLine * m_Header.m_Planes;
	int line_padding = (line_lgt * 8 / m_Header.m_Bpp) - m_Bitmap.width();

	if (line_lgt <= 0 || line_padding < 0)
		throw exceptions::load_resource();


	for(int i = 0; i < m_Bitmap.height(); ++i)
	{
		char runcount = 0;
		char data = 0;
		char runvalue = 0;

		for(int j = 0; j < line_lgt; j+= runcount)
		{

			if (!file.good())
				throw exceptions::load_resource();

			file.get(data);

			if (!file.good())
				throw exceptions::load_resource();

			if((data & 0xC0) == 0xC0)
			{
				runcount = data & 0x3F;
				file.get(runvalue);
				if (!file.good())
					throw exceptions::load_resource();
			}
			else
			{
				runcount = 1;
				runvalue = data;
			}

			for(int z = 0; z < runcount && j + z < m_Bitmap.width(); ++z)
				m_Bitmap.pixel(j + z, i) = runvalue;
		}
	}
}
开发者ID:DeX77,项目名称:ufo,代码行数:89,代码来源:pcxfile.cpp

示例13: loadFromStream

bool LocalizedString::loadFromStream(std::istream& in_Stream, const uint32_t subHeader,
                        const bool withHeader, uint32_t& bytesRead,
                        const bool localized, const StringTable& table,
                        char* buffer)
{
  if (withHeader)
  {
    uint32_t subRecName = 0;
    //read header
    in_Stream.read((char*) &subRecName, 4);
    bytesRead += 4;
    if (subRecName!=subHeader)
    {
      UnexpectedRecord(subHeader, subRecName);
      return false;
    }
  }//if with header

  //subrecord's length
  uint16_t subLength = 0;
  in_Stream.read((char*) &subLength, 2);
  bytesRead += 2;
  if (localized)
  {
    if (subLength!=4)
    {
      std::cout << "Error: sub record " << IntTo4Char(subHeader)
                << " has invalid length (" << subLength
                << " bytes). Should be four bytes.\n";
      return false;
    }
    //read value
    in_Stream.read((char*) &m_Index, 4);
    bytesRead += 4;
    if (!in_Stream.good())
    {
      std::cout << "LocalizedString::loadFromStream: Error while reading subrecord "
                << IntTo4Char(subHeader)<<"!\n";
      return false;
    }
    //treat index zero as empty string, some subrecords allow zero as index
    if (m_Index==0)
    {
      m_String.clear();
      m_Type = lsIndex;
      return true;
    }//if zero
    if (!table.hasString(m_Index))
    {
      std::cout << "LocalizedString::loadFromStream: table has no entry for index "<<m_Index<<"!\n";
      return false;
    }
    m_String = table.getString(m_Index);
    m_Type = lsIndex;
  }
  else
  {
    //unlocalized (plain string)
    if (subLength>511)
    {
      std::cout <<"Error: subrecord "<<IntTo4Char(subHeader)<<" is longer than 511 characters!\n";
      return false;
    }
    //read string
    memset(buffer, 0, 512);
    in_Stream.read(buffer, subLength);
    bytesRead += subLength;
    if (!in_Stream.good())
    {
      std::cout << "Error while reading subrecord "<<IntTo4Char(subHeader)<<"!\n";
      return false;
    }
    m_String = std::string(buffer);
    m_Type = lsString;
  }
  return true;
}
开发者ID:Thoronador,项目名称:morrowtools,代码行数:77,代码来源:LocalizedString.cpp

示例14: createTokens

bool TokenList::createTokens(std::istream &code, const std::string& file0)
{
    _files.push_back(file0);

    // line number in parsed code
    unsigned int lineno = 1;

    // The current token being parsed
    std::string CurrentToken;

    // lineNumbers holds line numbers for files in fileIndexes
    // every time an include file is completely parsed, last item in the vector
    // is removed and lineno is set to point to that value.
    std::stack<unsigned int> lineNumbers;

    // fileIndexes holds index for _files vector about currently parsed files
    // every time an include file is completely parsed, last item in the vector
    // is removed and FileIndex is set to point to that value.
    std::stack<unsigned int> fileIndexes;

    // FileIndex. What file in the _files vector is read now?
    unsigned int FileIndex = 0;

    bool expandedMacro = false;

    // Read one byte at a time from code and create tokens
    for (char ch = (char)code.get(); code.good(); ch = (char)code.get()) {
        if (ch == Preprocessor::macroChar) {
            while (code.peek() == Preprocessor::macroChar)
                code.get();
            ch = ' ';
            expandedMacro = true;
        } else if (ch == '\n') {
            expandedMacro = false;
        }

        // char/string..
        // multiline strings are not handled. The preprocessor should handle that for us.
        else if (ch == '\'' || ch == '\"') {
            std::string line;

            // read char
            bool special = false;
            char c = ch;
            do {
                // Append token..
                line += c;

                // Special sequence '\.'
                if (special)
                    special = false;
                else
                    special = (c == '\\');

                // Get next character
                c = (char)code.get();
            } while (code.good() && (special || c != ch));
            line += ch;

            // Handle #file "file.h"
            if (CurrentToken == "#file") {
                // Extract the filename
                line = line.substr(1, line.length() - 2);

                // Has this file been tokenized already?
                ++lineno;
                bool foundOurfile = false;
                fileIndexes.push(FileIndex);
                for (unsigned int i = 0; i < _files.size(); ++i) {
                    if (Path::sameFileName(_files[i], line)) {
                        // Use this index
                        foundOurfile = true;
                        FileIndex = i;
                    }
                }

                if (!foundOurfile) {
                    // The "_files" vector remembers what files have been tokenized..
                    _files.push_back(Path::simplifyPath(line.c_str()));
                    FileIndex = static_cast<unsigned int>(_files.size() - 1);
                }

                lineNumbers.push(lineno);
                lineno = 0;
            } else {
                // Add previous token
                addtoken(CurrentToken.c_str(), lineno, FileIndex);
                if (!CurrentToken.empty())
                    _back->setExpandedMacro(expandedMacro);

                // Add content of the string
                addtoken(line.c_str(), lineno, FileIndex);
                if (!line.empty())
                    _back->setExpandedMacro(expandedMacro);
            }

            CurrentToken.clear();

            continue;
        }
//.........这里部分代码省略.........
开发者ID:NightOfTwelve,项目名称:cppcheck,代码行数:101,代码来源:tokenlist.cpp

示例15: if

Node::Node( std::istream &in,  const int style, const int l, const int pos  )
   throw( MalformedError ): Element( l, pos )
{
   // variables to optimize data node promotion in tag nodes
   bool promote_data = true;
   Node *the_data_node = 0;
   char chr;
   std::string entity;
   int iStatus = STATUS_BEGIN;

   m_prev = m_next = m_parent = m_child = m_last_child = 0;
   // defaults to data type: parents will ignore/destroy empty data elements
   m_type = typeData;

   while ( iStatus >= 0 && in.good() ) {
      in.get( chr );
      // resetting new node foundings
      nextChar();

      //std::cout << "CHR: " << chr << " - status: " << iStatus << std::endl;

      switch ( iStatus ) {

         case STATUS_BEGIN:  // outside nodes
            switch ( chr ) {
               case MXML_LINE_TERMINATOR: nextLine() ; break;
               // We repeat line terminator here for portability
               case MXML_SOFT_LINE_TERMINATOR: break;
               case ' ': case '\t': break;
               case '<': iStatus = STATUS_FIRSTCHAR; break;
               default:  // it is a data node
                  m_type = typeData;
                  m_data = chr;
                  iStatus = STATUS_READ_DATA; // data
            }
         break;

         case STATUS_FIRSTCHAR: //inside a node, first character
            if ( chr == '/' ) {
               iStatus = STATUS_READ_TAG_NAME;
               m_type = typeFakeClosing;
            }
            else if ( chr == '!' ) {
               iStatus = STATUS_MAYBE_COMMENT;
            }
            else if ( chr == '?' ) {
               m_type = typePI;
               iStatus = STATUS_READ_TAG_NAME; // PI - read node name
            }
            else if ( isalpha( chr ) ) {
               m_type = typeTag;
               m_name = chr;
               iStatus = STATUS_READ_TAG_NAME2; // tag - read node name (2nd char)
            }
            else {
               throw MalformedError( Error::errInvalidNode, this );
            }
         break;

         case STATUS_MAYBE_COMMENT: //inside a possible comment (<!-/<!?)
            if ( chr == '-') {
               iStatus = STATUS_MAYBE_COMMENT2 ;
            }
            else if ( isalpha( chr ) ) {
               m_type = typeDirective;
               m_name = chr;
               iStatus = STATUS_READ_TAG_NAME; // read directive
            }
            else {
               throw MalformedError( Error::errInvalidNode, this );
            }
         break;

         case STATUS_MAYBE_COMMENT2:
            if ( chr == '-') {
               m_type = typeComment;
               iStatus = STATUS_READ_COMMENT; // read comment
            }
            else {
               throw MalformedError( Error::errInvalidNode, this );
            }
         break;

         case STATUS_READ_COMMENT:
            if ( chr == '-' ) {
               iStatus = STATUS_END_COMMENT1;
            }
            else {
               if ( chr == MXML_LINE_TERMINATOR )
                  nextLine();
               m_data += chr;
            }
         break;

         case STATUS_END_COMMENT1:
            if( chr == '-' )
               iStatus =  STATUS_END_COMMENT2;
            else {
               iStatus = STATUS_READ_COMMENT;
               m_data += "-" + chr;
//.........这里部分代码省略.........
开发者ID:Apyr,项目名称:Preinstall-Splash-Tool,代码行数:101,代码来源:mxml_node.cpp


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