Browse Source

pgraph: Add file_version property to BamFile (like BamReader/Writer)

rdb 2 years ago
parent
commit
45fbfab094

+ 4 - 0
panda/src/pgraph/bamFile.h

@@ -74,7 +74,11 @@ PUBLISHED:
   BamReader *get_reader();
   BamReader *get_reader();
   BamWriter *get_writer();
   BamWriter *get_writer();
 
 
+public:
+  EXTENSION(PyObject *get_file_version() const);
+
 PUBLISHED:
 PUBLISHED:
+  MAKE_PROPERTY(file_version, get_file_version);
   MAKE_PROPERTY(file_endian, get_file_endian);
   MAKE_PROPERTY(file_endian, get_file_endian);
   MAKE_PROPERTY(file_stdfloat_double, get_file_stdfloat_double);
   MAKE_PROPERTY(file_stdfloat_double, get_file_stdfloat_double);
 
 

+ 28 - 0
panda/src/pgraph/bamFile_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 bamFile_ext.cxx
+ * @author rdb
+ * @date 2023-05-03
+ */
+
+#include "bamFile_ext.h"
+#include "bamWriter_ext.h"
+
+#ifdef HAVE_PYTHON
+
+/**
+ * Returns the version number of the Bam file currently being written.
+ */
+PyObject *Extension<BamFile>::
+get_file_version() const {
+  return Py_BuildValue("(ii)", _this->get_file_major_ver(),
+                               _this->get_file_minor_ver());
+}
+
+#endif

+ 37 - 0
panda/src/pgraph/bamFile_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 bamFile_ext.h
+ * @author rdb
+ * @date 2023-05-03
+ */
+
+#ifndef BAMFILE_EXT_H
+#define BAMFILE_EXT_H
+
+#include "dtoolbase.h"
+
+#ifdef HAVE_PYTHON
+
+#include "extension.h"
+#include "bamFile.h"
+#include "py_panda.h"
+
+/**
+ * This class defines the extension methods for BamFile, which are called
+ * instead of any C++ methods with the same prototype.
+ */
+template<>
+class Extension<BamFile> : public ExtensionBase<BamFile> {
+public:
+  PyObject *get_file_version() const;
+};
+
+#endif  // HAVE_PYTHON
+
+#endif  // BAMFILE_EXT_H

+ 1 - 0
panda/src/pgraph/p3pgraph_ext_composite.cxx

@@ -1,3 +1,4 @@
+#include "bamFile_ext.cxx"
 #include "loaderFileTypeRegistry_ext.cxx"
 #include "loaderFileTypeRegistry_ext.cxx"
 #include "nodePath_ext.cxx"
 #include "nodePath_ext.cxx"
 #include "nodePathCollection_ext.cxx"
 #include "nodePathCollection_ext.cxx"