From 749e297a027dffda4c413ae24e8f9a19cc185e11 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 5 May 2023 10:51:24 +0200 Subject: [PATCH] putil: Add file_version property to BamWriter (mirroring BamReader) --- panda/src/putil/bamWriter.h | 4 +++ panda/src/putil/bamWriter_ext.cxx | 28 +++++++++++++++++ panda/src/putil/bamWriter_ext.h | 37 +++++++++++++++++++++++ panda/src/putil/p3putil_ext_composite.cxx | 1 + 4 files changed, 70 insertions(+) create mode 100644 panda/src/putil/bamWriter_ext.cxx create mode 100644 panda/src/putil/bamWriter_ext.h diff --git a/panda/src/putil/bamWriter.h b/panda/src/putil/bamWriter.h index 780104b61c..be07d80411 100644 --- a/panda/src/putil/bamWriter.h +++ b/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); diff --git a/panda/src/putil/bamWriter_ext.cxx b/panda/src/putil/bamWriter_ext.cxx new file mode 100644 index 0000000000..ea5b451eb6 --- /dev/null +++ b/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:: +get_file_version() const { + return Py_BuildValue("(ii)", _this->get_file_major_ver(), + _this->get_file_minor_ver()); +} + +#endif diff --git a/panda/src/putil/bamWriter_ext.h b/panda/src/putil/bamWriter_ext.h new file mode 100644 index 0000000000..1f0b3eefb1 --- /dev/null +++ b/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 : public ExtensionBase { +public: + PyObject *get_file_version() const; +}; + +#endif // HAVE_PYTHON + +#endif // BAMWRITER_EXT_H diff --git a/panda/src/putil/p3putil_ext_composite.cxx b/panda/src/putil/p3putil_ext_composite.cxx index 6306661a7f..abb9df3b73 100644 --- a/panda/src/putil/p3putil_ext_composite.cxx +++ b/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"