Panda3D
xFile.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 xFile.h
10  * @author drose
11  * @date 2004-10-03
12  */
13 
14 #ifndef XFILE_H
15 #define XFILE_H
16 
17 #include "pandatoolbase.h"
18 #include "xFileNode.h"
19 #include "xFileDataNode.h"
20 #include "windowsGuid.h"
21 #include "filename.h"
22 #include "pmap.h"
23 #include "pointerTo.h"
24 
25 class XFileTemplate;
27 
28 /**
29  * This represents the complete contents of an X file (file.x) in memory. It
30  * may be read or written from or to a disk file.
31  */
32 class XFile : public XFileNode {
33 public:
34  XFile(bool keep_names=false);
35  ~XFile();
36 
37  virtual void clear();
38 
39  bool read(Filename filename);
40  bool read(std::istream &in, const std::string &filename = std::string());
41 
42  bool write(Filename filename) const;
43  bool write(std::ostream &out) const;
44 
45  XFileTemplate *find_template(const std::string &name) const;
46  XFileTemplate *find_template(const WindowsGuid &guid) const;
47 
48  static XFileTemplate *find_standard_template(const std::string &name);
50 
51  XFileDataNodeTemplate *find_data_object(const std::string &name) const;
53 
54  virtual void write_text(std::ostream &out, int indent_level) const;
55 
56  enum FormatType {
57  FT_text,
58  FT_binary,
59  FT_compressed,
60  };
61  enum FloatSize {
62  FS_32,
63  FS_64,
64  };
65 
66 private:
67  bool read_header(std::istream &in);
68  bool write_header(std::ostream &out) const;
69 
70  static const XFile *get_standard_templates();
71 
72  int _major_version, _minor_version;
73  FormatType _format_type;
74  FloatSize _float_size;
75  bool _keep_names;
76 
78  NodesByGuid _nodes_by_guid;
79 
80  static PT(XFile) _standard_templates;
81 
82 public:
83  static TypeHandle get_class_type() {
84  return _type_handle;
85  }
86  static void init_type() {
87  XFileNode::init_type();
88  register_type(_type_handle, "XFile",
89  XFileNode::get_class_type());
90  }
91  virtual TypeHandle get_type() const {
92  return get_class_type();
93  }
94  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
95 
96 private:
97  static TypeHandle _type_handle;
98 
99  friend class XFileNode;
100 };
101 
102 #include "xFile.I"
103 
104 #endif
windowsGuid.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pmap< WindowsGuid, XFileNode * >
register_type
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
xFileDataNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFile
This represents the complete contents of an X file (file.x) in memory.
Definition: xFile.h:32
filename.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileNode
A single node of an X file.
Definition: xFileNode.h:39
XFile::find_template
XFileTemplate * find_template(const std::string &name) const
Returns the template associated with the indicated name, if any, or NULL if none.
Definition: xFile.cxx:178
xFileNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
pmap.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
xFile.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
XFileTemplate
A template definition in the X file.
Definition: xFileTemplate.h:27
XFile::write
bool write(Filename filename) const
Opens the indicated filename for output and writes a parseable description of all the known distribut...
Definition: xFile.cxx:130
XFileDataNodeTemplate
This is a node which contains all of the data elements defined by a template.
Definition: xFileDataNodeTemplate.h:30
XFile::find_data_object
XFileDataNodeTemplate * find_data_object(const std::string &name) const
Returns the data object associated with the indicated name, if any, or NULL if none.
Definition: xFile.cxx:257
XFile::find_standard_template
static XFileTemplate * find_standard_template(const std::string &name)
Returns the standard template associated with the indicated name, if any, or NULL if none.
Definition: xFile.cxx:237
XFile::read
bool read(Filename filename)
Opens and reads the indicated .x file by name.
Definition: xFile.cxx:73
pandatoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
WindowsGuid
This is an implementation of the Windows GUID object, used everywhere as a world-unique identifier fo...
Definition: windowsGuid.h:26
Filename
The name of a file, such as a texture file or an Egg file.
Definition: filename.h:39
XFile::write_text
virtual void write_text(std::ostream &out, int indent_level) const
Writes a suitable representation of this node to an .x file in text mode.
Definition: xFile.cxx:287
XFile::clear
virtual void clear()
Removes all of the classes defined within the XFile and prepares it for reading a new file.
Definition: xFile.cxx:58