From 45fbfab094ab68ca4f130f7a496f65fbe7273fa0 Mon Sep 17 00:00:00 2001 From: rdb Date: Fri, 5 May 2023 10:52:46 +0200 Subject: [PATCH] pgraph: Add file_version property to BamFile (like BamReader/Writer) --- panda/src/pgraph/bamFile.h | 4 +++ panda/src/pgraph/bamFile_ext.cxx | 28 ++++++++++++++++ panda/src/pgraph/bamFile_ext.h | 37 +++++++++++++++++++++ panda/src/pgraph/p3pgraph_ext_composite.cxx | 1 + 4 files changed, 70 insertions(+) create mode 100644 panda/src/pgraph/bamFile_ext.cxx create mode 100644 panda/src/pgraph/bamFile_ext.h diff --git a/panda/src/pgraph/bamFile.h b/panda/src/pgraph/bamFile.h index a244ab3fa3..32793e512e 100644 --- a/panda/src/pgraph/bamFile.h +++ b/panda/src/pgraph/bamFile.h @@ -74,7 +74,11 @@ PUBLISHED: BamReader *get_reader(); BamWriter *get_writer(); +public: + EXTENSION(PyObject *get_file_version() const); + PUBLISHED: + MAKE_PROPERTY(file_version, get_file_version); MAKE_PROPERTY(file_endian, get_file_endian); MAKE_PROPERTY(file_stdfloat_double, get_file_stdfloat_double); diff --git a/panda/src/pgraph/bamFile_ext.cxx b/panda/src/pgraph/bamFile_ext.cxx new file mode 100644 index 0000000000..6c5cd04e1a --- /dev/null +++ b/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:: +get_file_version() const { + return Py_BuildValue("(ii)", _this->get_file_major_ver(), + _this->get_file_minor_ver()); +} + +#endif diff --git a/panda/src/pgraph/bamFile_ext.h b/panda/src/pgraph/bamFile_ext.h new file mode 100644 index 0000000000..7a6408d531 --- /dev/null +++ b/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 : public ExtensionBase { +public: + PyObject *get_file_version() const; +}; + +#endif // HAVE_PYTHON + +#endif // BAMFILE_EXT_H diff --git a/panda/src/pgraph/p3pgraph_ext_composite.cxx b/panda/src/pgraph/p3pgraph_ext_composite.cxx index 37b9012c76..493636ccda 100644 --- a/panda/src/pgraph/p3pgraph_ext_composite.cxx +++ b/panda/src/pgraph/p3pgraph_ext_composite.cxx @@ -1,3 +1,4 @@ +#include "bamFile_ext.cxx" #include "loaderFileTypeRegistry_ext.cxx" #include "nodePath_ext.cxx" #include "nodePathCollection_ext.cxx"