00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef XFILE_H
00016 #define XFILE_H
00017
00018 #include "pandatoolbase.h"
00019 #include "xFileNode.h"
00020 #include "xFileDataNode.h"
00021 #include "windowsGuid.h"
00022 #include "filename.h"
00023 #include "pmap.h"
00024 #include "pointerTo.h"
00025
00026 class XFileTemplate;
00027 class XFileDataNodeTemplate;
00028
00029
00030
00031
00032
00033
00034
00035 class XFile : public XFileNode {
00036 public:
00037 XFile(bool keep_names=false);
00038 ~XFile();
00039
00040 virtual void clear();
00041
00042 bool read(Filename filename);
00043 bool read(istream &in, const string &filename = string());
00044
00045 bool write(Filename filename) const;
00046 bool write(ostream &out) const;
00047
00048 XFileTemplate *find_template(const string &name) const;
00049 XFileTemplate *find_template(const WindowsGuid &guid) const;
00050
00051 static XFileTemplate *find_standard_template(const string &name);
00052 static XFileTemplate *find_standard_template(const WindowsGuid &guid);
00053
00054 XFileDataNodeTemplate *find_data_object(const string &name) const;
00055 XFileDataNodeTemplate *find_data_object(const WindowsGuid &guid) const;
00056
00057 virtual void write_text(ostream &out, int indent_level) const;
00058
00059 enum FormatType {
00060 FT_text,
00061 FT_binary,
00062 FT_compressed,
00063 };
00064 enum FloatSize {
00065 FS_32,
00066 FS_64,
00067 };
00068
00069 private:
00070 bool read_header(istream &in);
00071 bool write_header(ostream &out) const;
00072
00073 static const XFile *get_standard_templates();
00074
00075 int _major_version, _minor_version;
00076 FormatType _format_type;
00077 FloatSize _float_size;
00078 bool _keep_names;
00079
00080 typedef pmap<WindowsGuid, XFileNode *> NodesByGuid;
00081 NodesByGuid _nodes_by_guid;
00082
00083 static PT(XFile) _standard_templates;
00084
00085 public:
00086 static TypeHandle get_class_type() {
00087 return _type_handle;
00088 }
00089 static void init_type() {
00090 XFileNode::init_type();
00091 register_type(_type_handle, "XFile",
00092 XFileNode::get_class_type());
00093 }
00094 virtual TypeHandle get_type() const {
00095 return get_class_type();
00096 }
00097 virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00098
00099 private:
00100 static TypeHandle _type_handle;
00101
00102 friend class XFileNode;
00103 };
00104
00105 #include "xFile.I"
00106
00107 #endif
00108
00109