Пример #1
0
void SgReadPoint::Read(std::istream& in) const
{
    string s;
    in >> s;
    if (! in)
        return;
    SG_ASSERT(s.length() > 0);
    if (s == "PASS" || s == "pass")
    {
        m_point = SG_PASS;
        return;
    }
    if (s == "COUPON" || s == "coupon")
    {
        m_point = SG_COUPONMOVE;
        return;
    }
    if (s == "COUPON_VIRTUAL" || s == "coupon_virtual")
    {
        m_point = SG_COUPONMOVE_VIRTUAL;
        return;
    }
    if (s == "RESIGN" || s == "resign")
    {
        m_point = SG_RESIGN;
        return;
    }
    char c = s[0];
    if (c >= 'A' && c <= 'Z')
        c = c - 'A' + 'a';
    else if (c < 'a' || c > 'z')
    {
        in.setstate(ios::failbit);
        return;
    }
    int col = c - 'a' + 1;
    if (c >= 'j')
        --col;
    istringstream sin(s.substr(1));
    int row;
    sin >> row;
    if (! sin || ! SgUtil::InRange(col, 1, SG_MAX_SIZE)
        || ! SgUtil::InRange(row, 1, SG_MAX_SIZE))
    {
        in.setstate(ios::failbit);
        return;
    }
    m_point = SgPointUtil::Pt(col, row);
}
Пример #2
0
void BinaryRecord::read(std::istream &in) throw(Core::StreamException) {
	BinaryArchive ar(in.rdbuf(), true);
	ar & NAMED_OBJECT("GenericRecord", *this);
	// Setting the eof bit causes the input to abort the reading
	if ( in.rdbuf()->sgetc() == EOF )
		in.setstate(std::ios_base::eofbit);
}
Пример #3
0
inline bool input(std::istream &in, std::string fmt)
{
    std::string pre_match, specifier, post_match;
    bool have_specifier = ci_private::nextSpecifier(fmt, pre_match, specifier, post_match);

    if(have_specifier)
    {
        // Error, we have no types left!
        return false;
    }

    for(unsigned i = 0; i < fmt.size(); ++i)
    {
        char c;

        in.get(c);
        if(c != fmt[i])
        {
            in.setstate(std::ios::failbit);
            return false;
        }
    }

    return true;
}
Пример #4
0
bool input(std::istream &in, std::string fmt, V &value, Values &... params)
{
    std::string pre_match, specifier, post_match;
    bool have_specifier;

    have_specifier = ci_private::nextSpecifier(fmt, pre_match, specifier, post_match);

    // First, match prematch
    for(unsigned i = 0; i < pre_match.size(); ++i)
    {
        char c;

        // in >> c;
        in.get(c);
        if(c != pre_match[i])
        {
            in.setstate(std::ios::failbit);
            return false;
        }
    }

    if(have_specifier)
    {
        // Then, input as per the specifier
        in >> value;

        // Finally, recurse with the rest of the string
        return input(in, post_match, params...);
    }

    return true;
}
void SELF::deserialize(std::istream & istr, bool withSuffix)
{
    std::string s;
    char c;

    istr >> c;
    if (!istr) {
        return;
    }
    if (c != '{') {
        istr.setstate(std::ios_base::failbit);
        return;
    }

    if (!readAttributeIdentifier(istr, s)) {
        return;
    }
    if (s != "text") {
        istr.setstate(std::ios_base::failbit);
        return;
    }
    istr >> c;
    if (!istr) {
        return;
    }
    if (c != '=') {
        istr.setstate(std::ios_base::failbit);
        return;
    }
    if (withSuffix)
        SPL::deserializeWithSuffix(istr, text_);
    else
        istr >> text_;
    if (!istr) {
        return;
    }
    istr >> c;
    if (!istr) {
        return;
    }

    if (c != '}') {
        istr.setstate(std::ios_base::failbit);
        return;
    }
}
void SELF::deserializeWithNanAndInfs(std::istream & istr, bool withSuffix)
{
   std::string s;
   char c;

   istr >> c; if (!istr) { return; }
   if (c != '{') { istr.setstate(std::ios_base::failbit); return; }
   
   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "arithmeticExpression") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   SPL::deserializeWithNanAndInfs(istr, arithmeticExpression_, withSuffix);
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   
   if (c != '}') { istr.setstate(std::ios_base::failbit); return; }
}
Пример #7
0
void skipToken(std::istream& is, char token)
{
    skipWhitespace(is);
    int i = is.peek();
    if (i == token) {
        is.ignore();
    } else {
        is.setstate(ios::failbit);
    }
}
Пример #8
0
void LFS::import(std::string& lfsFileName, std::istream& data) {
    unsigned iMapAddress = iMapAddresses[currentIMapIdx];
    unsigned iMapSegmentIdx = getSegmentIndexFromAddress(iMapAddress);
    unsigned iMapBlockIdx = getBlockIndexFromAddress(iMapAddress);
    IMap iMap(segments[iMapSegmentIdx]->blocks[iMapBlockIdx]);
    if (iMapAddress == 0) {
        iMap = IMap();
    }
    if (!iMap.hasFree()) {
        iMap = IMap();
        currentIMapIdx++; // may go out of bounds.
    }
    INode iNode(lfsFileName);

    while (data) {
        Block dataBlock;
        data >> dataBlock;
        unsigned blockOffset = 
            segments[currentSegmentIdx]->addBlock(
                    dataBlock, iNode.fileSize, iMap.getNextINodeIndex());
        if (blockOffset == 0) {
            selectNewCleanSegment();
            blockOffset = segments[currentSegmentIdx]->addBlock(
                    dataBlock, iNode.fileSize, iMap.getNextINodeIndex());
        }
        unsigned blockAddress = (currentSegmentIdx << 10) + blockOffset;
        iNode.addBlockAddress(blockAddress);
        if (iNode.fileSize == 128) {
            data.setstate(std::ios::badbit);
            break;
        }
    }

    unsigned iNodeOffset =segments[currentSegmentIdx]->addBlock(
            iNode, iMap.getNextINodeIndex());
    if (iNodeOffset == 0) {
        selectNewCleanSegment();
        iNodeOffset = segments[currentSegmentIdx]->addBlock(
                iNode, iMap.getNextINodeIndex());
    }
    unsigned iNodeAddress = (currentSegmentIdx << 10) + iNodeOffset;
    iMap.addINodeWithAddress(iNodeAddress);

    unsigned iMapOffset = segments[currentSegmentIdx]->addBlock(iMap, currentIMapIdx);
    if (iMapOffset == 0) {
        selectNewCleanSegment();
        iMapOffset = segments[currentSegmentIdx]->addBlock(iMap, currentIMapIdx);
    }
    iMapAddress = (currentSegmentIdx << 10) + iMapOffset;
    iMapAddresses[currentIMapIdx] = iMapAddress;

    files[lfsFileName] = iNodeAddress;
}
Пример #9
0
Файл: reader.cpp Проект: AmkG/hl
// read a string until a separator character is found
std::string read_upto(std::istream & in) {
  static const char *no_sym = " \t\n()";
  std::string res;
  char c;
  c = in.peek();
  while (!in.eof() && strchr(no_sym, c)==NULL) {
    res += in.get();
    c = in.peek();
  }
  if (res=="") 
    in.setstate(std::ios_base::badbit);
  return res;
}
Пример #10
0
bool input(std::istream &in, std::string fmt)
{
    // Just match fmt
    for(unsigned i = 0; i < fmt.size(); ++i)
    {
        char c;

        in.get(c);
        if(c != fmt[i])
        {
            in.setstate(std::ios::failbit);
            return false;
        }
    }
}
Пример #11
0
bool VersionedFileHeader::read_known( VFH_Type i_type, std::istream &io_istream )
{
	// save stream state and position
	streampos pos   = io_istream.tellg();
	ios_base::iostate state = io_istream.rdstate();

	if ( !read_raw( io_istream ) ||
	     m_magicNumber!=(isMSBF()?g_versioned_headers_list[i_type].magic_number_MSBF:g_versioned_headers_list[i_type].magic_number_LSBF) )
	{
		// reading failed, rewind to starting point and reset error flags
		io_istream.seekg( pos );
		io_istream.setstate( state );
		m_magicNumber = m_version = 0;
		m_isMSBF = MSBF_PROCESSOR();
		return false;
	}
	return true;
}
Пример #12
0
bool VersionedFileHeader::read_unknown( std::istream &io_istream, VFH_Type &o_id )
{
	// save stream state and position
	streampos pos   = io_istream.tellg();
	ios_base::iostate state = io_istream.rdstate();

	bool isMSBF_; // from magic number
	if ( !read_raw( io_istream ) ||
	     !typeFromMagicNumber(m_magicNumber, o_id, isMSBF_) ||
	     isMSBF_!=isMSBF() )
	{
		// reading failed, rewind to starting point and reset error flags
		io_istream.seekg( pos );
		io_istream.setstate( state );
		return false;
	}
	return true;
}
Пример #13
0
void Date::read(std::istream& in) {
    int in_day { }, in_month { }, in_year { };
    char sep1 { }, sep2 { };
    in >> in_day >> sep1 >> in_month >> sep2 >> in_year;
    if (isValidDate(1,1,1)) //should be  (isValidYear(in_day))
        std::swap(in_day, in_year);
    if (in_year >= 0 && in_year < 100)
        in_year += 2000;
    if (!in.fail() && sep1 == sep2
        && (sep1 == '.' || sep1 == '/' || sep1 == '-')
        && isValidDate(in_year, in_month, in_day)) {
        year = in_year;
        month = in_month;
        day = in_day;
    } else {
        in.setstate(std::ios::failbit | in.rdstate());
    }
}
Пример #14
0
        void read_with_limit(
            std::istream& in, 
            std::string& buffer, 
            int delim = '\n'
        ) 
        {
            using namespace std;
            const size_t max = 16*1024;
            buffer.clear();
            buffer.reserve(300);

            while (in.peek() != delim && in.peek() != EOF && buffer.size() < max)
            {
                buffer += (char)in.get();
            }

            // if we quit the loop because the data is longer than expected or we hit EOF
            if (in.peek() == EOF || buffer.size() == max)
                throw http_parse_error("HTTP field from client is too long", 414);

            // Make sure the last char is the delim.
            if (in.get() != delim) 
            {
                in.setstate(ios::badbit);
                buffer.clear();
            } 
            else 
            {
                // Read the remaining delimiters
                if (delim == ' ') 
                {
                    while (in.peek() == ' ')
                        in.get();
                }
            }
        }
