本文整理汇总了C++中std::istream::setstate方法的典型用法代码示例。如果您正苦于以下问题:C++ istream::setstate方法的具体用法?C++ istream::setstate怎么用?C++ istream::setstate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类std::istream
的用法示例。
在下文中一共展示了istream::setstate方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read
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: read
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: input
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: deserialize
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;
}
}
示例5: deserializeWithNanAndInfs
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; }
}
示例6: skipToken
void skipToken(std::istream& is, char token)
{
skipWhitespace(is);
int i = is.peek();
if (i == token) {
is.ignore();
} else {
is.setstate(ios::failbit);
}
}
示例7: import
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;
}
示例8: read_upto
// 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;
}
示例9: read_known
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;
}
示例10: read_unknown
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;
}
示例11: read
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());
}
}
示例12: read_with_limit
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();
}
}
}
示例13: LoadOFF
///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++;
}
}
}
示例14: deserialize
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_;
//.........这里部分代码省略.........
开发者ID:raghukiran1224,项目名称:samples,代码行数:101,代码来源:BeJwlyVELgjAQAOC_11NJiPkq7xaAcSNSjnN0hytiknQ_1790W_0ffCJLseh7ryBGswV1GFbCYUfZeVSDVVrzLmHu3_1C6XKDtldqfxtwyk6nceG3OLI6oMyyEdsmpDj96ZTKgh_1p0s_1kGo60c9Rz9pFfWL5vcivj.cpp