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;
}
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;
	}
}
Beispiel #3
0
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;
}
Beispiel #4
0
  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;
  }
Beispiel #5
0
    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;
    }
  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;
  }
Beispiel #7
0
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;
      }
   }
Beispiel #8
0
    /**
     * 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;
    }
Beispiel #9
0
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);
}
Beispiel #10
0
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");
}
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;
}
Beispiel #12
0
    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;
    }
Beispiel #13
0
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;
}
Beispiel #14
0
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);
}
Beispiel #15
0
/*!
 * 获得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();
}
Beispiel #16
0
 size_t read(void* buf, size_t len)
 {
   inf->read((char*)buf, len);
   if(inf->bad())
     fail("error reading from stream");
   return inf->gcount();
 }
Beispiel #17
0
std::streamsize fullread(
	std::istream& istr,
	char* buf,
	std::streamsize requested)
{
	std::streamsize got;
	std::streamsize total = 0;

	istr.read(buf, requested);	 /*Flawfinder: ignore*/
	got = istr.gcount();
	total += got;
	while(got && total < requested)
	{
		if(istr.fail())
		{
			// If bad is true, not much we can doo -- it implies loss
			// of stream integrity. Bail in that case, and otherwise
			// clear and attempt to continue.
			if(istr.bad()) return total;
			istr.clear();
		}
		istr.read(buf + total, requested - total);	 /*Flawfinder: ignore*/
		got = istr.gcount();
		total += got;
	}
	return total;
}
Beispiel #18
0
void HTTPRequest::read(std::istream& istr)
{
	static const int eof = std::char_traits<char>::eof();

	std::string method;
	std::string uri;
	std::string version;
	method.reserve(16);
	uri.reserve(64);
	version.reserve(16);
	int ch = istr.get();
	if (istr.bad()) throw NetException("Error reading HTTP request header");
	if (ch == eof) throw NoMessageException();
	while (Poco::Ascii::isSpace(ch)) ch = istr.get();
	if (ch == eof) throw MessageException("No HTTP request header");
	while (!Poco::Ascii::isSpace(ch) && ch != eof && method.length() < MAX_METHOD_LENGTH) { method += (char) ch; ch = istr.get(); }
	if (!Poco::Ascii::isSpace(ch)) throw MessageException("HTTP request method invalid or too long");
	while (Poco::Ascii::isSpace(ch)) ch = istr.get();
	while (!Poco::Ascii::isSpace(ch) && ch != eof && uri.length() < MAX_URI_LENGTH) { uri += (char) ch; ch = istr.get(); }
	if (!Poco::Ascii::isSpace(ch)) throw MessageException("HTTP request URI invalid or too long");
	while (Poco::Ascii::isSpace(ch)) ch = istr.get();
	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 (ch != '\n' && ch != eof) { ch = istr.get(); }
	HTTPMessage::read(istr);
	ch = istr.get();
	while (ch != '\n' && ch != eof) { ch = istr.get(); }
	setMethod(method);
	setURI(uri);
	setVersion(version);
}
Beispiel #19
0
ossimKeywordlist::KeywordlistParseState ossimKeywordlist::readComments(ossimString& sequence, std::istream& in)const
{
   KeywordlistParseState result = KeywordlistParseState_FAIL;
   char c = (char)in.peek();
   if(c == '/')
   {
      sequence += (char)in.get();
      c = in.peek();
      if(c == '/')
      {
        result = KeywordlistParseState_OK;
         sequence += c;
         while(!in.bad()&&!in.eof())
         {
            c = (char)in.get();
            if((c == '\n')||
               (c == '\r'))
            {
               break;
            }
            sequence += c;
         }
      }
   }
   return result;
}
Beispiel #20
0
	bool Lexer::readNext( LexToken &tk, std::istream &is ) {
		bool reading = true;
		char ch;
		tk.t_ = T_UNDEFINED;
		tk.s_.clear();

		while( reading ) {
			ch = is.get();
			/*std::cout << "char: " << ch;
			std::cout << " tok: " << tk.t_;
			std::cout << " state: " << state_;
			std::cout << " str: " << tk.s_;
			std::cout << std::endl;*/
			
			
			if( is.bad() || is.eof() ) {
				ch = I_EOF;
				reading = false;
			}

			const Action& a = getAction_(state_,ch);
			switch( a.charAction ) {
				case A_ADD:
					tk.s_ += ch;
					break;
				
				case A_PUTBACK:
					if(ch != I_EOF )
						is.putback(ch);
					break;
				
				case A_IGNORE:
					break;
				
				case A_ERROR:
					tk.t_ = T_UNDEFINED;
					tk.s_.clear();
					reset();
					throw IncorrectTextException();
					break;
			}

			switch( a.bufferAction ) {
				case A_UNCHANGED: break;
				case A_CLEAR: tk.s_.clear(); break;
				case A_RETURN: reading = false; break;
			}

			if( a.newTokenType != T_UNCHANGED )
				tk.t_ = a.newTokenType;

			state_ = a.toState;
		}

		if( ch == I_EOF )
			return false;
		else
			return true;
	}
