Browse Source

use python_repr() to make linmath pickleable

David Rose 20 years ago
parent
commit
09878b64b0

+ 23 - 0
panda/src/linmath/lmatrix3_src.cxx

@@ -288,6 +288,29 @@ write(ostream &out, int indent_level) const {
     << "\n";
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LMatrix3::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LMatrix3)::
+python_repr(ostream &out, const string &class_name) const {
+  out << class_name << "(" 
+      << MAYBE_ZERO(_m.m._00) << ", "
+      << MAYBE_ZERO(_m.m._01) << ", "
+      << MAYBE_ZERO(_m.m._02) << ", "
+
+      << MAYBE_ZERO(_m.m._10) << ", "
+      << MAYBE_ZERO(_m.m._11) << ", "
+      << MAYBE_ZERO(_m.m._12) << ", "
+
+      << MAYBE_ZERO(_m.m._20) << ", "
+      << MAYBE_ZERO(_m.m._21) << ", "
+      << MAYBE_ZERO(_m.m._22) << ")";
+}
+#endif  // HAVE_PYTHON
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LMatrix3::generate_hash
 //       Access: Public

+ 3 - 0
panda/src/linmath/lmatrix3_src.h

@@ -188,6 +188,9 @@ PUBLISHED:
 
   void output(ostream &out) const;
   void write(ostream &out, int indent_level = 0) const;
+#ifdef HAVE_PYTHON
+  void python_repr(ostream &out, const string &class_name) const;
+#endif
 
 public:
   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;

+ 31 - 0
panda/src/linmath/lmatrix4_src.cxx

@@ -196,6 +196,37 @@ output(ostream &out) const {
       << " ]";
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LMatrix4::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LMatrix4)::
+python_repr(ostream &out, const string &class_name) const {
+  out << class_name << "(" 
+      << MAYBE_ZERO(_m.m._00) << ", "
+      << MAYBE_ZERO(_m.m._01) << ", "
+      << MAYBE_ZERO(_m.m._02) << ", "
+      << MAYBE_ZERO(_m.m._03) << ", "
+
+      << MAYBE_ZERO(_m.m._10) << ", "
+      << MAYBE_ZERO(_m.m._11) << ", "
+      << MAYBE_ZERO(_m.m._12) << ", "
+      << MAYBE_ZERO(_m.m._13) << ", "
+
+      << MAYBE_ZERO(_m.m._20) << ", "
+      << MAYBE_ZERO(_m.m._21) << ", "
+      << MAYBE_ZERO(_m.m._22) << ", "
+      << MAYBE_ZERO(_m.m._23) << ", "
+
+      << MAYBE_ZERO(_m.m._30) << ", "
+      << MAYBE_ZERO(_m.m._31) << ", "
+      << MAYBE_ZERO(_m.m._32) << ", "
+      << MAYBE_ZERO(_m.m._33) << ")";
+}
+#endif  // HAVE_PYTHON
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LMatrix4::write
 //       Access: Public

+ 3 - 0
panda/src/linmath/lmatrix4_src.h

@@ -181,6 +181,9 @@ PUBLISHED:
 
   void output(ostream &out) const;
   void write(ostream &out, int indent_level = 0) const;
+#ifdef HAVE_PYTHON
+  void python_repr(ostream &out, const string &class_name) const;
+#endif
 
 public:
   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;

+ 12 - 0
panda/src/linmath/lpoint2_src.I

@@ -188,3 +188,15 @@ INLINE_LINMATH FLOATNAME(LPoint2) FLOATNAME(LPoint2)::
 operator / (FLOATTYPE scalar) const {
   return FLOATNAME(LPoint2)(FLOATNAME(LVecBase2)::operator / (scalar));
 }
+
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint2::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LPoint2)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase2)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 4 - 0
panda/src/linmath/lpoint2_src.h

@@ -51,6 +51,10 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LPoint2) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LPoint2) operator / (FLOATTYPE scalar) const;
 
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 11 - 0
panda/src/linmath/lpoint3_src.I

@@ -236,3 +236,14 @@ rfu(FLOATTYPE right_v, FLOATTYPE fwd_v, FLOATTYPE up_v,
     FLOATNAME(LVector3)::rfu(right_v, fwd_v, up_v, cs);
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint3::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LPoint3)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase3)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 5 - 0
panda/src/linmath/lpoint3_src.h

@@ -65,6 +65,11 @@ PUBLISHED:
                                        FLOATTYPE fwd,
                                        FLOATTYPE up,
                                        CoordinateSystem cs = CS_default);
+
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 12 - 0
panda/src/linmath/lpoint4_src.I

@@ -208,3 +208,15 @@ INLINE_LINMATH FLOATNAME(LPoint4) FLOATNAME(LPoint4)::
 operator / (FLOATTYPE scalar) const {
   return FLOATNAME(LPoint4)(FLOATNAME(LVecBase4)::operator / (scalar));
 }
+
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LPoint4::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LPoint4)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase4)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 4 - 0
panda/src/linmath/lpoint4_src.h

@@ -52,6 +52,10 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LPoint4) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LPoint4) operator / (FLOATTYPE scalar) const;
 
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 14 - 0
panda/src/linmath/lvecBase2_src.I

