Index: trunk/SophyaLib/NTools/poly.h
===================================================================
--- trunk/SophyaLib/NTools/poly.h	(revision 508)
+++ trunk/SophyaLib/NTools/poly.h	(revision 514)
@@ -1,7 +1,6 @@
 // This may look like C code, but it is really -*- C++ -*-
 //
-// $Id: poly.h,v 1.2 1999-10-25 10:36:11 ansari Exp $
+// $Id: poly.h,v 1.3 1999-10-25 16:40:01 ansari Exp $
 //
-
 
 // Des polynomes avec des operations de bases et surtout des fits.
@@ -10,24 +9,31 @@
 #define POLY_SEEN
 
+#include "objfio.h"
 #include <stdio.h>
 #include "peida.h"
-#include "cvector.h"
+#include "tvector.h"
+#include "ppersist.h"
+#include "anydataobj.h"
+
+namespace PlanckDPC {
 
 class Poly2;
 
-class Poly : public OVector {
+//////////////////////////////////////////////////////////////////////////
+class Poly : public Vector {
+  friend class ObjFileIO<Poly>;
 public:
   Poly(int degre = 0);
+  Poly(Poly const& a);
 
   enum {classId = ClassId_Poly1};
-  int_4                 ClassId() const         { return classId; }
-  static PPersist*      Create() {return new Poly;}
+  int_4  ClassId() const         { return classId; }
 
   inline int Degre() const {UpdateDegIfDirty(); return deg;}
 
-  inline void Realloc(int n, bool force=false) {OVector::Realloc(n+1,force);}
-
-  inline double operator[](int i) const {return data[i];}
-  inline double& operator[](int i) {dirty = 1; return data[i];}
+  inline void Realloc(int n, bool force=false) {Vector::Realloc(n+1,force);}
+
+  inline double operator[](int i) const {return Element(i);}
+  inline double& operator[](int i) {dirty = 1; return Element(i);}
   // Retourne le coefficient de degre i
 
@@ -41,5 +47,5 @@
   // Derive le polynome dans un autre
 
-  int    Roots(OVector& roots) const;
+  int    Roots(Vector& roots) const;
   // retourne les racines si on peut les calculer...
 
@@ -49,8 +55,4 @@
   int    Root2(double& r1, double& r2) const;
   // special degre 2
-
-  friend Poly operator* (Poly const& a, Poly const& b);
-  friend Poly operator+ (Poly const& a, Poly const& b);
-  friend Poly operator- (Poly const& a, Poly const& b);
 
   Poly& operator = (Poly const& b);
@@ -58,7 +60,7 @@
   Poly& operator -= (Poly const& b);
 
-  friend Poly operator* (double a, Poly const& b);
-
   Poly& operator *= (double a);
+
+  Poly Mult(Poly const& b) const;
 
   Poly power(int n) const;
@@ -66,15 +68,11 @@
   Poly2 operator() (Poly2 const& b) const;
 
-  void ReadSelf(PInPersist&);
-  void WriteSelf(POutPersist&) const;
-
   void Print(ostream& s) const;
-  friend ostream& operator << (ostream& s, const Poly& a);
-
-  double Fit(OVector const& x, OVector const& y, int degre);
+
+  double Fit(Vector const& x, Vector const& y, int degre);
   // Fit d'un polynome de degre donne sur les x et y.
 
-  double Fit(OVector const& x, OVector const& y, OVector const& erry2, int degre,
-            OVector& errCoef);
+  double Fit(Vector const& x, Vector const& y, Vector const& erry2, int degre,
+            Vector& errCoef);
   // En plus, on fournit les carres des erreurs sur y et on a les erreurs
   // sur les coefficients dans un vecteur.
@@ -87,11 +85,35 @@
 };
 
+inline Poly operator* (Poly const& a, Poly const& b)
+  { return a.Mult(b); }
+
+inline Poly operator+ (Poly const& a, Poly const& b)
+ { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1));
+   c = a; c += b; return c; }
+
+inline Poly operator- (Poly const& a, Poly const& b)
+  { Poly c((a.Degre() > b.Degre())?(a.Degre()+1):(b.Degre()+1));
+    c = a; c -= b; return c; }
+
+inline Poly operator* (double a, Poly const& b)
+  { Poly c(b); c *= a; return c; }
+
+inline ostream& operator << (ostream& s, const Poly& a)
+  { a.Print(s); return s; }
+
+//////////////////////////////////////////////////////////////////////////
+inline POutPersist& operator << (POutPersist& os, Poly & obj)
+  { ObjFileIO<Poly> fio(&obj);  fio.Write(os);  return(os); }
+inline PInPersist& operator >> (PInPersist& is, Poly & obj)
+  { ObjFileIO<Poly> fio(&obj);  fio.Read(is);  return(is); }
+// Classe pour la gestion de persistance
+// ObjFileIO<Poly>
+
+//////////////////////////////////////////////////////////////////////////
 int binomial(int n, int p);
 
