Browse Source

Added cpp code for stream io

Hugh Sanderson 16 years ago
parent
commit
9f2c2a76ef
2 changed files with 14 additions and 0 deletions
  1. 7 0
      std/haxe/io/Input.hx
  2. 7 0
      std/haxe/io/Output.hx

+ 7 - 0
std/haxe/io/Input.hx

@@ -141,6 +141,8 @@ class Input {
 	public function readFloat() : Float {
 		#if neko
 			return _float_of_bytes(untyped read(4).b,bigEndian);
+		#elseif cpp
+			return _float_of_bytes(read(4).getData(),bigEndian);
 		#elseif php
 			var a = untyped __call__('unpack', 'f', readString(4));
 			return a[1];
@@ -153,6 +155,8 @@ class Input {
 	public function readDouble() : Float {
 		#if neko
 			return _double_of_bytes(untyped read(8).b,bigEndian);
+		#elseif cpp
+			return _double_of_bytes(read(8).getData(),bigEndian);
 		#elseif php
 			var a = untyped __call__('unpack', 'd', readString(8));
 			return a[1];
@@ -251,6 +255,9 @@ class Input {
 	static function __init__() untyped {
 		Input.prototype.bigEndian = false;
 	}
+#elseif cpp
+	static var _float_of_bytes = cpp.Lib.load("std","float_of_bytes",2);
+	static var _double_of_bytes = cpp.Lib.load("std","double_of_bytes",2);
 #end
 
 }

+ 7 - 0
std/haxe/io/Output.hx

@@ -96,6 +96,8 @@ class Output {
 	public function writeFloat( x : Float ) {
 		#if neko
 		write(untyped new Bytes(4,_float_bytes(x,bigEndian)));
+		#elseif cpp
+		write(Bytes.ofData(_float_bytes(x,bigEndian)));
 		#elseif php
 		write(untyped Bytes.ofString(__call__('pack', 'f', x)));
 		#else
@@ -106,6 +108,8 @@ class Output {
 	public function writeDouble( x : Float ) {
 		#if neko
 		write(untyped new Bytes(8,_double_bytes(x,bigEndian)));
+		#elseif cpp
+		write(Bytes.ofData(_double_bytes(x,bigEndian)));
 		#elseif php
 		write(untyped Bytes.ofString(__call__('pack', 'd', x)));
 		#else
@@ -245,6 +249,9 @@ class Output {
 	static function __init__() untyped {
 		Output.prototype.bigEndian = false;
 	}
+#elseif cpp
+	static var _float_bytes = cpp.Lib.load("std","float_bytes",2);
+	static var _double_bytes = cpp.Lib.load("std","double_bytes",2);
 #end
 
 }