Panda3D
Loading...
Searching...
No Matches
pnmFileType.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 pnmFileType.h
10 * @author drose
11 * @date 2000-06-15
12 */
13
14#ifndef PNMFILETYPE_H
15#define PNMFILETYPE_H
16
17#include "pandabase.h"
18
19#include "pnmimage_base.h"
20
21#include "typedObject.h"
22#include "typedWritable.h"
23
24class PNMReader;
25class PNMWriter;
26class FactoryParams;
27
28/**
29 * This is the base class of a family of classes that represent particular
30 * image file types that PNMImage supports.
31 */
32class EXPCL_PANDA_PNMIMAGE PNMFileType : public TypedWritable {
33protected:
34 PNMFileType();
35
36public:
37 virtual ~PNMFileType();
38
39PUBLISHED:
40 virtual std::string get_name() const=0;
41
42 virtual int get_num_extensions() const;
43 virtual std::string get_extension(int n) const;
44 MAKE_SEQ(get_extensions, get_num_extensions, get_extension);
45 virtual std::string get_suggested_extension() const;
46
47 MAKE_PROPERTY(name, get_name);
48 MAKE_SEQ_PROPERTY(extensions, get_num_extensions, get_extension);
49 MAKE_PROPERTY(suggested_extension, get_suggested_extension);
50
51public:
52 virtual bool has_magic_number() const;
53 virtual bool matches_magic_number(const std::string &magic_number) const;
54
55 virtual PNMReader *make_reader(std::istream *file, bool owns_file = true,
56 const std::string &magic_number = std::string());
57 virtual PNMWriter *make_writer(std::ostream *file, bool owns_file = true);
58
59protected:
60 static void init_pnm();
61
62private:
63 static bool _did_init_pnm;
64
65
66 // The TypedWritable interface follows.
67public:
68 static void register_with_read_factory();
69 virtual void write_datagram(BamWriter *writer, Datagram &datagram);
70
71protected:
72 static TypedWritable *make_PNMFileType(const FactoryParams &params);
73
74public:
75 static TypeHandle get_class_type() {
76 return _type_handle;
77 }
78 static void init_type() {
79 TypedWritable::init_type();
80 register_type(_type_handle, "PNMFileType",
81 TypedWritable::get_class_type());
82 }
83 virtual TypeHandle get_type() const {
84 return get_class_type();
85 }
86 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
87
88private:
89 static TypeHandle _type_handle;
90};
91
92#endif
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition datagram.h:38
An instance of this class is passed to the Factory when requesting it to do its business and construc...
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 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
virtual void write_datagram(BamWriter *manager, Datagram &dg)
Writes the contents of this object to the datagram for shipping out to a Bam file.
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(),...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.