-
-class Poly2 : public OVector {  // Ca pourrait etre une matrice mais
-                                  // la encore, un vecteur est utile pour les
-                                  // fits.
-
+//////////////////////////////////////////////////////////////////////////
+class Poly2 : public Vector {
+  friend class ObjFileIO<Poly2>;
 public:
   Poly2(int degreX=0, int degreY=0);
@@ -101,6 +123,5 @@
 
   enum {classId = ClassId_Poly2};
-  int_4                 ClassId() const         { return classId; }
-  static PPersist*      Create() {return new Poly2;}
+  int_4 ClassId() const         { return classId; }
 
   inline int DegX() const {UpdateDegIfDirty(); return degX;}
@@ -123,25 +144,25 @@
 
   inline double Coef(int dx, int dy) const {
-    return (dx>maxDegX || dy>maxDegY) ? 0 : data[IndCoef(dx,dy)];
+    return (dx>maxDegX || dy>maxDegY) ? 0 : Element(IndCoef(dx,dy));
   }
   inline double& Coef(int dx, int dy) {
     if (dx>maxDegX || dy>maxDegY) THROW(rangeCheckErr);
-    dirty = 1; return data[IndCoef(dx,dy)];
+    dirty = 1; return Element(IndCoef(dx,dy));
   }
   // retourne le coefficient de degre (dx,dy)
 
-  double Fit(OVector const& x, OVector const& y, OVector const& z,
+  double Fit(Vector const& x, Vector const& y, Vector const& z,
              int degreX, int degreY);
-  double Fit(OVector const& x, OVector const& y, OVector const& z,
-             OVector const& errz2, int degreX, int degreY,
-             OVector& errCoef);
+  double Fit(Vector const& x, Vector const& y, Vector const& z,
+             Vector const& errz2, int degreX, int degreY,
+             Vector& errCoef);
   // degres partiels imposes. cf Poly::Fit sinon
 
 
-  double Fit(OVector const& x, OVector const& y, OVector const& z,
+  double Fit(Vector const& x, Vector const& y, Vector const& z,
              int degre);
-  double Fit(OVector const& x, OVector const& y, OVector const& z,
-             OVector const& errz2, int degre,
-             OVector& errCoef);
+  double Fit(Vector const& x, Vector const& y, Vector const& z,
+             Vector const& errz2, int degre,
+             Vector& errCoef);
   // degre total impose. cf Poly::Fit sinon
 
@@ -151,12 +172,9 @@
   Poly2& operator -= (Poly2 const& b);
 
-  friend Poly2 operator + (Poly2 const& a, Poly2 const& b);
-  friend Poly2 operator - (Poly2 const& a, Poly2 const& b);
-  friend Poly2 operator * (Poly2 const& a, Poly2 const& b);
+  Poly2& operator *= (double a);
+
+  Poly2 Mult(Poly2 const& b) const;
 
   Poly2 power(int n) const;
-
-  Poly2& operator *= (double a);
-  friend Poly2 operator * (double a, Poly2 const& b);
 
   Poly2 operator() (Poly const& px, Poly const& py) const;
@@ -165,9 +183,5 @@
   void Realloc(int degreX, int degreY);
 
-  void ReadSelf(PInPersist&);
-  void WriteSelf(POutPersist&) const;
-
   void Print(ostream& s) const;
-  friend ostream& operator << (ostream& s, const Poly2& a);
 
 private:
@@ -182,3 +196,29 @@
 };
 
+inline Poly2 operator* (Poly2 const& a, Poly2 const& b)
+  { return a.Mult(b); }
+
+inline Poly2 operator+ (Poly2 const& a, Poly2 const& b)
+  { Poly2 c(a); c += b; return c; }
+
+inline Poly2 operator- (Poly2 const& a, Poly2 const& b)
+  { Poly2 c(a); c -= b; return c; }
+
+inline Poly2 operator * (double a, Poly2 const& b)
+  { Poly2 c(b); c *= a; return c; }
+
+inline ostream& operator << (ostream& s, const Poly2& a)
+  { a.Print(s); return s; }
+
+//////////////////////////////////////////////////////////////////////////
+inline POutPersist& operator << (POutPersist& os, Poly2 & obj)
+  { ObjFileIO<Poly2> fio(&obj);  fio.Write(os);  return(os); }
+inline PInPersist& operator >> (PInPersist& is, Poly2 & obj)
+  { ObjFileIO<Poly2> fio(&obj);  fio.Read(is);  return(is); }
+// Classe pour la gestion de persistance
+// ObjFileIO<Poly2>
+
+
+} // Fin du namespace
+
 #endif // POLY_SEEN