Пример #15
0
///Loads from the GeomView Object File Format (OFF)
bool LoadOFF(std::istream& in,TriMesh& tri)
{
    string tag;
    in>>tag;
    if(tag != "OFF") {
        fprintf(stderr,"LoadOFF: not a proper OFF file\n");
        return false;
    }
    int mode = 0; //0: waiting for sizes, 1: reading verts, 2: reading tris
    int numFaces = 0;
    int vertIndex=0,faceIndex=0;
    string line;
    while(in) {
        getline(in,line);
        if(in.bad()) return false;
        if(line.length() == 0) continue;
        if(line[0] == '#') continue; //comment line
        if(mode == 0) {
            stringstream ss(line);
            int nv,nf,ne;
            ss>>nv>>nf>>ne;
            if(ss.bad()) {
                in.setstate(ios::badbit);
                return false;
            }
            tri.verts.resize(nv);
            tri.tris.resize(0);
            numFaces = nf;
            mode = 1;
        }
        if(mode == 1) {
            if((int)tri.verts.size() == vertIndex) mode=2;
            else {
                stringstream ss(line);
                ss >> tri.verts[vertIndex];
                if(ss.bad()) {
                    in.setstate(ios::badbit);
                    return false;
                }
                //ignore RGBA colors
                vertIndex++;
            }
        }
        if(mode == 2) {
            if(faceIndex == numFaces) return true;
            else {
                stringstream ss(line);
                int nv;
                vector<int> face;
                ss >> nv;
                if(ss.bad()) {
                    in.setstate(ios::badbit);
                    return false;
                }
                for(int i=0; i<nv; i++) {
                    int v;
                    ss>>v;
                    face.push_back(v);
                }
                if(ss.bad()) {
                    in.setstate(ios::badbit);
                    return false;
                }
                //ignore RGBA colors

                //triangulate faces, assume convex
                for(int i=1; i+1<nv; i++) {
                    tri.tris.push_back(IntTriple(face[0],face[i],face[i+1]));
                }

                faceIndex++;
            }
        }
    }
void SELF::deserialize(std::istream & istr, bool withSuffix)
{
   std::string s;
   char c;

   istr >> c; if (!istr) { return; }
   if (c != '{') { istr.setstate(std::ios_base::failbit); return; }
   
   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "updateType") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, updateType_);
   else
     istr >> updateType_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "updateFlags") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, updateFlags_);
   else
     istr >> updateFlags_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "objectId") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, objectId_);
   else
     istr >> objectId_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "latitude") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, latitude_);
   else
     istr >> latitude_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "longitude") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, longitude_);
   else
     istr >> longitude_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "startNodeId") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, startNodeId_);
   else
     istr >> startNodeId_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "endNodeId") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, endNodeId_);
   else
     istr >> endNodeId_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   if (c != ',') { istr.setstate(std::ios_base::failbit); return; }

   if (!readAttributeIdentifier(istr, s)) { return; }
   if (s != "isOneWay") { istr.setstate(std::ios_base::failbit); return; }
   istr >> c; if (!istr) { return; }
   if (c != '=') { istr.setstate(std::ios_base::failbit); return; }
   if (withSuffix)
     SPL::deserializeWithSuffix(istr, isOneWay_);
   else
     istr >> isOneWay_;
   if (!istr) { return; }  
   istr >> c; if (!istr) { return; }
   
   if (c != '}') { istr.setstate(std::ios_base::failbit); return; }
}