IOFunctions.cpp
Go to the documentation of this file.
00001 #include "IOFunctions.h"
00002 
00003 namespace PointMatcherSupport
00004 {
00005 
00006 
00007 std::istream & safeGetLine( std::istream& is, std::string & t)
00008 {
00009    t.clear();
00010 
00011    // The characters in the stream are read one-by-one using a std::streambuf.
00012    // That is faster than reading them one-by-one using the std::istream.
00013    // Code that uses streambuf this way must be guarded by a sentry object.
00014    // The sentry object performs various tasks,
00015    // such as thread synchronization and updating the stream state.
00016 
00017    std::istream::sentry se(is, true);
00018    std::streambuf* sb = is.rdbuf();
00019 
00020    for(;;) {
00021            int c = sb->sbumpc();
00022            switch (c) {
00023                    case '\n':
00024                            return is;
00025                    case '\r':
00026                            if(sb->sgetc() == '\n')
00027                                    sb->sbumpc();
00028                            return is;
00029                    case EOF:
00030                            // Also handle the case when the last line has no line ending
00031                            if(t.empty())
00032                                    is.setstate(std::ios::eofbit);
00033                            return is;
00034                    default:
00035                            t += (char)c;
00036            }
00037    }
00038 }
00039 
00040 }// namespace PointMatcherSupport


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:31