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


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

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


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

示例1: q

bool G2oEdgeSE3
::read(std::istream& is)
{
//  assert(false);
  std::cout << "read G2oEdgeSE3 called" << "\n";

  Vector3d vec;
  for(int i=0; i<3; i++) is >> vec[i];

  double q_in [4];
  for(int i=0; i<4; i++) is >> q_in[i];
  Quaterniond q(q_in[0], q_in[1], q_in[2], q_in[3]);

  Sophus::SE3 se3(q, vec);
  setMeasurement(se3);

   if (is.bad()) {
      return false;
    }
    for ( int i=0; i<information().rows() && is.good(); i++)
      for (int j=i; j<information().cols() && is.good(); j++){
        is >> information()(i,j);
        if (i!=j)
          information()(j,i)=information()(i,j);
      }
    if (is.bad()) {
      //  we overwrite the information matrix with the Identity
      information().setIdentity();
    }
  return true;
}
开发者ID:asimay,项目名称:ScaViSLAM_ros,代码行数:31,代码来源:anchored_points.cpp

示例2: if

static inline std::streamsize
get_frame(std::istream& is, std::vector<char>& buf)
{
	using boost::lexical_cast;
	using boost::starts_with;

	static const std::string b{"--RaNd0m"};
	static const std::string cl{"Content-length: "};

	std::string line{};

	do {
		std::getline(is, line);
	}
	while (is.good() && !starts_with(line, b));

	do {
		std::getline(is, line);
	}
	while (is.good() && !starts_with(line, cl));

	if (is.eof()) {
		return false;
	}
	else if (is.bad()) {
		throw std::runtime_error{"Error finding start of frame."};
	}

	std::size_t n;

	try {
		auto s = line.substr(cl.length(), line.length() - cl.length() - 1);
		n = boost::lexical_cast<std::size_t>(std::move(s));
	}
	catch (boost::bad_lexical_cast& e) {
		throw std::runtime_error{"Error parsing content length."};
	}

	if (n <= 0) {
		throw std::runtime_error{"Content length not positive."};
	}

	if (buf.size() < n) {
		buf.resize(n);
	}

	std::getline(is, line);
	if (!(line.length() == 1 && line[0] == '\r')) {
		throw std::runtime_error{"Expected \"\\r\\n\" before frame contents."};
	}
	
	is.read(buf.data(), n);

	if (is.bad()) {
		throw std::runtime_error{"Error reading frame contents."};
	}
	else {
		return true;
	}
}
开发者ID:adityaramesh,项目名称:deldot_downloader,代码行数:60,代码来源:split.cpp

示例3: parseStream

bool ossimKeywordlist::parseStream(std::istream& is)
{
   if (!is) // Check stream state.
   {
      return false;
   }
   ossimString key;
   ossimString value;
   ossimString sequence;
   KeywordlistParseState state = KeywordlistParseState_OK;
   while(!is.eof() && !is.bad())
   {
      skipWhitespace(is);
      if(is.eof() || is.bad()) return true; // we skipped to end so valid keyword list
      state = readComments(sequence, is);
      if(state & KeywordlistParseState_BAD_STREAM) return false;
      // if we failed a comment parse then try key value parse.
      if(state == KeywordlistParseState_FAIL)
      {
         key = sequence; // just in case there is a 1 token look ahead residual for a single slash test.
         ossimKeywordlist::KeywordlistParseState testKeyValueState = readKeyAndValuePair(key, value, is);
         if(testKeyValueState == KeywordlistParseState_OK)
         {
            key = key.trim();
            if(key.empty())
            {
               return true;
            }
            if ( m_expandEnvVars == true )
            {
               ossimString result = value.expandEnvironmentVariable();
               m_map.insert(std::make_pair(key.string(), result.string()));
            }
            else
            {
               m_map.insert(std::make_pair(key.string(), value.string()));
            }
         }
         else if(testKeyValueState & KeywordlistParseState_BAD_STREAM)
         {
            return false;
         }
#if 0
         // Commented out to allow an invalid line in keyword list without
         // erroring out, effectively skipping bad line. drb - 01 Sep. 2001
         else
         {
            return false;
         }
#endif
      }
      else if(state & KeywordlistParseState_BAD_STREAM)
      {
         return false;
      }
      sequence = key = value = "";
   }   
   
   return true;
}
开发者ID:harryjfowen,项目名称:ossim,代码行数:60,代码来源:ossimKeywordlist.cpp

