xyMonom.cc
Go to the documentation of this file.00001
00002 #include "xyMonom.h"
00003 #include "parseTools.h"
00004
00005
00006
00007 using namespace std;
00008
00009
00013 unsigned int xyExpPair::extractExplicitExponent(stringstream& sstream)
00014 {
00015 string res="";
00016
00017 int num=0;
00018 int sign=getSign(sstream);
00019
00020 if (sign<0)
00021 {
00022 throw "negative exponents not allowed fom monoms! " ;
00023 }
00024
00025 sstream >> ws;
00026 sstream >>num;
00027 if (sstream.fail())
00028 {
00029 throw "no exponent given" ;
00030 }
00031 return num;
00032 }
00033
00034
00035
00036
00037
00046 xyExpPair::xyExpPair(std::stringstream& sstream)
00047 {
00048 #ifdef DEBUG
00049 std::cerr << "create xyExpPair" << std::endl;
00050 std::cerr << "xyExpPair stream: =" << sstream.str() << std::endl;
00051 #endif
00052
00053 assert (!sstream.fail());
00054
00055 x_exp=0;
00056 y_exp=0;
00057
00058 char a;
00059 bool isXExp=false;
00060 bool isYExp=false;
00061
00062 sstream >> ws;
00063
00064 while (!sstream.eof() )
00065 {
00066 assert (!sstream.fail());
00067 a=sstream.peek();
00068 #ifdef DEBUG
00069 std::cerr << "a " << a;
00070 #endif
00071 if (a=='*')
00072 {
00073 isXExp=false;
00074 isYExp=false;
00075 sstream >>a;
00076 sstream >> ws;
00077 continue;
00078 }
00079 if (a=='x')
00080 {
00081 x_exp=1;
00082 isXExp=true;
00083 isYExp=false;
00084 sstream >>a;
00085 sstream >> ws;
00086 continue;
00087 }
00088 else
00089 if (a=='y')
00090 {
00091
00092 y_exp=1;
00093 isYExp=true;
00094 isXExp=false;
00095 sstream >>a;
00096 sstream >> ws;
00097 continue;
00098 }
00099 else
00100 if (a=='^')
00101 {
00102 sstream >>a;
00103 if (isXExp)
00104 {
00105 x_exp=extractExplicitExponent(sstream);
00106
00107 }
00108 else if (isYExp)
00109 {
00110 y_exp=extractExplicitExponent(sstream);
00111
00112 }
00113 else throw "[xy]-polynom: unknown variable";
00114 sstream >> ws;
00115 continue;
00116 }
00117 else
00118 {
00119 sstream >> ws;
00120 if (sstream.eof() || a=='-' || a =='+' )
00121 return;
00122 else
00123 {
00124 throw "error during extracting (x,y) exponents";
00125 }
00126 }
00127 }
00128 }
00129
00130
00131