Panda3D
pnmFileType.cxx
1 // Filename: pnmFileType.cxx
2 // Created by: drose (15Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #include "pnmFileType.h"
16 
17 #include "string_utils.h"
18 #include "executionEnvironment.h"
19 #include "bamReader.h"
20 #include "bamWriter.h"
21 
22 bool PNMFileType::_did_init_pnm = false;
23 TypeHandle PNMFileType::_type_handle;
24 
25 ////////////////////////////////////////////////////////////////////
26 // Function: PNMFileType::Constructor
27 // Access: Protected
28 // Description:
29 ////////////////////////////////////////////////////////////////////
30 PNMFileType::
31 PNMFileType() {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: PNMFileType::Destructor
36 // Access: Public, Virtual
37 // Description:
38 ////////////////////////////////////////////////////////////////////
39 PNMFileType::
40 ~PNMFileType() {
41 }
42 
43 ////////////////////////////////////////////////////////////////////
44 // Function: PNMFileType::get_num_extensions
45 // Access: Published, Virtual
46 // Description: Returns the number of different possible filename
47 // extensions associated with this particular file type.
48 ////////////////////////////////////////////////////////////////////
49 int PNMFileType::
51  return 0;
52 }
53 
54 ////////////////////////////////////////////////////////////////////
55 // Function: PNMFileType::get_extension
56 // Access: Published, Virtual
57 // Description: Returns the nth possible filename extension
58 // associated with this particular file type, without a
59 // leading dot.
60 ////////////////////////////////////////////////////////////////////
61 string PNMFileType::
62 get_extension(int) const {
63  nassertr(false, string());
64  return string();
65 }
66 
67 ////////////////////////////////////////////////////////////////////
68 // Function: PNMFileType::get_suggested_extension
69 // Access: Published, Virtual
70 // Description: Returns a suitable filename extension (without a
71 // leading dot) to suggest for files of this type, or
72 // empty string if no suggestions are available.
73 ////////////////////////////////////////////////////////////////////
74 string PNMFileType::
76  if (get_num_extensions() > 0) {
77  return get_extension(0);
78  }
79  return string();
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: PNMFileType::has_magic_number
84 // Access: Public, Virtual
85 // Description: Returns true if this particular file type uses a
86 // magic number to identify it, false otherwise.
87 ////////////////////////////////////////////////////////////////////
88 bool PNMFileType::
90  return false;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: PNMFileType::matches_magic_number
95 // Access: Public, Virtual
96 // Description: Returns true if the indicated "magic number" byte
97 // stream (the initial few bytes read from the file)
98 // matches this particular file type, false otherwise.
99 ////////////////////////////////////////////////////////////////////
100 bool PNMFileType::
101 matches_magic_number(const string &) const {
102  return false;
103 }
104 
105 ////////////////////////////////////////////////////////////////////
106 // Function: PNMFileType::make_reader
107 // Access: Public, Virtual
108 // Description: Allocates and returns a new PNMReader suitable for
109 // reading from this file type, if possible. If reading
110 // from this file type is not supported, returns NULL.
111 ////////////////////////////////////////////////////////////////////
113 make_reader(istream *, bool, const string &) {
114  return NULL;
115 }
116 
117 ////////////////////////////////////////////////////////////////////
118 // Function: PNMFileType::make_writer
119 // Access: Public, Virtual
120 // Description: Allocates and returns a new PNMWriter suitable for
121 // reading from this file type, if possible. If writing
122 // files of this type is not supported, returns NULL.
123 ////////////////////////////////////////////////////////////////////
125 make_writer(ostream *, bool) {
126  return NULL;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function: PNMFileType::init_pnm
131 // Access: Protected, Static
132 // Description: Initializes the underlying PNM library, if it has not
133 // already been initialized. This should be called by
134 // every implementation of make_reader() and
135 // make_writer(), to ensure that the library is properly
136 // initialized before any I/O is attempted.
137 ////////////////////////////////////////////////////////////////////
138 void PNMFileType::
139 init_pnm() {
140  if (!_did_init_pnm) {
141  _did_init_pnm = true;
142 
143  // No reason to do anything here nowadays.
144  }
145 }
146 
147 ////////////////////////////////////////////////////////////////////
148 // Function: PNMFileType::write_datagram
149 // Access: Public, Virtual
150 // Description: Fills the indicated datagram up with a binary
151 // representation of the current object, in preparation
152 // for writing to a Bam file.
153 //
154 // None of the particular PNMFileType objects store any
155 // extra data--at least, not yet--so we just define this
156 // up here to do nothing.
157 ////////////////////////////////////////////////////////////////////
158 void PNMFileType::
160 }
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
virtual string get_extension(int n) const
Returns the nth possible filename extension associated with this particular file type, without a leading dot.
Definition: pnmFileType.cxx:62
virtual PNMWriter * make_writer(ostream *file, bool owns_file=true)
Allocates and returns a new PNMWriter suitable for reading from this file type, if possible...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
virtual PNMReader * make_reader(istream *file, bool owns_file=true, const string &magic_number=string())
Allocates and returns a new PNMReader suitable for reading from this file type, if possible...
virtual bool matches_magic_number(const 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:31
This is an abstract base class that defines the interface for writing image files of various types...
Definition: pnmWriter.h:31
virtual bool has_magic_number() const
Returns true if this particular file type uses a magic number to identify it, false otherwise...
Definition: pnmFileType.cxx:89
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
virtual int get_num_extensions() const
Returns the number of different possible filename extensions associated with this particular file typ...
Definition: pnmFileType.cxx:50
virtual string get_suggested_extension() const
Returns a suitable filename extension (without a leading dot) to suggest for files of this type...
Definition: pnmFileType.cxx:75