Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

WDFFile.h

00001 /*
00002   File: WDFFile.h
00003 
00004   Copyright(C) C. Kotterink, Computed Graphics
00005 */
00006 #ifndef WDFFILE_H
00007 #define WDFFILE_H
00008 
00009 #include<File.h>
00010 #include<Material.h>
00011 #include<Vertex3.h>
00012 #include<Color4.h>
00013 
00014 #include<wdf.h>
00015 #include<stack>
00016 #include<map>
00017 
00020 class WDFFile : public File
00021 {
00022 public:
00025     class Chunk
00026     {
00027         friend WDFFile;
00028     public:
00029         Chunk() {}
00030         Chunk(uint16 chunk) {
00031             id = chunk;
00032             next = 0;
00033         }
00034         uint16 getId() {
00035             return id;
00036         }
00037         bool operator ==(uint16 chunk) {
00038             return chunk == id;
00039         }
00040         bool operator !=(uint16 chunk) {
00041             return chunk != id;
00042         }
00043         bool last() {
00044             return (next == 0);
00045         }
00046     private:
00047         uint16 id;
00048         uint32 next;
00049     };
00050 
00051     WDFFile();
00052     ~WDFFile();
00053 
00054     WDFFile(const string &name);
00055     uint16 getVersion() {
00056         return version;
00057     }
00058     // Reading
00059     void read(Chunk &ch);
00060     bool readNext(Chunk &chunk);
00061     Vertex3 readVertex();
00062     Color4 readColor();
00063     RefMaterial readMaterial(uint16 type);
00064 
00065     // Writing
00066     void writeChunk(uint16 chunkId);
00067     void openChunk() {
00068         chunkStack.push(0);
00069     }
00070     void closeChunk() {
00071         // Chunk chains are always closed, so its is save to pop the stack
00072         chunkStack.pop();
00073     }
00074     void writeVertex(const Vertex3 &v);
00075     void writeColor(const Color4 &c);
00076     void writeMaterial(RefMaterial &material);
00077 
00078     // File
00079     void open(const string &name);
00080     void create(const string &name);
00081 
00082 protected:
00083     typedef File super;
00084     typedef stack<uint32> ChukStack;
00085     typedef map<Material*, uint16> MaterialID;
00086     typedef map<uint16, RefMaterial> MaterialPool;
00087     static const uint16 latestVersion;
00088 
00089     void write(Chunk &ch);
00090 
00091     uint16 version;
00092     bool reading;
00093 
00094     // Stack containing positions of chunks
00095     //   for writing: A stack of previous pointers
00096     //   for reading: A stack of next-pointers
00097     ChukStack chunkStack;
00098 
00099     // Material pools
00100     MaterialID materialId;          // for writing
00101     MaterialPool materialPool;      // for reading
00102 };
00103 #endif

This documentation was generated using doxygen. If you have any comments or additions please mail me.