00001 // Filename: pnmFileType.cxx 00002 // Created by: drose (15Jun00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "pnmFileType.h" 00020 00021 #include <string_utils.h> 00022 #include <executionEnvironment.h> 00023 #include <bamReader.h> 00024 #include <bamWriter.h> 00025 00026 bool PNMFileType::_did_init_pnm = false; 00027 TypeHandle PNMFileType::_type_handle; 00028 00029 //////////////////////////////////////////////////////////////////// 00030 // Function: PNMFileType::Constructor 00031 // Access: Protected 00032 // Description: 00033 //////////////////////////////////////////////////////////////////// 00034 PNMFileType:: 00035 PNMFileType() { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: PNMFileType::Destructor 00040 // Access: Public, Virtual 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 PNMFileType:: 00044 ~PNMFileType() { 00045 } 00046 00047 //////////////////////////////////////////////////////////////////// 00048 // Function: PNMFileType::get_num_extensions 00049 // Access: Public, Virtual 00050 // Description: Returns the number of different possible filename 00051 // extensions associated with this particular file type. 00052 //////////////////////////////////////////////////////////////////// 00053 int PNMFileType:: 00054 get_num_extensions() const { 00055 return 0; 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: PNMFileType::get_extension 00060 // Access: Public, Virtual 00061 // Description: Returns the nth possible filename extension 00062 // associated with this particular file type, without a 00063 // leading dot. 00064 //////////////////////////////////////////////////////////////////// 00065 string PNMFileType:: 00066 get_extension(int) const { 00067 nassertr(false, string()); 00068 return string(); 00069 } 00070 00071 //////////////////////////////////////////////////////////////////// 00072 // Function: PNMFileType::get_suggested_extension 00073 // Access: Public, Virtual 00074 // Description: Returns a suitable filename extension (without a 00075 // leading dot) to suggest for files of this type, or 00076 // empty string if no suggestions are available. 00077 //////////////////////////////////////////////////////////////////// 00078 string PNMFileType:: 00079 get_suggested_extension() const { 00080 if (get_num_extensions() > 0) { 00081 return get_extension(0); 00082 } 00083 return string(); 00084 } 00085 00086 //////////////////////////////////////////////////////////////////// 00087 // Function: PNMFileType::has_magic_number 00088 // Access: Public, Virtual 00089 // Description: Returns true if this particular file type uses a 00090 // magic number to identify it, false otherwise. 00091 //////////////////////////////////////////////////////////////////// 00092 bool PNMFileType:: 00093 has_magic_number() const { 00094 return false; 00095 } 00096 00097 //////////////////////////////////////////////////////////////////// 00098 // Function: PNMFileType::matches_magic_number 00099 // Access: Public, Virtual 00100 // Description: Returns true if the indicated "magic number" byte 00101 // stream (the initial few bytes read from the file) 00102 // matches this particular file type, false otherwise. 00103 //////////////////////////////////////////////////////////////////// 00104 bool PNMFileType:: 00105 matches_magic_number(const string &) const { 00106 return false; 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: PNMFileType::make_reader 00111 // Access: Public, Virtual 00112 // Description: Allocates and returns a new PNMReader suitable for 00113 // reading from this file type, if possible. If reading 00114 // from this file type is not supported, returns NULL. 00115 //////////////////////////////////////////////////////////////////// 00116 PNMReader *PNMFileType:: 00117 make_reader(istream *, bool, const string &) { 00118 return NULL; 00119 } 00120 00121 //////////////////////////////////////////////////////////////////// 00122 // Function: PNMFileType::make_writer 00123 // Access: Public, Virtual 00124 // Description: Allocates and returns a new PNMWriter suitable for 00125 // reading from this file type, if possible. If writing 00126 // files of this type is not supported, returns NULL. 00127 //////////////////////////////////////////////////////////////////// 00128 PNMWriter *PNMFileType:: 00129 make_writer(ostream *, bool) { 00130 return NULL; 00131 } 00132 00133 //////////////////////////////////////////////////////////////////// 00134 // Function: PNMFileType::init_pnm 00135 // Access: Protected, Static 00136 // Description: Initializes the underlying PNM library, if it has not 00137 // already been initialized. This should be called by 00138 // every implementation of make_reader() and 00139 // make_writer(), to ensure that the library is properly 00140 // initialized before any I/O is attempted. 00141 //////////////////////////////////////////////////////////////////// 00142 void PNMFileType:: 00143 init_pnm() { 00144 if (!_did_init_pnm) { 00145 _did_init_pnm = true; 00146 00147 // No reason to do anything here nowadays. 00148 /* 00149 00150 // Make an argc/argv style copy of the ExecutionEnvironment's 00151 // args. We do this because pm_init() might attempt to change 00152 // this (for instance, to remove arguments it finds). 00153 00154 int argc = ExecutionEnvironment::get_num_args() + 1; 00155 char **argv = new char *[argc + 1]; 00156 argv[0] = strdup(ExecutionEnvironment::get_binary_name().c_str()); 00157 int i; 00158 for (i = 1; i < argc; i++) { 00159 argv[i] = strdup(ExecutionEnvironment::get_arg(i - 1).c_str()); 00160 } 00161 argv[argc] = (char *)NULL; 00162 00163 pm_init(&argc, argv); 00164 00165 // We can delete the argv array itself, but we cannot free the 00166 // results of the strdup() calls we just made, since the pnm 00167 // library might keep pointers to it. But this is a one-time 00168 // leak. 00169 delete[] argv; 00170 00171 */ 00172 } 00173 } 00174 00175 //////////////////////////////////////////////////////////////////// 00176 // Function: PNMFileType::write_datagram 00177 // Access: Public, Virtual 00178 // Description: Fills the indicated datagram up with a binary 00179 // representation of the current object, in preparation 00180 // for writing to a Bam file. 00181 // 00182 // None of the particular PNMFileType objects store any 00183 // extra data--at least, not yet--so we just define this 00184 // up here to do nothing. 00185 //////////////////////////////////////////////////////////////////// 00186 void PNMFileType:: 00187 write_datagram(BamWriter *, Datagram &) { 00188 }