@@ -592,6 +592,20 @@ output(ostream &out) const {
       << MAYBE_ZERO(_v.v._1);
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase2::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVecBase2)::
+python_repr(ostream &out, const string &class_name) const {
+  out << class_name << "("
+      << MAYBE_ZERO(_v.v._0) << ", "
+      << MAYBE_ZERO(_v.v._1) << ")";
+}
+#endif  // HAVE_PYTHON
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase2::generate_hash
 //       Access: Public

+ 3 - 0
panda/src/linmath/lvecBase2_src.h

@@ -112,6 +112,9 @@ PUBLISHED:
   INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase2) &other) const;
 
   INLINE_LINMATH void output(ostream &out) const;
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
 
 public:
   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;

+ 15 - 0
panda/src/linmath/lvecBase3_src.I

@@ -764,6 +764,21 @@ output(ostream &out) const {
       << MAYBE_ZERO(_v.v._2);
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase3::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVecBase3)::
+python_repr(ostream &out, const string &class_name) const {
+  out << class_name << "(" 
+      << MAYBE_ZERO(_v.v._0) << ", "
+      << MAYBE_ZERO(_v.v._1) << ", "
+      << MAYBE_ZERO(_v.v._2) << ")";
+}
+#endif  // HAVE_PYTHON
+
 
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase3::generate_hash

+ 3 - 0
panda/src/linmath/lvecBase3_src.h

@@ -122,6 +122,9 @@ PUBLISHED:
   INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase3) &other) const;
 
   INLINE_LINMATH void output(ostream &out) const;
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
 
 public:
   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;

+ 16 - 0
panda/src/linmath/lvecBase4_src.I

@@ -714,6 +714,22 @@ output(ostream &out) const {
       << MAYBE_ZERO(_v.v._3);
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVecBase4::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVecBase4)::
+python_repr(ostream &out, const string &class_name) const {
+  out << class_name << "(" 
+      << MAYBE_ZERO(_v.v._0) << ", "
+      << MAYBE_ZERO(_v.v._1) << ", "
+      << MAYBE_ZERO(_v.v._2) << ", "
+      << MAYBE_ZERO(_v.v._3) << ")";
+}
+#endif  // HAVE_PYTHON
+
 ////////////////////////////////////////////////////////////////////
 //     Function: LVecBase4::generate_hash
 //       Access: Public

+ 3 - 0
panda/src/linmath/lvecBase4_src.h

@@ -117,6 +117,9 @@ PUBLISHED:
   INLINE_LINMATH bool almost_equal(const FLOATNAME(LVecBase4) &other) const;
 
   INLINE_LINMATH void output(ostream &out) const;
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
 
 public:
   INLINE_LINMATH void generate_hash(ChecksumHashGenerator &hashgen) const;

+ 12 - 0
panda/src/linmath/lvector2_src.I

@@ -221,3 +221,15 @@ operator / (FLOATTYPE scalar) const {
   FLOATTYPE recip_scalar = 1.0f/scalar;
   return FLOATNAME(LVector2)(FLOATNAME(LVecBase2)::operator * (recip_scalar));
 }
+
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVector2::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVector2)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase2)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 4 - 0
panda/src/linmath/lvector2_src.h

@@ -47,6 +47,10 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector2) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector2) operator / (FLOATTYPE scalar) const;
 
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 11 - 0
panda/src/linmath/lvector3_src.I

@@ -383,3 +383,14 @@ rfu(FLOATTYPE right_v, FLOATTYPE fwd_v, FLOATTYPE up_v,
  return FLOATNAME(LVector3)(right_v,vy,vz);
 }
 
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVector3::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVector3)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase3)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 4 - 0
panda/src/linmath/lvector3_src.h

@@ -69,6 +69,10 @@ PUBLISHED:
   INLINE_LINMATH static FLOATNAME(LVector3) rfu(FLOATTYPE right,
                                         FLOATTYPE fwd,FLOATTYPE up,     CoordinateSystem cs = CS_default);
 
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;

+ 12 - 0
panda/src/linmath/lvector4_src.I

@@ -242,3 +242,15 @@ operator / (FLOATTYPE scalar) const {
   FLOATTYPE recip_scalar = 1.0f/scalar;
   return FLOATNAME(LVector4)(FLOATNAME(LVecBase4)::operator * (recip_scalar));
 }
+
+#ifdef HAVE_PYTHON
+////////////////////////////////////////////////////////////////////
+//     Function: LVector4::python_repr
+//       Access: Published
+//  Description:
+////////////////////////////////////////////////////////////////////
+INLINE_LINMATH void FLOATNAME(LVector4)::
+python_repr(ostream &out, const string &class_name) const {
+  FLOATNAME(LVecBase4)::python_repr(out, class_name);
+}
+#endif  // HAVE_PYTHON

+ 4 - 0
panda/src/linmath/lvector4_src.h

@@ -49,6 +49,10 @@ PUBLISHED:
   INLINE_LINMATH FLOATNAME(LVector4) operator * (FLOATTYPE scalar) const;
   INLINE_LINMATH FLOATNAME(LVector4) operator / (FLOATTYPE scalar) const;
 
+#ifdef HAVE_PYTHON
+  INLINE_LINMATH void python_repr(ostream &out, const string &class_name) const;
+#endif
+
 public:
   static TypeHandle get_class_type() {
     return _type_handle;