Panda3D
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 
24 class PNMReader;
25 class PNMWriter;
26 class 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  */
32 class EXPCL_PANDA_PNMIMAGE PNMFileType : public TypedWritable {
33 protected:
34  PNMFileType();
35 
36 public:
37  virtual ~PNMFileType();
38 
39 PUBLISHED:
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 
51 public:
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 
59 protected:
60  static void init_pnm();
61 
62 private:
63  static bool _did_init_pnm;
64 
65 
66  // The TypedWritable interface follows.
67 public:
68  static void register_with_read_factory();
69  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
70 
71 protected:
72  static TypedWritable *make_PNMFileType(const FactoryParams &params);
73 
74 public:
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 
88 private:
89  static TypeHandle _type_handle;
90 };
91 
92 #endif
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
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:36
This is the base class of a family of classes that represent particular image file types that PNMImag...
Definition: pnmFileType.h:32
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
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:35
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(),...
Definition: register_type.I:22
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.