示例4: setMeasurement

  bool EdgeSE3Offset::read(std::istream& is) {
    int pidFrom, pidTo;
    is >> pidFrom >> pidTo   ;
    if (! setParameterId(0,pidFrom))
      return false;
    if (! setParameterId(1,pidTo))
      return false;

    Vector7d meas;
    for (int i=0; i<7; i++) 
      is >> meas[i];
    // normalize the quaternion to recover numerical precision lost by storing as human readable text
    Vector4d::MapType(meas.data()+3).normalize();
    setMeasurement(internal::fromVectorQT(meas));
    
    if (is.bad()) {
      return false;
    }
    for ( int i=0; i<information().rows() && is.good(); i++)
      for (int j=i; j<information().cols() && is.good(); j++){
  is >> information()(i,j);
  if (i!=j)
    information()(j,i)=information()(i,j);
      }
    if (is.bad()) {
      //  we overwrite the information matrix with the Identity
      information().setIdentity();
    } 
    return true;
  }
开发者ID:Aerobota,项目名称:c2tam,代码行数:30,代码来源:edge_se3_offset.cpp

示例5: load

    bool load(std::istream &in, Memory& mem, addr_t img_base) {
        if (virt_sz > 0) {
            addr_t sect_addr_va = img_base + virt_addr;
            int prot = get_prot(charac);
            mem.alloc_protect(sect_addr_va , virt_sz, prot | Memory::Write);
            //TODO check for file_sz > virt_sz (explained in spec)
            if (file_sz > 0) {
                std::istream::streampos pos_orig = in.tellg(); 
                if (pos_orig == std::istream::pos_type(std::istream::off_type(-1)))
                    return false;
                in.seekg(file_pos, std::ios_base::beg);
                // TODO is "bad()" the right thing to check?
                if (in.bad())
                    return false;
                char *sect_data = new char[file_sz];
                in.read(sect_data, file_sz);
                if (std::size_t(in.gcount()) < file_sz) {
                    delete[] sect_data;
                    return false;
                }
                // perhaps change "write" interface to accept const char * to
                // avoid this copying madness?
                mem.write(sect_addr_va, std::string(sect_data, file_sz));
                delete[] sect_data;
                if (!(prot & Memory::Write))
                    mem.alloc_protect(sect_addr_va, virt_sz, prot);
                in.seekg(pos_orig);
                if (in.bad())
                    return false;
            }
        }

        return true;
    }
开发者ID:dusek,项目名称:army,代码行数:34,代码来源:PELoader.cpp

示例6: setParameterId

  bool EdgeSE3PointXYZDisparity::read(std::istream& is) {
    // measured keypoint
    int pid;
    is >> pid;
    setParameterId(0,pid);

    Vector3d meas;
    for (int i=0; i<3; i++) is >> meas[i];
    setMeasurement(meas);
    if (is.bad())
      return false;
    for ( int i=0; i<information().rows() && is.good(); i++)
      for (int j=i; j<information().cols() && is.good(); j++){
  is >> information()(i,j);
  if (i!=j)
    information()(j,i)=information()(i,j);
      }
    if (is.bad()) {
      //  we overwrite the information matrix
      information().setIdentity();
      information()(2,2)=1000.;
    }
    //_cacheIds[0] = _paramId;
    return true;
  }
开发者ID:mikejmills,项目名称:g2o,代码行数:25,代码来源:edge_se3_pointxyz_disparity.cpp

示例7: readHeader

