00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "config.hpp"
00014
00015 #if !defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE) || \
00016 defined(ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE_IO)
00017
00018 #include <iomanip>
00019
00020 #include "io.hpp"
00021 #include "exception.hpp"
00022 #include "cmp.hpp"
00023
00024
00025 namespace Arageli
00026 {
00027
00028
00029 template <typename T, typename Ch, typename ChT>
00030 std::basic_ostream<Ch, ChT>& output_polynom_internal_default
00031 (std::basic_ostream<Ch, ChT>& out, const T& x)
00032 {
00033 std::ios_base::fmtflags old_opts = out.flags();
00034
00035 try { out << std::showpos << x; }
00036 catch(...)
00037 {
00038 out.flags(old_opts);
00039 throw;
00040 }
00041
00042 out.flags(old_opts);
00043 return out;
00044 }
00045
00046
00047 template <typename T, typename Ch, typename ChT>
00048 std::basic_ostream<Ch, ChT>& output_pow_default
00049 (std::basic_ostream<Ch, ChT>& out, const T& x)
00050 {
00051
00052
00053 if(is_negative(x))out << "(" << x << ")";
00054 else out << x;
00055 return out;
00056 }
00057
00058
00059 template <typename T, typename Ch, typename ChT>
00060 std::basic_istream<Ch, ChT>& input_polynom_internal_default
00061 (std::basic_istream<Ch, ChT>& in, T& x)
00062 {
00063 char ch;
00064 in >> ch;
00065 if(!in)return in;
00066
00067
00068
00069 bool minus = false;
00070
00071 if(ch == '-')
00072 {
00073 char ch1;
00074 in >> ch1;
00075 if(!in)return in;
00076 in.putback(ch1);
00077
00078 if(ch1 == '(')
00079 minus = true;
00080 else
00081 in.putback(ch);
00082 }
00083 else if(ch != '+')
00084 {
00085 in.putback(ch);
00086 in.clear(std::ios_base::failbit);
00087 }
00088
00089 T res;
00090 in >> res;
00091 if(!in && !in.eof())return in;
00092 if(minus)opposite(&res);
00093
00094 x = res;
00095 return in;
00096 }
00097
00098
00099 template <typename T, typename Ch, typename ChT>
00100 std::basic_istream<Ch, ChT>& input_polynom_first_default
00101 (std::basic_istream<Ch, ChT>& in, T& x)
00102 {
00103 char ch;
00104 in >> ch;
00105 if(!in)return in;
00106
00107
00108
00109 bool minus = false;
00110
00111 if(ch == '-')
00112 {
00113 char ch1;
00114 in >> ch1;
00115 if(!in)return in;
00116 in.putback(ch1);
00117
00118 if(ch1 == '(')
00119 minus = true;
00120 else
00121 in.putback(ch);
00122 }
00123 else if(ch != '+')
00124 in.putback(ch);
00125
00126 T res;
00127 in >> res;
00128 if(!in && !in.eof())return in;
00129 if(minus)opposite(&res);
00130
00131 x = res;
00132 return in;
00133 }
00134
00135
00136 }
00137
00138
00139 #endif // #ifndef ARAGELI_INCLUDE_CPP_WITH_EXPORT_TEMPLATE
00140