Go to the documentation of this file.00001
00002 #ifndef mbl_parse_tuple_h_
00003 #define mbl_parse_tuple_h_
00004
00005
00006
00007
00008
00009
00010 #include <vcl_istream.h>
00011 #include <mbl/mbl_exception.h>
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 template <class T, class U>
00029 inline void mbl_parse_tuple(vcl_istream &afs, T& a, U& b)
00030 {
00031 if (!afs) return;
00032 char brace1, brace2;
00033 afs >> vcl_ws >> brace1;
00034 if (afs.eof())
00035 throw mbl_exception_parse_error("mbl_parse_tuple failed unexpected eof");
00036 if ( brace1 == '{')
00037 {
00038 afs >> vcl_ws >> a >> vcl_ws >> b >> vcl_ws >> brace2;
00039 if (!afs)
00040 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00041 if (brace2 != '}')
00042 {
00043 afs.putback(brace2);
00044 afs.clear(vcl_ios::failbit);
00045
00046 throw mbl_exception_parse_error("mbl_parse_tuple failed to find closing brace");
00047 }
00048 }
00049 else
00050 {
00051 afs.putback(brace1);
00052 afs >> vcl_ws >> a >> vcl_ws >> b;
00053 if (!afs)
00054 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00055 }
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073 template <class T, class U, class V>
00074 inline void mbl_parse_tuple(vcl_istream &afs, T& a, U& b, V& c)
00075 {
00076 if (!afs) return;
00077 char brace1, brace2;
00078 afs >> vcl_ws >> brace1;
00079 if (afs.eof())
00080 throw mbl_exception_parse_error("mbl_parse_tuple failed unexpected eof");
00081 if ( brace1 == '{')
00082 {
00083 afs >> vcl_ws >> a >> vcl_ws >> b >> vcl_ws >> c >> vcl_ws >> brace2;
00084 if (!afs)
00085 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00086 if (brace2 != '}')
00087 {
00088 afs.putback(brace2);
00089 afs.clear(vcl_ios::failbit);
00090
00091 throw mbl_exception_parse_error("mbl_parse_tuple failed to find closing brace");
00092 }
00093 }
00094 else
00095 {
00096 afs.putback(brace1);
00097 afs >> vcl_ws >> a >> vcl_ws >> b >> vcl_ws >> c;
00098 if (!afs)
00099 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00100 }
00101 }
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120 template <class T, class U, class V, class W>
00121 inline void mbl_parse_tuple(vcl_istream &afs, T& a, U& b, V& c, W& d)
00122 {
00123 if (!afs) return;
00124 char brace1, brace2;
00125 afs >> vcl_ws >> brace1;
00126 if (afs.eof())
00127 throw mbl_exception_parse_error("mbl_parse_tuple failed unexpected eof");
00128 if ( brace1 == '{')
00129 {
00130 afs >> vcl_ws >> a >> vcl_ws >> b >> vcl_ws >> c >> vcl_ws >> d >> vcl_ws >> brace2;
00131 if (!afs)
00132 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00133 if (brace2 != '}')
00134 {
00135 afs.putback(brace2);
00136 afs.clear(vcl_ios::failbit);
00137
00138 throw mbl_exception_parse_error("mbl_parse_tuple failed to find closing brace");
00139 }
00140 }
00141 else
00142 {
00143 afs.putback(brace1);
00144 afs >> vcl_ws >> a >> vcl_ws >> b >> vcl_ws >> c >> vcl_ws >> d;
00145 if (!afs)
00146 throw mbl_exception_parse_error("mbl_parse_tuple failed with stream error");
00147 }
00148 }
00149
00150 #endif // mbl_parse_tuple_h_