Panda3D
Loading...
Searching...
No Matches
pythonLoaderFileType.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file pythonLoaderFileType.h
10 * @author rdb
11 * @date 2019-07-29
12 */
13
14#ifndef PYTHONLOADERFILETYPE_H
15#define PYTHONLOADERFILETYPE_H
16
17#include "pandabase.h"
18
19#ifdef HAVE_PYTHON
20
21#include "loaderFileType.h"
22#include "extension.h"
23
24/**
25 * This defines a Python-based loader plug-in. An instance of this can be
26 * constructed by inheritance and explicitly registered, or it can be created
27 * by passing in a pkg_resources.EntryPoint instance.
28 *
29 * @since 1.10.4
30 */
31class PythonLoaderFileType : public LoaderFileType {
32public:
33 PythonLoaderFileType();
34 PythonLoaderFileType(std::string extension, PyObject *entry_point);
35 ~PythonLoaderFileType();
36
37 bool init(PyObject *loader);
38 bool ensure_loaded() const;
39
40 virtual std::string get_name() const override;
41 virtual std::string get_extension() const override;
42 virtual std::string get_additional_extensions() const override;
43 virtual bool supports_compressed() const override;
44
45 virtual bool supports_load() const override;
46 virtual bool supports_save() const override;
47
48 virtual PT(PandaNode) load_file(const Filename &path, const LoaderOptions &options,
49 BamCacheRecord *record) const override;
50 virtual bool save_file(const Filename &path, const LoaderOptions &options,
51 PandaNode *node) const override;
52
53private:
54 std::string _extension;
55 std::string _additional_extensions;
56 PyObject *_entry_point = nullptr;
57 PyObject *_load_func = nullptr;
58 PyObject *_save_func = nullptr;
59 bool _supports_compressed = false;
60
62
63public:
64 static TypeHandle get_class_type() {
65 return _type_handle;
66 }
67 static void init_type() {
68 LoaderFileType::init_type();
69 register_type(_type_handle, "PythonLoaderFileType",
70 LoaderFileType::get_class_type());
71 }
72 virtual TypeHandle get_type() const override {
73 return get_class_type();
74 }
75 virtual TypeHandle force_init_type() override {
76 init_type();
77 return get_class_type();
78 }
79
80private:
81 static TypeHandle _type_handle;
82};
83
84#endif // HAVE_PYTHON
85
86#endif
An instance of this class is written to the front of a Bam or Txo file to make the file a cached inst...
The default class template does not define any methods.
Definition extension.h:34
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This class maintains the set of all known LoaderFileTypes in the universe.
This is the base class for a family of scene-graph file types that the Loader supports.
virtual bool supports_compressed() const
Returns true if this file type can transparently load compressed files (with a .pz or ....
virtual bool supports_save() const
Returns true if the file type can be used to save files, and save_file() is supported.
virtual bool supports_load() const
Returns true if the file type can be used to load files, and load_file() is supported.
virtual std::string get_additional_extensions() const
Returns a space-separated list of extension, in addition to the one returned by get_extension(),...
Specifies parameters that may be passed to the loader.
A basic node of the scene graph or data graph.
Definition pandaNode.h:65
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void register_type(TypeHandle &type_handle, const std::string &name)
This inline function is just a convenient way to call TypeRegistry::register_type(),...