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