summaryrefslogtreecommitdiff
path: root/src/endian_str.cpp
diff options
context:
space:
mode:
authorljfa-ag <ljfa-ag@web.de>2015-07-28 20:03:40 +0200
committerljfa-ag <ljfa-ag@web.de>2015-07-28 20:27:02 +0200
commit9d4d2455a4a562f0883c73ec8e87c469d38069e5 (patch)
treed49e23043c3dcf731202b0be9f8b01c96d62dc3a /src/endian_str.cpp
parent1d51c9a541361693e5d7113f8bef47c63a246436 (diff)
downloadProject-Tick-9d4d2455a4a562f0883c73ec8e87c469d38069e5.tar.gz
Project-Tick-9d4d2455a4a562f0883c73ec8e87c469d38069e5.zip
Implement endian stream i/o for double
Diffstat (limited to 'src/endian_str.cpp')
-rw-r--r--src/endian_str.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/endian_str.cpp b/src/endian_str.cpp
index 15aaa36a3f..bc2f4b149c 100644
--- a/src/endian_str.cpp
+++ b/src/endian_str.cpp
@@ -43,8 +43,22 @@ namespace //anonymous
memcpy(&ret, &f, 4);
return ret;
}
+
+ void pun_int_to_double(double& d, uint64_t i)
+ {
+ memcpy(&d, &i, 8);
+ }
+
+ uint64_t pun_double_to_int(double f)
+ {
+ uint64_t ret;
+ memcpy(&ret, &f, 8);
+ return ret;
+ }
}
+//------------------------------------------------------------------------------
+
void read_little(std::istream& is, uint8_t& x)
{
is.get(reinterpret_cast<char&>(x));
@@ -94,6 +108,13 @@ void read_little(std::istream& is, float& x)
pun_int_to_float(x, tmp);
}
+void read_little(std::istream& is, double& x)
+{
+ uint64_t tmp;
+ read_little(is, tmp);
+ pun_int_to_double(x, tmp);
+}
+
//------------------------------------------------------------------------------
void read_big(std::istream& is, uint8_t& x)
@@ -145,6 +166,13 @@ void read_big(std::istream& is, float& x)
pun_int_to_float(x, tmp);
}
+void read_big(std::istream& is, double& x)
+{
+ uint64_t tmp;
+ read_big(is, tmp);
+ pun_int_to_double(x, tmp);
+}
+
//------------------------------------------------------------------------------
void write_little(std::ostream& os, uint8_t x)
@@ -194,6 +222,11 @@ void write_little(std::ostream& os, float x)
write_little(os, pun_float_to_int(x));
}
+void write_little(std::ostream& os, double x)
+{
+ write_little(os, pun_double_to_int(x));
+}
+
//------------------------------------------------------------------------------
void write_big(std::ostream& os, uint8_t x)
@@ -243,4 +276,9 @@ void write_big(std::ostream& os, float x)
write_big(os, pun_float_to_int(x));
}
+void write_big(std::ostream& os, double x)
+{
+ write_big(os, pun_double_to_int(x));
+}
+
}