Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Diff of /trunk/MMix/MMix.Machine/BinaryWriter.hpp [000000] .. [r1] Maximize Restore

  Switch to side-by-side view

--- a
+++ b/trunk/MMix/MMix.Machine/BinaryWriter.hpp
@@ -0,0 +1,68 @@
+#ifndef MMIX_MACHINE_BINARYWRITER_INCLUDED
+#define MMIX_MACHINE_BINARYWRITER_INCLUDED
+#include <MMix.Machine/Type.hpp>
+#include <fstream>
+#include <vector>
+
+namespace MMix { namespace Machine {
+
+class BinaryWriter
+{
+public:
+    BinaryWriter(const String& fileName_, Octa& loc_, Octa& oloc_);
+    ~BinaryWriter();
+    Octa Loc() const { return loc; }
+    Octa FileLoc() const { return floc; }
+    void Emit(Octa o);
+    void Emit(Tetra t);
+    void Emit(Wyde w);
+    void Emit(Byte b)
+    {
+        Put(b);
+        ++loc;
+    }
+    void Put(Octa o);
+    void Put(Tetra t);
+    void Put(Wyde w)
+    {
+        Put(w.GetByte(0));
+        Put(w.GetByte(1));
+    }
+    void Put(Byte b) 
+    {
+        Write(b);
+        ++oloc;
+    }
+    void Write(Octa o);
+    void Write(Tetra t);
+    void Write(Wyde w)
+    {
+        Write(w.GetByte(0));
+        Write(w.GetByte(1));
+    }
+    void Write(Byte b)
+    {
+        if (bufpos >= bufsize)
+        {
+            Flush();
+        }
+        buffer[bufpos++] = b;
+        ++floc;
+    }
+    void Write(const String& s);
+    void Flush();
+    void Align(int alignment);
+private:
+    Octa& loc;
+    Octa& oloc;
+    Octa floc;
+    String fileName;
+    std::ofstream file;
+    std::vector<Byte> buffer;
+    int bufpos;
+    int bufsize;
+};
+
+} } // namespace MMix::Machine
+
+#endif // MMIX_MACHINE_BINARYWRITER_INCLUDED