• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ std::istream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: bs

bool demo_csgo::handle_cmdheader<DEMO_USERCMD>(std::istream& is, demo_cmdheader& cmdheader) {
    int32_t seq_num_out;
    if(!stream_read_primitive<int32_t>(is, seq_num_out)) {
        std::cerr << "handle_cmdheader<DEMO_USERCMD>(): !stream_read_primitive<int32_t>(is, seq_num_out)" << std::endl;
        return false;
    }

    int32_t data_length = 0;
    if(!stream_read_primitive<int32_t>(is, data_length)) {
        std::cerr << "handle_cmdheader<DEMO_USERCMD>(): !stream_read_primitive<int32_t>(is, data_length)" << std::endl;
        return false;
    }

    char* buffer = new char[data_length];
    is.read(buffer, data_length);
    CBitRead bs(buffer, data_length);

    usercmd ucmd = this->progressive_usercmd;

    if(bs.ReadOneBit()) { // bs.read(1);
        ucmd.command_number = bs.ReadUBitLong(32); // bs.nReadUInt(32);
    } else {
        ucmd.command_number = this->progressive_usercmd.command_number + 1;
    }

    if(bs.ReadOneBit()) { // bs.read(1)
        ucmd.tick_count = bs.ReadUBitLong(32); // bs.nReadUInt(32);
    } else {
        ucmd.tick_count = this->progressive_usercmd.tick_count + 1;
    }

    if(bs.ReadOneBit()) { // bs.read(1)
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.viewangles[0] = v;
    }

    if(bs.ReadOneBit()) { // bs.read(1)
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.viewangles[1] = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.viewangles[2] = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.aimdirection[0] = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.aimdirection[1] = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.aimdirection[2] = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.forwardmove = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.sidemove = v;
    }

    if(bs.ReadOneBit()) {
        float v;
        bs.ReadBits(reinterpret_cast<char*>(&v), 32);
        ucmd.upmove = v;
    }

    if(bs.ReadOneBit()) {
        ucmd.buttons = bs.ReadUBitLong(32); // bs.nReadUInt(32);
    }

    if(bs.ReadOneBit()) {
        ucmd.impulse = bs.ReadUBitLong(8); // bs.nReadUInt(8);
    }

    if(bs.ReadOneBit()) {
        ucmd.weapon_select = bs.ReadUBitLong(MAX_EDICT_BITS); // bs.nReadUInt(MAX_EDICT_BITS);
        if(bs.ReadOneBit()) {
            ucmd.weapon_subtype = bs.ReadUBitLong(WEAPON_SUBTYPE_BITS); // bs.nReadUInt(WEAPON_SUBTYPE_BITS);
        }
    }

//.........这里部分代码省略.........
开发者ID:4D4B,项目名称:demo_csgo,代码行数:101,代码来源:demo.cpp


示例2: loadModel

bool PolyModel::loadModel(std::istream& istr)
{

    int vertex_count;
    int face_count;
    string data;

    if (!istr.good())
        return false;

    char line[1024];
    istr.getline(line, 1024);

    std::istringstream sstr(line);
    sstr >> data >> vertex_count >> face_count;
    std::string attrib_type;
    bool has_texcoords = false;
    while (!sstr.eof() && sstr.good()) {
        sstr >> attrib_type;
        if (attrib_type == "tex-coords1")
            has_texcoords = true;
    }
    //m_verts.clear();
    //m_polys.clear();
    m_verts.resize(vertex_count);
    m_polys.resize(face_count);
    for(int i = 0; i < m_verts.capacity(); i++)//STORE VERTEX
    {
        string temp1,temp2,temp3;
        istr.getline(line, 1024);
        std::istringstream sstr(line);
        sstr >> temp1 >> temp2 >> temp3;
        m_verts[i].set(atof(temp1.c_str()), atof(temp2.c_str()), atof(temp3.c_str()));


    }


    for(int i = 0; i < m_polys.capacity(); i++)//STORE PLOY NUMBERS
    {
        string temp1,temp;
        istr.getline(line, 1024);
        std::istringstream sstr(line);
        sstr>>temp1;
        m_polys[i].insert(m_polys[i].begin(), atoi(temp1.c_str()));

        for(int j = 0; j < atoi(temp1.c_str()); j++)
        {
            sstr>>temp;
            atoi(temp.c_str());
            m_polys[i].insert(m_polys[i].begin()+j+1,atoi(temp.c_str()));
        }


    }
    /* for(int i =0;i<2;i++)
      {
      for(int j =0;j<4;j++)
      cout<<m_polys[i][j]<<" ";
      cout<<"\n";
      }*/
    m_center = 0.0f;
    m_max_bounding = -numeric_limits<float>::max();
    m_min_bounding = numeric_limits<float>::max();


    computeFaceNormals();
    computeVertexNormals();

    return true;
}
开发者ID:y101149,项目名称:computer-graphic,代码行数:71,代码来源:PolyModel.cpp


示例3: error

bool
CompareTestBaseline
::DoComparison( std::istream & testCSV,
	std::istream & baselineCSV )
{
	this->StringError.clear();
	this->AbsoluteError.clear();
	this->FractionalError.clear();
	this->RowCount = 0;
	this->MaxColumnCount = 1;
	this->StringErrorCount = 0;
	this->AbsoluteErrorCount = 0;
	this->FractionalErrorCount = 0;

	// the stream gets partitioned into lines, then tokens, then type
	// converted to a double or white-space removed string.
	std::string testLine;
	std::string baselineLine;
	std::istringstream testLineStream;
	std::istringstream baselineLineStream;
	std::string testToken;
	std::string baselineToken;
	std::istringstream testTokenStream;
	std::istringstream baselineTokenStream;
	double testTokenAsDouble;
	double baselineTokenAsDouble;
	std::string testTokenAsString;
	std::string baselineTokenAsString;
	bool fractionalErrorOccured = false;
	bool absoluteErrorOccurred = false;
	bool stringErrorOccurred = false;

	// for every line
	while( testCSV.good() )
		{
		++this->RowCount;
		StringErrorRowType stringErrorRow;
		NumericalErrorRowType fractionalErrorRow;
		NumericalErrorRowType absoluteErrorRow;

		getline( testCSV, testLine );
		getline( baselineCSV, baselineLine );
		if( testCSV.good() && !baselineCSV.good() || !testCSV.good() && baselineCSV.good() )
			{
			std::ostringstream ostrm;
			ostrm << "The Baseline does not have the same number of rows"
			      << " as the Test.";
			this->ComparisonMessage = ostrm.str();
			return false;
			}
		testLineStream.str( testLine );
		baselineLineStream.str( baselineLine );

		IndexValueType columnCount = 0;
		// for every token in a line
		while( testLineStream.good() )
			{
			++columnCount;
			// get the token
			getline( testLineStream, testToken, this->Parameters->Delimiter );
			getline( baselineLineStream, baselineToken, this->Parameters->Delimiter );
			if( testLineStream.good() && !baselineLineStream.good() || !testLineStream.good() && baselineLineStream.good() )
				{
				std::ostringstream ostrm;
				ostrm << "The Baseline does not have the same number of columns"
				      << " as the Test in row " << this->RowCount << ".";
				this->ComparisonMessage = ostrm.str();
				return false;
				}

			testTokenStream.clear();
			baselineTokenStream.clear();
			testTokenStream.str( testToken );
			baselineTokenStream.str( baselineToken );

			baselineTokenStream >> baselineTokenAsDouble;
			if( !baselineTokenStream.fail() )
				{
				testTokenStream >> testTokenAsDouble;
				if( testTokenStream.fail() )
					{
					std::ostringstream ostrm;
					ostrm << "Test entry was not a number when Baseline was a number"
					      << " in row " << this->RowCount << " column " << columnCount << ".";
					this->ComparisonMessage = ostrm.str();
					return false;
					}
				double fractionalError = fabs( testTokenAsDouble - baselineTokenAsDouble ) / fabs( baselineTokenAsDouble );
				if( fractionalError >= this->Parameters->FractionalTolerance )
					{
					NumericalErrorPairType error( columnCount - 1, fractionalError );
					fractionalErrorRow.push_back( error );
					fractionalErrorOccured = true;
					++this->FractionalErrorCount;
					}
				double absoluteError = fabs( testTokenAsDouble - baselineTokenAsDouble ); 
				if( absoluteError >= this->Parameters->AbsoluteTolerance )
					{
					NumericalErrorPairType error( columnCount - 1, absoluteError );
					absoluteErrorRow.push_back( error );
//.........这里部分代码省略.........
开发者ID:JumperWang,项目名称:farsight-clone,代码行数:101,代码来源:CSVRegressionTestCompareTestBaseline.cpp


示例4: readInts

//---------------------------------------------------------------------
void OgreMeshDeserializer::readInts(std::istream& stream, std::uint32_t* pDest, size_t count)
{
    stream.read(reinterpret_cast<char*>(pDest), sizeof(std::uint32_t) * count);
    flipFromLittleEndian(pDest, sizeof(std::uint32_t), count);
}
开发者ID:worldforge,项目名称:cyphesis,代码行数:6,代码来源:OgreMeshDeserializer.cpp


示例5: logic_error

task4_4::a_message::a_message( std::istream& inp )
{
	inp.read( content_, content_size );
	if ( inp.eof() )
		throw std::logic_error("bad input stream, a_message cannot be readed");
}
开发者ID:Aljaksandr,项目名称:cpp_craft_1013,代码行数:6,代码来源:a_message.cpp


示例6: importHistogram

bool ossimMultiResLevelHistogram::importHistogram(std::istream& in)
{
   if (!in) // Check stream state.
   {
      return false;
   }
   
   ossimString buffer;
   getline(in, buffer);

   if ( in.eof() ) // Zero byte files will hit here.
   {
      return false;
   }

   // check to see if it is a proprietary histogram file
   // 
   if((buffer =="") || (buffer.c_str()[0] != 'F' ||
      buffer.c_str()[1] != 'i'))
   {
      in.seekg(0, ios::beg);
      ossimKeywordlist kwl;
      if (kwl.parseStream(in) == true)
      {
         return loadState(kwl);
      }
      else
      {
         return false;
      }
   }
   
   ossimProprietaryHeaderInformation header;
   in.seekg(0, ios::beg);
   deleteHistograms();
   if(header.parseStream(in))
   {
      ossim_uint32 numberOfResLevels = header.getNumberOfResLevels();
      
      if(numberOfResLevels)
      {
         theHistogramList.resize(numberOfResLevels);

         for(ossim_uint32 counter = 0; counter < (ossim_uint32)theHistogramList.size(); ++counter)
         {
            theHistogramList[counter] = NULL;
         }
         ossimString reslevelBuffer;
         ossimString buffer;
         
         for(ossim_uint32 idx = 0; idx < numberOfResLevels; ++idx)
         {
            getline(in, buffer);
            if(buffer.find("RR Level") != string::npos)
            {
               std::string::size_type offset = buffer.find(":");
               if(offset != string::npos)
               {
                  reslevelBuffer = buffer.substr(offset+1);
               }
               else
               {
                  deleteHistograms();
                  return false;
               }
            }
            else
            {
               deleteHistograms();
               return false;
            }
            ossim_uint32 resLevelIdx = reslevelBuffer.toUInt32();

            if(resLevelIdx < (ossim_uint32)theHistogramList.size())
            {
               if(!theHistogramList[resLevelIdx])
               {
                  ossimRefPtr<ossimMultiBandHistogram> histogram = new ossimMultiBandHistogram;
                  if(histogram->importHistogram(in))
                  {
                     theHistogramList[resLevelIdx] = histogram;
                  }
                  else
                  {
                     deleteHistograms();
                     return false;
                  }
               }
            }
            else
            {
               deleteHistograms();
               return false;
            }
            ossimString skipDot;
            getline(in, skipDot);
         }
      }
      else
      {
//.........这里部分代码省略.........
开发者ID:LucHermitte,项目名称:ossim,代码行数:101,代码来源:ossimMultiResLevelHistogram.cpp


示例7: atoi

void ossimDoqq::ldstr_v1(std::istream& in)
{
   static const char MODULE[] = "ossimDoqq::ldstr_v1(istream& in)";

   if (!in)
   {
      theErrorStatus = OSSIM_ERROR;
      return;
   }

   char tmp1[DATA_ORDER_SIZE+1];
   in.seekg(DATA_ORDER_OFFSET, std::ios::beg);
   in.get(tmp1, DATA_ORDER_SIZE+1);
   theDataOrder = tmp1;

   //***
   // Perform a sanity check on the data order just in case this isn't a
   // ossimDoqq file.
   //***  
   tmp1[DATA_ORDER_SIZE] = '\0';
   int data_order = atoi(tmp1);
   if ( (data_order != 1) && (data_order != 2) )
   {
      theErrorStatus = OSSIM_ERROR;

      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " NOTICE:\n"
            << "Invalid data ordering.  Not a doq?" << std::endl;
      }
   }
   
   char tmp2[LINE_SIZE+1];
   in.seekg(LINE_OFFSET, std::ios::beg);
   in.get(tmp2, LINE_SIZE+1);
   theLine = atoi(tmp2);

   char tmp3[SAMPLE_SIZE+1];
   in.seekg(SAMPLE_OFFSET,std::ios::beg);
   in.get(tmp3, SAMPLE_SIZE+1); 
   theSample = atoi(tmp3);

   // Check for valid lines and samples.
   if (theLine <= 0 || theSample <= 0)
   {
      theErrorStatus = OSSIM_ERROR;

      if(traceDebug())
      {
         ossimNotify(ossimNotifyLevel_WARN)
            << MODULE << " ERROR:\n"
            << "\tInvalid lines or samples."
            << std::endl;
      }
      
      return;
   }
   
   char tmp4[PROJECTION_SIZE+1];
   in.seekg(PROJECTION_OFFSET, std::ios::beg);
   in.get(tmp4, PROJECTION_SIZE+1);
   theProjection = tmp4;

   char tmp5[UTM_ZONE_SIZE+1];
   in.seekg(UTM_ZONE_OFFSET, std::ios::beg);
   in.get(tmp5, UTM_ZONE_SIZE+1);
   theUtmZone = atoi(tmp5);

   char tmp8[DATUM_SIZE+1];
   in.seekg(DATUM_OFFSET, std::ios::beg);
   in.get(tmp8, DATUM_SIZE+1);
   theDatum = tmp8;

   char rgbType[RGB_SIZE+1];
   in.seekg(RGB_OFFSET, std::ios::beg);
   in.get(rgbType, RGB_SIZE+1);


   if(atoi(rgbType) == 5)
   {
      theRgb = 3;
   }
   else
   {
      theRgb = 1;
   }
   
   theHeaderSize = (theSample * theRgb * 4);

   // Calculate the size of each record.
   theRecordSize = (theSample * theRgb);

   char tmp6[UL_EASTING_SIZE+1];
   in.seekg( (theRecordSize * 2) + UL_EASTING_OFFSET, std::ios::beg);
   in.get(tmp6, UL_EASTING_SIZE+1);

   char tmp7[UL_NORTHING_SIZE+1];
   in.seekg( (theRecordSize * 2) + UL_NORTHING_OFFSET, std::ios::beg);
   in.get(tmp7, UL_NORTHING_SIZE+1);
//.........这里部分代码省略.........
开发者ID:ossimlabs,项目名称:ossim,代码行数:101,代码来源:ossimDoqq.cpp


示例8: if

void ossimDoqq::ldstr_v2(std::istream& in)
{
   static const char MODULE[] = "ossimDoqq::ldstr_v2(istream& in)";

   if (!in)
   {
      theErrorStatus = OSSIM_ERROR;
      return;
   }

   char line[100];
   char dum1[30];
   char dum2[30];
   char dum3[30];
   char dum4[30];

   while((strncmp(line, "END_USGS_HEADER", 15) != 0)&&
			(in.good()))
   {
      // Read in one line of header at a time.
      in.getline(line, 100);
      
      if(strncmp(line, "SAMPLES_AND_LINES", 17) == 0)
      {
         sscanf(line, "%s %s %s", dum1, dum2, dum3);
         theLine = atoi(dum3);
         theSample = atoi(dum2);
      }

      else if(strncmp(line, "HORIZONTAL_COORDINATE_SYSTEM", 28) == 0)
      {
         sscanf(line, "%s %s", dum1, dum2);
         theProjection = dum2;
      }
      
      else if(strncmp(line, "NW_QUAD_CORNER_XY", 17) == 0)
      {         
         sscanf(line, "%s %s %s", dum1, dum2, dum3);
         
         theUE = atof(dum2);
         theUN = atof(dum3);
      }
      
      else if(strncmp(line, "NE_QUAD_CORNER_XY", 17) == 0)
      {
         sscanf(line, "%s %s %s", dum1, dum2, dum3);
         theLE = atof(dum2);
         theLN = atof(dum3);
      }

      else if(strncmp(line, "COORDINATE_ZONE", 15) == 0)
      {
         sscanf(line, "%s %s", dum1, dum2);
         theUtmZone = atoi(dum2);
      }

      else if(strncmp(line, "SOURCE_IMAGE_DATE", 17) == 0)
      {
         sscanf(line, "%s %s %s %s", dum1, dum2, dum3, dum4);
         theAcqYear  = ossimString(dum2);
         theAcqMonth = ossimString(dum3);
         theAcqDay   = ossimString(dum4);
      }

      else if((strncmp(line, "XY_ORIGIN", 9) == 0))
      {
         sscanf(line, "%s %s %s", dum1, dum2, dum3);
         theEasting = atof(dum2);
         theNorthing = atof(dum3);        
      }

      else if((strncmp(line, "HORIZONTAL_DATUM", 16) == 0) && theDatum.empty())
      {
         ossimString datum;         
         sscanf(line, "%s %s", dum1, dum2);
         datum = dum2; 
         
         if(datum.contains("NAD27"))
            theDatum = "NAD";
         else
            theDatum = "NAR";
      }

      else if(strncmp(line, "BYTE_COUNT", 10) == 0)
      {
         ossimString header;         
         sscanf(line, "%s %s", dum1, dum2);
         header = dum2;
         
         theHeaderSize = atoi(header.chars());
      }

      else if(strncmp(line, "BAND_CONTENT", 12) == 0)
      {
         ossimString rgbType;        
         sscanf(line, "%s %s", dum1, dum2);
         rgbType = dum2;

         if(rgbType.contains("BLACK&WHITE"))
            theRgb = 1;
//.........这里部分代码省略.........
开发者ID:ossimlabs,项目名称:ossim,代码行数:101,代码来源:ossimDoqq.cpp


示例9: Load

void matrix::Load(std::istream& in)
{
	int i,j;
    for(  i=0; i<vert; i++ ) for(  j=0; j<horz; j++ )
	in.read((char*) &(*this)(i, j), sizeof(float));
}
开发者ID:mohammad-adnan,项目名称:MuteDeafGestureRecognition,代码行数:6,代码来源:matrix.cpp


示例10: 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:JJ,项目名称:minetest,代码行数:66,代码来源:settings.cpp


示例11: demo_sequence_info_read

bool demo_sequence_info_read(std::istream& is, demo_sequence_info& s) {
    is.read(reinterpret_cast<char*>(&s.seq_number_in), sizeof(s.seq_number_in));
    is.read(reinterpret_cast<char*>(&s.seq_number_out), sizeof(s.seq_number_out));

    return is.good();
}
开发者ID:4D4B,项目名称:demo_csgo,代码行数:6,代码来源:demo.cpp


示例12: demo_cmdinfo_read

bool demo_cmdinfo_read(std::istream& is, demo_cmdinfo& s) {
    demo_cmdinfo_player_read(is, s.players[0]);
    demo_cmdinfo_player_read(is, s.players[1]);

    return is.good();
}
开发者ID:4D4B,项目名称:demo_csgo,代码行数:6,代码来源:demo.cpp


示例13: istrstream

        }
    };

    std::ostream& operator<<(std::ostream& out, const ostrstream& x) {
        out << static_cast<strstreambuf*>(x.rdbuf())->str();
        return out;
    }

    class istrstream : public std::istream {
        strstreambuf sb;
    public:
        istrstream(char* buf) : sb(buf) { }

        template<class T>
        istrstream& operator>>(T& x) {
            std::istream in(&sb);
            in.copyfmt(*this);
            in >> x;
            setstate(in.rdstate());
            return *this;
        }
    };
}

int main() {
    using namespace std;
    using namespace ch21;

    char buf[1024];
    ostrstream out(buf, 1024);
    out << "foo bar " << 12345;
开发者ID:Nobody-7,项目名称:tcpppl_answers,代码行数:31,代码来源:ex26.cpp


示例14:

fourcc::fourcc( std::istream &in )
{
	in.read( _char, 4 );
}
开发者ID:kdt3rd,项目名称:gecko,代码行数:4,代码来源:fourcc.cpp


示例15: LoadFromStream

	Bool TgaFile::LoadFromStream( std::istream & p_Stream )
	{
		// Read the stream size.
		p_Stream.seekg( 0, std::fstream::end );
		SizeType fileSize = static_cast<SizeType>( p_Stream.tellg( ) );
		p_Stream.seekg( 0, std::fstream::beg );

		// Error check the stream size
		if( fileSize < 18 )
		{
			bitLogGraErr(  "Missing header field." );
			p_Stream.seekg( 0, std::fstream::beg ); // Go back to the begining of the stream
			return false;
		}

		// Read the header.
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_IdLength ), 1 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ColorMapType ), 1 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageType ), 1 );
		// Read color map specifications
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ColorMapSpec.m_Offset ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ColorMapSpec.m_Length ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ColorMapSpec.m_EntrySize ), 1 );
		// Read image specifications
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_OriginX ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_OriginY ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_ImageWidth ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_ImageHeight ), 2 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_PixelDepth ), 1 );
		p_Stream.read( reinterpret_cast<char *>( &m_Header.m_ImageSpec.m_ImageDescriptor ), 1 );

		// Error check the header field.
		if( m_Header.m_ImageSpec.m_PixelDepth != 8 &&
			m_Header.m_ImageSpec.m_PixelDepth != 16 &&
			m_Header.m_ImageSpec.m_PixelDepth != 24 &&
			m_Header.m_ImageSpec.m_PixelDepth != 32 )
		{
			bitLogGraErr( "Not supporting " << (int)m_Header.m_ImageSpec.m_PixelDepth << " bit pixel depth."  );
			p_Stream.seekg( 0, std::fstream::beg ); // Go back to the begining of the stream
			return false;
		}

		// Error check the image type
		if( m_Header.GetImageType( ) != UncompressedTrueColorImage &&
			m_Header.GetImageType( ) != UncompressedGrayscaleImage )
		{
			bitLogGraErr(  "Not supporting color mapped or compressed images." );
			p_Stream.seekg( 0, std::fstream::beg ); // Go back to the begining of the stream
			return false;
		}

		if(	m_Header.GetImageType( ) == UncompressedGrayscaleImage && m_Header.m_ImageSpec.m_PixelDepth != 8 )
		{
			bitLogGraErr(  "Not supporting non 8 bit grayscale iamges." );
			p_Stream.seekg( 0, std::fstream::beg ); // Go back to the begining of the stream
			return false;
		}

		// Clear the old pixel data.
		if( m_pData )
		{
			delete m_pData;
		}

		// Calcualte the data size.
		m_DataSize =	static_cast<SizeType>( m_Header.m_ImageSpec.m_ImageWidth ) *
						static_cast<SizeType>( m_Header.m_ImageSpec.m_ImageHeight ) *
						static_cast<SizeType>( m_Header.m_ImageSpec.m_PixelDepth / 8 );

		// Read the data if we are expecting any data.
		if( m_DataSize != 0 )
		{
			// Check if the data fits in the file
			if( fileSize < m_DataSize + 18 )
			{
				bitLogGraErr(  "The expected data size is too large." );
				p_Stream.seekg( 0, std::fstream::beg ); // Go back to the begining of the stream
				return false;
			}

			// Allocate the data
			m_pData = new Uint8[ m_DataSize ];

			// Read the bitmap data
			p_Stream.read( reinterpret_cast<char *>( m_pData ), m_DataSize );
		}

		// Read the footer( optional )
		if( fileSize >= 44 + m_DataSize )
		{
			// Seek to the end where the footer is expected to be
			p_Stream.seekg( 26, std::fstream::end );

			// Read the footer
			p_Stream.read( reinterpret_cast<char *>( &m_Footer.m_ExtensionOffset ), 4 );
			p_Stream.read( reinterpret_cast<char *>( &m_Footer.m_DeveloperAreaOffset ), 4 );
			p_Stream.read( reinterpret_cast<char *>( m_Footer.m_Signature ), 16 );
			p_Stream.read( reinterpret_cast<char *>( &m_Footer.m_Dot ), 1 );
			p_Stream.read( reinterpret_cast<char *>( &m_Footer.m_End ), 1 );
		}
//.........这里部分代码省略.........
开发者ID:jimmiebergmann,项目名称:Bit-Engine,代码行数:101,代码来源:TgaFile.cpp


示例16: loadFromStream

void CompressedPixmap::loadFromStream(std::istream& inputStream)
{
    PixmapHeader header;

    inputStream.read((char*)&header, sizeof(PixmapHeader));

    int bitAccessor = 1;

    for (int i = 0; i < header.domainRegionCount; ++i)
    {
        unsigned long packed;
        inputStream.read((char*)&packed, 4);

        std::bitset<32> bitset(packed);
        DomainRegionDescriptor domainRegion = { 0, 0, 0 };

        for (int j = 0; j < 13; ++j)
        {
            if (bitset[j])
                domainRegion.x += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 13; ++j)
        {
            if (bitset[13 + j])
                domainRegion.y += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 6; ++j)
        {
            if (bitset[26 + j])
                domainRegion.size += bitAccessor;

            bitAccessor <<= 1;
        }

        m_domainRegions.push_back(domainRegion);

        bitAccessor = 1;
    }

    for (int i = 0; i < header.rangeRegionCount; ++i)
    {
        unsigned long long packed;
        inputStream.read((char*)&packed, 7);

        std::bitset<58> bitset(packed);
        RangeRegionDescriptor rangeRegion = { 0, 0, 0, 0, 0, 0 };

        for (int j = 0; j < 13; ++j)
        {
            if (bitset[j])
                rangeRegion.x += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 13; ++j)
        {
            if (bitset[13 + j])
                rangeRegion.y += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 4; ++j)
        {
            if (bitset[26 + j])
                rangeRegion.size += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 14; ++j)
        {
            if (bitset[30 + j])
                rangeRegion.domainRegionIndex += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
        for (int j = 0; j < 4; ++j)
        {
            if (bitset[44 + j])
                rangeRegion.transformation += bitAccessor;

            bitAccessor <<= 1;
        }

        bitAccessor = 1;
//.........这里部分代码省略.........
开发者ID:Tamalulu,项目名称:FractalCompression,代码行数:101,代码来源:CompressedPixmap.cpp


示例17: parseStream

bool rspfApplanixEOFile::parseStream(std::istream& in)
{
    theRecordIdMap.clear();
    rspfString line;
    int c = '\0';
    if(!parseHeader(in, theHeader))
    {
        return false;
    }

    // now parse parameters
    in>>applanix_skipws;
    line = "";
    while(in.good()&&
            !line.contains("RECORD FORMAT"))
    {
        std::getline(in, line.string());
        line = line.upcase();
        line = line.substitute("\r","\n", true);
        if(line.contains("KAPPA CARDINAL"))
        {
            theKappaCardinal = line;
            theKappaCardinal = theKappaCardinal.substitute("KAPPA CARDINAL ROTATION","");
            theKappaCardinal = theKappaCardinal.substitute(":","");
            theKappaCardinal = theKappaCardinal.substitute("\n","");
        }
        else if(line.contains("LEVER ARM"))
        {
            rspfKeywordlist kwl('=');
            line = line.substitute("LEVER ARM VALUES:",
                                   "");
            line = line.substitute(",",
                                   "\n",
                                   true);
            std::istringstream in(line);

            kwl.parseStream(in);

            theLeverArmLx = kwl.find("LX");
            theLeverArmLy = kwl.find("LY");
            theLeverArmLz = kwl.find("LZ");
        }
        else if(line.contains("BORESIGHT VALUES"))
        {
            rspfKeywordlist kwl('=');
            line = line.substitute("BORESIGHT VALUES:",
                                   "");
            line = line.substitute(",",
                                   "\n",
                                   true);

            std::istringstream in(line);

            kwl.parseStream(in);


            theBoreSightTx = kwl.find("TX");
            theBoreSightTy = kwl.find("TY");
            theBoreSightTz = kwl.find("TZ");
        }
        else if(line.contains("SHIFT VALUES:"))
        {
            rspfKeywordlist kwl('=');
            line = line.substitute("SHIFT VALUES:","");
            line = line.substitute(",",
                                   "\n",
                                   true);

            std::istringstream in(line);
            kwl.parseStream(in);


            theShiftValuesX = kwl.find("X");
            theShiftValuesY = kwl.find("Y");
            theShiftValuesZ = kwl.find("Z");

        }
        else if(line.contains("GRID:"))
        {
            rspfKeywordlist kwl(':');
            line = line.substitute(";",
                                   "\n",
                                   true);
            std::istringstream in(line);
            kwl.parseStream(in);
            theUtmZone = kwl.find("ZONE");

            if(theUtmZone.contains("NORTH"))
            {
                theUtmHemisphere = "North";
            }
            else
            {
                theUtmHemisphere = "South";
            }
            theUtmZone = theUtmZone.replaceAllThatMatch("UTM|\\(.*\\)|NORTH|SOUTH","");
            theUtmZone = theUtmZone.trim();
        }
        else if(line.contains("FRAME DATUM"))
        {
//.........这里部分代码省略.........
开发者ID:vapd-radi,项目名称:rspf_v2.0,代码行数:101,代码来源:rspfApplanixEOFile.cpp


示例18: EatWhitespace

void EatWhitespace(std::istream& in)
{
  while(in && isspace(in.peek())) in.get();
}
开发者ID:HargisJ,项目名称:KrisLibrary,代码行数:4,代码来源:ioutils.cpp


示例19: if

//I/O facilities - FIXME: read( char *fname ), etc. missing
int BSplineCurve2D::read(std::istream &infile)
{
    //FIXME: maybe we need more checks!!!
    char txtbuffer[256];
    bool israt       = false;
    bool isemptyknot = false;


    infile.getline(txtbuffer, 255);   //read line
    if(strcmp(txtbuffer, ff_const_1) &&
       strcmp(txtbuffer, ff_const_4))
    {
        return -1; //bad file format
    }
    if(!strcmp(txtbuffer, ff_const_4))
    {
        israt = true;
    }
    infile >> txtbuffer; //FIXME: error prone: too long string causes problem!!!
    if(strcmp(txtbuffer, ff_const_2) )
        return -1;                                     //yeah, bad file format again

    infile >> dimension >> std::ws;
    if(dimension < 1)
        return -2;                  //ah, bad dimension

    int knoterr = basis_function.read(infile);
    if(knoterr == -3)  // FIXME: hardwired val...
    {
        isemptyknot = true;
    }
    else if(knoterr)
    {
        return -3; //error reading basis function
    }
    if(CheckKnotPoints(basis_function.getKnotVector(), dimension) )
        return -4;

    infile >> txtbuffer; //FIXME: error prone: too long string causes problem!!!
    if(strcmp(txtbuffer, ff_const_3) )
        return -1;                                    //bad file format once again

    DCTPVec3dvector::size_type num_of_cps;
    infile >> num_of_cps >> std::ws;
    if(num_of_cps < 1)
        return -5;                   //too few control points
    control_points.resize(num_of_cps);   //FIXME: whatif not enoght memory?

    for(DCTPdvector::size_type i = 0; i < num_of_cps; ++i)
    {
        Vec3d cp;
        if(israt)
        {
            infile >> cp[0] >> cp[1] >> cp[2] >> std::ws;
        }
        else
        {
            infile >> cp[0] >> cp[1] >> std::ws;
            cp[2] = 1.0;
        }
        control_points[i] = cp;   //FIXME: ya see, we need ERROR CHECKS!!!
    }
开发者ID:DaveHarrison,项目名称:OpenSGDevMaster,代码行数:63,代码来源:OSGBSplineCurve2D.cpp


示例20: localRng

void SpmdMultiVectorSerializer<Scalar>::deserialize(
  std::istream& in, MultiVectorBase<Scalar>* mv
  ) const
{
  Teuchos::RCP<const SpmdVectorSpaceBase<Scalar> >
    mpi_vec_spc = Teuchos::rcp_dynamic_cast<const SpmdVectorSpaceBase<Scalar> >(mv->range());
  if( mpi_vec_spc.get() ) {
    // This is a mpi-based vector space so let's just read the local
    // multi-vector elements (row-by-row).
    const Ordinal
      localOffset = mpi_vec_spc->localOffset(),
      localSubDim = mpi_vec_spc->localSubDim();
    const Range1D localRng( localOffset, localOffset+localSubDim-1 );
    DetachedMultiVectorView<Scalar> local_mv(*mv,localRng,Range1D());
#ifdef TEUCHOS_DEBUG
    TEUCHOS_TEST_FOR_EXCEPTION(
      !in, std::logic_error
      ,"Error: The input stream given is empty before any reading has began!\n"
      "If this stream came from a file, then the file may not exist!"
      );
#endif
    Ordinal localSubDim_in;
    in >> localSubDim_in;
#ifdef TEUCHOS_DEBUG
    TEUCHOS_TEST_FOR_EXCEPTION(
      localSubDim != localSubDim_in, std::logic_error
      , "Error, localSubDim = "<<localSubDim<<" does not match the read in value of "
      "localSubDim_in = "<<localSubDim_in<<"!"
      );
#endif
    Ordinal numSubCols_in;
    in >> numSubCols_in;
#ifdef TEUCHOS_DEBUG
    TEUCHOS_TEST_FOR_EXCEPTION(
      local_mv.numSubCols() != numSubCols_in, std::logic_error
      , "Error, numSubCols = "<<local_mv.numSubCols()<<" does not match the read in value of "
      "numSubCols_in = "<<numSubCols_in<<"!"
      );
#endif
    // Get rid of extra newline after first line
    in >> std::ws;
    // Get the elements
    if( binaryMode() ) {
      // Column-wise
      for( Ordinal j = 0; j < local_mv.numSubCols(); ++j )
        in.read( reinterpret_cast<char*>(&local_mv(0,j)), sizeof(Scalar)*localSubDim );
    }
    else {
      // Row-wise
      for( Ordinal i = 0; i < localSubDim; ++i ) {
#ifdef TEUCHOS_DEBUG
        TEUCHOS_TEST_FOR_EXCEPTION( !in, std::logic_error, "Error, premature end of input!"	);
#endif
        Ordinal i_in;
        in >> i_in;
#ifdef TEUCHOS_DEBUG
        TEUCHOS_TEST_FOR_EXCEPTION(
          i != i_in, std::logic_error
          , "Error, i = "<<i<<" does not match the read in value of "
          "i_in = "<<i_in<<"!"
          );
#endif
        for( Ordinal j = 0; j < local_mv.numSubCols(); ++j ) {
#ifdef TEUCHOS_DEBUG
          TEUCHOS_TEST_FOR_EXCEPTION(
            !in, std::logic_error
            ,"Error: The input stream ran out at j="<<j<<" before"
            " reaching the promised " << local_mv.numSubCols()
            << " rows of the (multi)vector!"
            );
#endif
          in >> local_mv(i,j);
        }
      }
    }
  }
  else {
开发者ID:agrippa,项目名称:Trilinos,代码行数:77,代码来源:Thyra_SpmdMultiVectorSerializer_def.hpp



注:本文中的std::istream类示例由


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ std::istringstream类代码示例发布时间:2022-05-31
下一篇:
C++ std::iostream类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap