Panda3D
Loading...
Searching...
No Matches
pnmFileType.cxx
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 pnmFileType.cxx
10 * @author drose
11 * @date 2000-06-15
12 */
13
14#include "pnmFileType.h"
15
16#include "string_utils.h"
18#include "bamReader.h"
19#include "bamWriter.h"
20
21using std::string;
22
23bool PNMFileType::_did_init_pnm = false;
24TypeHandle PNMFileType::_type_handle;
25
26/**
27 *
28 */
29PNMFileType::
30PNMFileType() {
31}
32
33/**
34 *
35 */
36PNMFileType::
37~PNMFileType() {
38}
39
40/**
41 * Returns the number of different possible filename extensions associated
42 * with this particular file type.
43 */
45get_num_extensions() const {
46 return 0;
47}
48
49/**
50 * Returns the nth possible filename extension associated with this particular
51 * file type, without a leading dot.
52 */
53string PNMFileType::
54get_extension(int) const {
55 nassertr(false, string());
56 return string();
57}
58
59/**
60 * Returns a suitable filename extension (without a leading dot) to suggest
61 * for files of this type, or empty string if no suggestions are available.
62 */
63string PNMFileType::
65 if (get_num_extensions() > 0) {
66 return get_extension(0);
67 }
68 return string();
69}
70
71/**
72 * Returns true if this particular file type uses a magic number to identify
73 * it, false otherwise.
74 */
76has_magic_number() const {
77 return false;
78}
79
80/**
81 * Returns true if the indicated "magic number" byte stream (the initial few
82 * bytes read from the file) matches this particular file type, false
83 * otherwise.
84 */
86matches_magic_number(const string &) const {
87 return false;
88}
89
90/**
91 * Allocates and returns a new PNMReader suitable for reading from this file
92 * type, if possible. If reading from this file type is not supported,
93 * returns NULL.
94 */
96make_reader(std::istream *, bool, const string &) {
97 return nullptr;
98}
99
100/**
101 * Allocates and returns a new PNMWriter suitable for reading from this file
102 * type, if possible. If writing files of this type is not supported, returns
103 * NULL.
104 */
106make_writer(std::ostream *, bool) {
107 return nullptr;
108}
109
110/**
111 * Initializes the underlying PNM library, if it has not already been
112 * initialized. This should be called by every implementation of
113 * make_reader() and make_writer(), to ensure that the library is properly
114 * initialized before any I/O is attempted.
115 */
116void PNMFileType::
117init_pnm() {
118 if (!_did_init_pnm) {
119 _did_init_pnm = true;
120
121 // No reason to do anything here nowadays.
122 }
123}
124
125/**
126 * Fills the indicated datagram up with a binary representation of the current
127 * object, in preparation for writing to a Bam file.
128 *
129 * None of the particular PNMFileType objects store any extra data--at least,
130 * not yet--so we just define this up here to do nothing.
131 */
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition bamWriter.h:63
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise.
get_suggested_extension
Returns a suitable filename extension (without a leading dot) to suggest for files of this type,...
Definition pnmFileType.h:49
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object,...
virtual PNMReader * make_reader(std::istream *file, bool owns_file=true, const std::string &magic_number=std::string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible.
get_num_extensions
Returns the number of different possible filename extensions associated with this particular file typ...
Definition pnmFileType.h:44
virtual PNMWriter * make_writer(std::ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible.
get_extension
Returns the nth possible filename extension associated with this particular file type,...
Definition pnmFileType.h:44
virtual bool matches_magic_number(const std::string &magic_number) const
Returns true if the indicated "magic number" byte stream (the initial few bytes read from the file) m...
This is an abstract base class that defines the interface for reading image files of various types.
Definition pnmReader.h:27
This is an abstract base class that defines the interface for writing image files of various types.
Definition pnmWriter.h:27
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.