skip_past.hpp

Go to the documentation of this file.
00001 #ifndef IOF_IGNORE_HPP_
00002 #define IOF_IGNORE_HPP_
00003 
00004 
00018 #include "iof/process_fmt_in.hpp"
00019 #include "iof/except.hpp"
00020 
00021 
00022 namespace iof
00023 {
00024 
00025 
00030 class skip_past
00031 {
00032 public:
00033     skip_past(const std::string& ign): my_ignStr(ign), my_width(-1), my_fill(0) {}
00034     skip_past(int width, char fill = 0): my_width(width), my_fill(fill) 
00035     {
00036         if (my_width < 0) 
00037             throw std::invalid_argument("Width in skip_past must be >= 0");
00038     }
00039 
00040     void applyTo(std::istream& in) const
00041     {
00042         try 
00043         {
00044             if (!my_ignStr.empty()) 
00045                 iof_private::doSkip(in, my_ignStr.c_str(), false);
00046             else 
00047                 iof_private::execSkip(in, my_width, my_fill, my_ignStr.c_str());
00048         }
00049         catch (const iof_private::failure& fail)
00050         {
00051             // silence exception since fmtr will see that stream is fail();
00052             // if not using fmtr, it's up to the user to check stream
00053             // state; if in.exceptions(), we never get here
00054             assert(fail.errType != iof_private::failure::MARKER_NOT_CLOSED);
00055         }
00056     }
00057     
00058 private:
00059     const std::string my_ignStr;
00060     const int my_width;
00061     const char my_fill;
00062 };
00063 
00064 
00065 inline std::istream& 
00066 operator>>(std::istream& in, skip_past ign)
00067 {
00068     ign.applyTo(in);
00069     return in;
00070 }
00071 
00072 
00073 } // namespace 
00074 
00075 
00076 #endif // IOF_IGNORE_HPP_

Generated on Fri Nov 24 16:16:01 2006 for IOF Library by doxygen 1.5.1-p1
Thanks to SourceForge.net Logo for hosting