Browse Source

putil: Add file_version property to BamWriter (mirroring BamReader)

rdb 2 years ago
parent
commit
749e297a02

+ 4 - 0
panda/src/putil/bamWriter.h

@@ -87,9 +87,13 @@ PUBLISHED:
   INLINE TypedWritable *get_root_node() const;
   INLINE void set_root_node(TypedWritable *root_node);
 
+public:
+  EXTENSION(PyObject *get_file_version() const);
+
 PUBLISHED:
   MAKE_PROPERTY(target, get_target, set_target);
   MAKE_PROPERTY(filename, get_filename);
+  MAKE_PROPERTY(file_version, get_file_version);
   MAKE_PROPERTY(file_endian, get_file_endian);
   MAKE_PROPERTY(file_stdfloat_double, get_file_stdfloat_double);
   MAKE_PROPERTY(file_texture_mode, get_file_texture_mode);

+ 28 - 0
panda/src/putil/bamWriter_ext.cxx

@@ -0,0 +1,28 @@
+/**
+ * PANDA 3D SOFTWARE
+ * Copyright (c) Carnegie Mellon University.  All rights reserved.
+ *
+ * All use of this software is subject to the terms of the revised BSD
+ * license.  You should have received a copy of this license along
+ * with this source code in a file named "LICENSE."
+ *
+ * @file bamWriter_ext.cxx
+ * @author rdb
+ * @date 2023-05-03
+ */
+
+#include "bamWriter_ext.h"
+#include "config_putil.h"
+
+#ifdef HAVE_PYTHON
+
+/**
+ * Returns the version number of the Bam file currently being written.
+ */
+PyObject *Extension<BamWriter>::
+get_file_version() const {
+  return Py_BuildValue("(ii)", _this->get_file_major_ver(),
+                               _this->get_file_minor_ver());
+}
+
+#endif

+ 37 - 0
panda/src/putil/bamWriter_ext.h

@@ -0,0 +1,37 @@
+/**
+ * PANDA 3D SOFTWARE
+ * Copyright (c) Carnegie Mellon University.  All rights reserved.
+ *
+ * All use of this software is subject to the terms of the revised BSD
+ * license.  You should have received a copy of this license along
+ * with this source code in a file named "LICENSE."
+ *
+ * @file bamWriter_ext.h
+ * @author rdb
+ * @date 2023-05-01
+ */
+
+#ifndef BAMWRITER_EXT_H
+#define BAMWRITER_EXT_H
+
+#include "dtoolbase.h"
+
+#ifdef HAVE_PYTHON
+
+#include "extension.h"
+#include "bamWriter.h"
+#include "py_panda.h"
+
+/**
+ * This class defines the extension methods for BamWriter, which are called
+ * instead of any C++ methods with the same prototype.
+ */
+template<>
+class Extension<BamWriter> : public ExtensionBase<BamWriter> {
+public:
+  PyObject *get_file_version() const;
+};
+
+#endif  // HAVE_PYTHON
+
+#endif  // BAMWRITER_EXT_H

+ 1 - 0
panda/src/putil/p3putil_ext_composite.cxx

@@ -1,4 +1,5 @@
 #include "bamReader_ext.cxx"
+#include "bamWriter_ext.cxx"
 #include "bitArray_ext.cxx"
 #include "paramPyObject.cxx"
 #include "pythonCallbackObject.cxx"