Beispiel #21
0
bool ObjMeshParser::parseTextureVertex(std::istream& lineStream, ObjMeshData& meshData)
{
    float u(0),v(0);
    float w(0.f);
    char whiteSpaceu_v(0);
    lineStream>>u>>whiteSpaceu_v>>std::ws>>v>>std::ws;
    if(!lineStream.bad() || !lineStream.eof())
    {
        lineStream>>w>>std::ws;
    }
Beispiel #22
0
bool InputToken(std::istream& in,const char* characterSet,std::string& str)
{
  str.erase();
  int c;
  while(in && (c=in.peek())!=EOF) {
    if(strchr(characterSet,c) != NULL)
      str += c;
    c=in.get();
  }
  return !in.bad();
}
Beispiel #23
0
void JobList::init(std::istream &in, Tape *tape)
{
	PCB t(tape);
	while(!(in.eof() || in.bad() || in.fail()))
	{
		in >> *(t.name) >> t.pid >> t.stime >> t.ntime >> t.memory >> t.tapeNum >> t.super;
		jlist.push_back(t);
	}
	auto i = jlist.end();
	i--;
	jlist.erase(i);
}
Beispiel #24
0
void genericLineBasedParsing(
    std::istream &file,
    field_cb_t cb_per_field,
    line_cb_t cb_per_line,
    void *data,
    const csv::params &params) {
  struct csv_parser parser;

  if (!csv_init(&parser, 0)) {
    csv_set_opts(&parser, CSV_APPEND_NULL);
    csv_set_delim(&parser, params.getDelimiter());

    std::string line;
    int line_start = params.getLineStart();

    if (line_start != 1) {
      while (line_start > 1) {
        std::getline(file, line);
        --line_start;
      }
    }


    int lineCount = 0;
    while (std::getline(file, line)) {

      ++lineCount;
      line.append("\n");
      if (csv_parse(&parser,
                    line.c_str(),
                    line.size(),
                    cb_per_field,
                    cb_per_line,
                    data) != line.size()) {
        throw ParserError(csv_strerror(csv_error(&parser)));
      }

      if (params.getLineCount() != -1 && lineCount >= params.getLineCount())
        break;

      if (file.bad())
        break;
    }

    csv_fini(&parser,
             cb_per_field,
             cb_per_line,
             data);
  }
  csv_free(&parser);

}
Beispiel #25
0
/*!
 * 获得ASN1的Tag
 */
bool hwasn1GetTag(std::istream& input, int& tag)
{
    unsigned char loc_Char;
    int loc_Tag = 0;

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

    // 如果后 5 位都是 1,则后续N个字节也是Tag
    if((loc_Char & 0x1f) == 0x1f)
    {
        int loc_Len = 1;
        while((loc_Len++) <= 4)
        {
            if(input.bad() || input.eof())
            {
                return false;
            }

            loc_Char = input.get();

            //第一个后续字节的第7位到第1位不能全为0
            if(loc_Len == 2)
            {
                if(!((loc_Char & 0x7f) | 0x00))
                {
                    return false;
                }
            }

            loc_Tag <<= 8;
            loc_Tag |= loc_Char;

            //后续字节除最后一个字节外,其他字节的第8位为1
            //如果第8位为0,则说明是最后一个后续字节
            if((loc_Char & 0x80) != 0x80)
            {
                break;
            }
        }

        // 华为格式里 Tag 不会大于 4
        if(loc_Len > 4)
        {
            return false;
        }
    }

    tag = loc_Tag;
    return input.good();
}
Beispiel #26
0
std::string readfile(std::istream &in) {
	std::ostringstream buf;
	while (in.good()) {
		char tempbuf[512];
		in.get(tempbuf, sizeof tempbuf, '\0');
		buf << tempbuf;
		if (!in.good())
			break;
		if (in.bad())
			throw creaturesException("IO error");
	}
	return buf.str();
}
void load_file(std::string& s, std::istream& is)
{
   s.erase();
   if(is.bad()) return;
   s.reserve(static_cast<std::string::size_type>(is.rdbuf()->in_avail()));
   char c;
   while(is.get(c))
   {
      if(s.capacity() == s.size())
         s.reserve(s.capacity() * 3);
      s.append(1, c);
   }
}
bool EdgePoseLandmarkReproject
::read(std::istream& is)
{
  double u, v;
  is >> u;
  is >> v;
  setMeasurement(Eigen::Vector2d(u,v));

  if (is.bad()) {
    return false;
  }
  for ( int i=0; i<information().rows() && is.good(); i++)
    for (int j=0; j<information().cols() && is.good(); j++)
      is >> information()(i,j);

  if (is.bad()) {
    //  we overwrite the information matrix with the Identity
    information().setIdentity();
  }

  return true;
}
Beispiel #29
0
 void process(std::istream& input) {
     if (m_state == hybi_legacy_state::INIT) {
         // we are looking for a 0x00
         if (input.peek() == 0x00) {
             // start a message
             input.ignore();
             
             m_state = hybi_legacy_state::READ;
             
             m_data_message = m_connection.get_data_message();
             
             if (!m_data_message) {
                 throw processor::exception("Out of data messages",processor::error::OUT_OF_MESSAGES);
             }
             
             m_data_message->reset(frame::opcode::TEXT);
         } else {
             input.ignore();
             // TODO: ignore or error
             //std::stringstream foo;
             
             //foo << "invalid character read: |" << input.peek() << "|";
             
             std::cout << "invalid character read: |" << input.peek() << "|" << std::endl;
             
             //throw processor::exception(foo.str(),processor::error::PROTOCOL_VIOLATION);
         }
     } else if (m_state == hybi_legacy_state::READ) {
         if (input.peek() == 0xFF) {
             // end
             input.ignore();
             
             m_state = hybi_legacy_state::DONE;
         } else {
             if (m_data_message) {
                 size_t num;
                 
                 input.get(m_payload_buffer, PAYLOAD_BUFFER_SIZE, '\xFF');
                 
                 num = static_cast<size_t>(input.gcount());
                 
                 if (input.bad()) {
                     throw processor::exception("istream readsome error",
                                                processor::error::FATAL_ERROR);
                 }
                 
                 m_data_message->process_payload(m_payload_buffer,num);
             }
         }
     }
 }
Beispiel #30
0
 bool readpacket() // watch performance, if bad, optimize with chunk reading
 {
     std::size_t offset = 0;
     if( !m_synchronized )
     {
         bool first = true;
         while( offset < 4 ) // watch performance, if bad, optimize with chunk reading
         {
             m_istream->read( &m_buf[offset], 1 );
             if( first && m_istream->eof() ) { return false; }
             first = false;
             if( m_istream->eof() || m_istream->bad() ) { COMMA_THROW( comma::exception, "failed to synchronize, bad stream" ); }
             unsigned char header_byte = reinterpret_cast<const unsigned char*>( m_header->data() )[offset];
             offset = header_byte == header::sentinel_value[offset] ? offset + 1 : 0;
         }
         m_synchronized = true; // quick and dirty: synchronize once, should be enough
     }
     m_istream->read( &m_buf[0] + offset, header::size - offset );
     if( m_istream->gcount() == 0 ) { return false; }
     if( m_istream->eof() || m_istream->bad() || m_istream->gcount() != static_cast< int >( header::size - offset ) ) { COMMA_THROW( comma::exception, "failed to read packet header" ); }
     if( !m_header->valid() )
     {
         m_synchronized = false;
         COMMA_THROW( comma::exception, "invalid header (stream from laser went out of sync)" );
     }
     const std::size_t size = m_header->payload_size();
     if( m_buf.size() < size + header::size )
     {
         m_buf.resize( size + header::size );
         m_header = reinterpret_cast< const header* >( &m_buf[0] );
         m_payload = &m_buf[0] + header::size;
     }
     m_istream->read( m_payload, size ); // todo: check payload size so that it does not go crazy?
     if( m_istream->eof() ) { COMMA_THROW( comma::exception, "failed to read payload of size " << m_header->payload_size() << ", end of file" ); }
     if( m_istream->bad() || m_istream->gcount() != int( size ) ) { COMMA_THROW( comma::exception, "failed to read payload of size " << m_header->payload_size() << ", bad stream" ); }
     if( m_header->type() == header::fault_type ) { m_fault = *( reinterpret_cast< fault* >( m_payload ) ); }
     return true;
 }