00001
00007 class TFoundFactor
00008 {
00009 private:
00010 mpz_t x;
00011 unsigned int e;
00012 string comment;
00013 public:
00014 explicit TFoundFactor(const mpz_t f, const unsigned int exp = 1, const string &xcomment="")
00015 : e(exp), comment(xcomment) { mpz_init_set(x,f); }
00016 explicit TFoundFactor(const unsigned long int f, const unsigned int exp = 1)
00017 : e(exp), comment() { mpz_init_set_ui(x,f); }
00018 TFoundFactor(const TFoundFactor &FF)
00019 : e(FF.e), comment(FF.comment) { mpz_init_set(x,FF.x); }
00020 explicit TFoundFactor(std::istream &is)
00021 {
00022 mpz_init(x);
00023 is.get();
00024 if (is.eof()) { is.setstate(std::ios::failbit); return; }
00025 is.unget();
00026 string s;
00027 is >> x;
00028 is >> s; if (s!="e") { MARK; is.setstate(std::ios::failbit); return; }
00029 is >> e;
00030 is >> s; if (s!="c") { MARK; is.setstate(std::ios::failbit); return; }
00031 char buf[4096];
00032 is.getline(buf,sizeof(buf),'\n'); comment=buf;
00033 }
00034 virtual ~TFoundFactor() { mpz_clear(x); }
00035 virtual bool operator< (const TFoundFactor &nf) const { return (mpz_cmp(x,nf.x)<0); }
00036 void get_factor(mpz_t f, unsigned int &exponent) const { mpz_set(f,x); exponent=e; }
00037 virtual void output(std::ostream &ostr) const;
00038 TFoundFactor& operator= (const TFoundFactor &rhs)
00039 {
00040 mpz_set(x,rhs.x); e=rhs.e; comment=rhs.comment;
00041 return *this;
00042 }
00043 virtual void Save(std::ostream &os) const
00044 {
00045 os << x << " e " << e << " c " << comment << endl;
00046 }
00047 };
00048
00049
00050
00051 inline std::ostream& operator << (std::ostream& ostr, const TFoundFactor FF)
00052 {
00053 FF.output(ostr);
00054 return ostr;
00055 }
00056
00057
00058
00059 class TFoundFactors : public set<TFoundFactor>
00060 {
00061 private:
00062
00063 class autompz_t
00064 {
00065 private:
00066 mpz_t x;
00067 public:
00068 autompz_t() { mpz_init(x); }
00069 ~autompz_t() { mpz_clear(x); }
00070 operator mpz_t&() { return x; }
00071 operator const mpz_t&() const { return x; }
00072 };
00073 public:
00074 string regarding;
00075 autompz_t regarding_numeric_value;
00076
00077 void Load(std::istream &is)
00078 {
00079 clear();
00080 while (is)
00081 {
00082 TFoundFactor FF(is);
00083 if (is.good()) insert(FF);
00084 }
00085 }
00086 void Save(std::ostream &os) const
00087 {
00088 for (TFoundFactors::const_iterator p=begin(); p!=end(); ++p) p->Save(os);
00089 }
00090
00091 void PrettyPrint(std::ostream &os) const;
00092 void AutoSave() const;
00093 void AutoLoad();
00094 };