bool ossimXmlDocument::readHeader(std::istream& in)
{
   //---
   // Clear the existing header so we don't get double:
   // <?xml version='1.0'?><?xml version='1.0'?>
   //---
   theXmlHeader.clear();
   
   char c;
   in>>xmlskipws;

   while(in.peek() == '<')
   {
      std::stack<char> theLessThanStack;
      theLessThanStack.push('<');
      in.ignore(1);
      c = in.peek();
      // we will for now skip things like !DOCTYPE and any other things in the header of the document that start with <? or <!
      if((c == '?')||
         (c == '!'))
      {
         theXmlHeader += "<";
         theXmlHeader += (char)in.get();
         
         while(!theLessThanStack.empty()&&
               (!in.bad()))
         {
            if(in.peek() == '<')
            {
               theLessThanStack.push('<');
            }
            else if(in.peek() == '>')
            {
               theLessThanStack.pop();
            }
            theXmlHeader += (char)in.get();
         }
         if(!in.bad())
         {
            if(in.peek()=='\n'||
               in.peek()=='\r')
            {
               theXmlHeader += (char)in.get();
            }
         }
//          if(!in.bad())
//          {
//             theXmlHeader += (char)in.get();
//          }
         in>>xmlskipws;
      }
   }
开发者ID:LucHermitte,项目名称:ossim,代码行数:52,代码来源:ossimXmlDocument.cpp

示例8: parse_options

    /**
     * Parses an option stream  of the form "a=b c=d ..."
     */
    inline bool parse_options(std::istream& s) {
        options.clear();
        std::string opt, value;
        // read till the equal
        while(s.good()) {
            getline(s, opt, '=');
            if (s.bad() || s.eof()) return false;

            getline(s, value, ' ');
            if (s.bad()) return false;
            set_option_str(trim(opt), trim(value));
        }
        return true;
    }
开发者ID:JackieXie168,项目名称:graphlab,代码行数:17,代码来源:options_map.hpp

示例9: read

bool ossimXmlDocument::read(std::istream& in)
{
//   char buffer[BUFFER_MAX_LEN];
//   streampos file_pos;
//   bool readingHeader = true;
   bool startTagCharacterFound = false;
   char c = in.peek();

   // Initially we will do our own skipping to make sure we ar not binary.
   while(!in.bad() && (c != '<') && (c >= 0x20) && (c <= 0x7e))
   {
      in.ignore(1);
      c = in.peek();
   }

   if (in.bad() || (c!='<'))
   {
      setErrorStatus();
      return false;
   }
   startTagCharacterFound = true;

   if(readHeader(in))
   {
      if(theXmlHeader=="")
      {
         if(startTagCharacterFound)
         {
            theXmlHeader = "<?xml version='1.0'?>";
         }
      }
   }
   if((!theXmlHeader.contains("xml version")) && theStrictCheckFlag)
   {
      if (traceDebug())
      {
         ossimNotify(ossimNotifyLevel_DEBUG)
            << "FATAL: ossimXmlDocument::ossimXmlDocument"
            << "encountered parsing XML file <" << theFilename
            << ">. The file does not appear to be XML v1.0. \n"
            << "Header = \n" << theXmlHeader <<"\n"
            << endl;
      }
      setErrorStatus();
      return false;
   }
   theRootNode = new ossimXmlNode(in, 0);
   setErrorStatus(theRootNode->getErrorStatus());
   return (getErrorStatus()==ossimErrorCodes::OSSIM_OK);
}
开发者ID:LucHermitte,项目名称:ossim,代码行数:50,代码来源:ossimXmlDocument.cpp

示例10: sizeof

template<class T> void WavFileInputSoundStream::read(std::istream & is, T & t)
{
	is.read(reinterpret_cast<char *>(&t), sizeof(T));
	if(is.eof()) throw std::string("EOF");
	if(is.fail()) throw std::string("FAIL");
	if(is.bad()) throw std::string("BAD");
}
开发者ID:romadidukh,项目名称:audio,代码行数:7,代码来源:WavFileSoundStream.cpp

示例11: BadFileException

std::vector<TautomerTransform> readTautomers(std::istream& inStream,
                                             int nToRead) {
  std::vector<TautomerTransform> tautomers;
  tautomers.clear();
  if (inStream.bad()) {
    throw BadFileException("Bad stream contents.");
  }
  const int MAX_LINE_LEN = 512;
  char inLine[MAX_LINE_LEN];
  std::string tmpstr;
  int nRead = 0;
  while (!inStream.eof() && (nToRead < 0 || nRead < nToRead)) {
    inStream.getline(inLine, MAX_LINE_LEN, '\n');
    tmpstr = inLine;
    // parse the molpair on this line (if there is one)
    TautomerTransform* transform = getTautomer(tmpstr);
    if (transform != nullptr) {
      //			std::cout << MolToSmiles(*(transform->Mol) ) <<
      //std::endl;
      tautomers.push_back(*transform);
      nRead++;
    }
  }
  return tautomers;
}
开发者ID:iwatobipen,项目名称:rdkit,代码行数:25,代码来源:TautomerCatalogUtils.cpp

示例12: Error

    XMListream::XMListream(std::istream &i)
    {
      root = lastsibling = NULL;
      XML_Parser p = XML_ParserCreate(NULL);
      if (!p) throw Error("Couldn't create parser");

      XML_SetElementHandler(p, startElement, endElement);
      XML_SetCharacterDataHandler(p, charData);
      XML_SetUserData(p, (void *) this);

      do {
        static const size_t SIZE = 8192;
        char buffer[SIZE];

        i.read(buffer, SIZE);
        if (i.bad()) throw Error("Read error");
        if (!XML_Parse(p, buffer, i.gcount(), i.eof())) {
  	std::ostringstream ost;
  	ost << "XML parsing error at line " << XML_GetCurrentLineNumber(p)
              << ':' << XML_ErrorString(XML_GetErrorCode(p));
  	throw Error(ost.str());
        }
      } while (!i.eof());

      XML_ParserFree(p);
      if (!parents.empty()) throw Error("Non-empty stack."); 

      // root->print(); // For debugging
      current = root;
    }
开发者ID:dilawar,项目名称:cec,代码行数:30,代码来源:IR.cpp

示例13: read_buffer

static bool read_buffer(std::istream& is, z_stream& z, char* in_buf, void* p, size_t size, std::ostream* errorStream) {
    z.next_out=(Bytef*)p;
    z.avail_out=(uInt)size;

    while (z.avail_out) {
        if ( z.avail_in == 0 ) {
            if (!is.eof()) {
                z.next_in = (Bytef*)in_buf;
                is.read((char*)z.next_in, OUT_BUFSIZE);
                if (is.bad()) {
                    if(errorStream) *errorStream<<"read error "<<std::endl;;
                    return false;
                }
                z.avail_in = (uInt)is.gcount();
            }
        }
        int ret = inflate( &z, Z_BLOCK  );
        if ( ret != Z_OK && ret != Z_STREAM_END ) {
            if(errorStream) *errorStream<<"Zlib error "<<z.msg<<std::endl;;
            return false;
        }
        if (ret == Z_STREAM_END && z.avail_out > 0) {
            std::cerr<<"Truncated prt file  "<<std::endl;;
            return false;
        }
    }
    return true;
}
开发者ID:davvid,项目名称:partio,代码行数:28,代码来源:PRT.cpp

示例14: read

void HTTPResponse::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();

	std::string version;
	std::string status;
	std::string reason;
	
	int ch =  istr.get();
	if (istr.bad()) throw NetException("Error reading HTTP response header");
	if (ch == eof) throw NoMessageException();
	while (Poco::Ascii::isSpace(ch)) ch = istr.get();
	if (ch == eof) throw MessageException("No HTTP response header");
	while (!Poco::Ascii::isSpace(ch) && ch != eof && version.length() < MAX_VERSION_LENGTH) { version += (char) ch; ch = istr.get(); }
	if (!Poco::Ascii::isSpace(ch)) throw MessageException("Invalid HTTP version string");
	while (Poco::Ascii::isSpace(ch)) ch = istr.get();
	while (!Poco::Ascii::isSpace(ch) && ch != eof && status.length() < MAX_STATUS_LENGTH) { status += (char) ch; ch = istr.get(); }
	if (!Poco::Ascii::isSpace(ch)) throw MessageException("Invalid HTTP status code");
	while (Poco::Ascii::isSpace(ch) && ch != '\r' && ch != '\n' && ch != eof) ch = istr.get();
	while (ch != '\r' && ch != '\n' && ch != eof && reason.length() < MAX_REASON_LENGTH) { reason += (char) ch; ch = istr.get(); }
	if (!Poco::Ascii::isSpace(ch)) throw MessageException("HTTP reason string too long");
	if (ch == '\r') ch = istr.get();
	if (ch != '\n') throw MessageException("Unterminated HTTP response line");

	HTTPMessage::read(istr);
	ch = istr.get();
	while (ch != '\n' && ch != eof) { ch = istr.get(); }
	setVersion(version);
	setStatus(status);
	setReason(reason);
}
开发者ID:Bjoe,项目名称:poco,代码行数:31,代码来源:HTTPResponse.cpp

示例15: hwasn1GetLen

/*!
 * 获得ASN1的Len
 */
bool hwasn1GetLen(std::istream& input, size_t& len)
{
    unsigned char loc_Char;
    size_t loc_Len = 0;

    // 读取第一个字符
    loc_Char = input.get();
    loc_Len |= loc_Char;

    // 如果第一位是1,则后7位表示长度所占的字节数
    if((loc_Char & 0x80) == 0x80)
    {
        loc_Len = 0;
        int loc_LenSize = loc_Char & 0x7f;
        while((loc_LenSize--) > 0)
        {
            if(input.bad() || input.eof())
            {
                return false;
            }

            loc_Char = input.get();
            loc_Len <<= 8;
            loc_Len |= loc_Char;
        }
    }

    len = loc_Len;
    return input.good();
}
开发者ID:ismailwissam,项目名称:bill-parser,代码行数:33,代码来源:hw_asn1.cpp


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