summaryrefslogtreecommitdiff
path: root/binparse/parse.cpp
diff options
context:
space:
mode:
authorDennis Brentjes <d.brentjes@gmail.com>2016-07-05 17:51:21 +0200
committerDennis Brentjes <d.brentjes@gmail.com>2016-07-05 17:51:21 +0200
commit06336eaddcc6a8f9cc578d8f059117c3aa535c9f (patch)
tree4884cc68161df06112a49a04007fa6d03775d507 /binparse/parse.cpp
parentb80a82fcc9edc73057796005cede4eea8380e193 (diff)
downloadopenwar-06336eaddcc6a8f9cc578d8f059117c3aa535c9f.tar.gz
openwar-06336eaddcc6a8f9cc578d8f059117c3aa535c9f.tar.bz2
openwar-06336eaddcc6a8f9cc578d8f059117c3aa535c9f.zip
Made the interface somewhat more consistant.
Diffstat (limited to 'binparse/parse.cpp')
-rw-r--r--binparse/parse.cpp35
1 files changed, 20 insertions, 15 deletions
diff --git a/binparse/parse.cpp b/binparse/parse.cpp
index a26e72e..de0f04d 100644
--- a/binparse/parse.cpp
+++ b/binparse/parse.cpp
@@ -80,6 +80,12 @@ Offset16 parse<Offset16>(std::istream& is, std::string name) {
}
template<>
+Value24 parse<Value24>(std::istream& is, std::__cxx11::string name)
+{
+ return Value24(parse<std::array<uint8_t, 3>>(is, name));
+}
+
+template<>
Value32 parse<Value32>(std::istream& is, std::string name) {
return Value32(parse<uint32_t>(is, name));
}
@@ -97,13 +103,13 @@ PString8 parse<PString8>(std::istream& is, std::string name) {
return PString8(std::string(data.begin(), data.end()));
}
-template<>
-std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name) {
+template<typename T, unsigned int N>
+std::array<T, N> parse(std::istream& is, std::string name) {
if(!is) {
throw UnexpectedEOS();
}
- std::array<uint8_t, 8> buffer;
+ std::array<T, N> buffer;
is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
if(!is) {
@@ -114,19 +120,18 @@ std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::stri
}
template<>
+std::array<uint8_t, 3> parse<std::array<uint8_t, 3>>(std::istream& is, std::string name) {
+ return parse<uint8_t, 3>(is, name);
+}
+
+template<>
+std::array<uint8_t, 8> parse<std::array<uint8_t, 8>>(std::istream& is, std::string name) {
+ return parse<uint8_t, 8>(is, name);
+}
+
+template<>
std::array<uint8_t, 22> parse<std::array<uint8_t, 22>>(std::istream& is, std::string name) {
- if(!is) {
- throw UnexpectedEOS();
- }
-
- std::array<uint8_t, 22> buffer;
- is.read(reinterpret_cast<char*>(buffer.data()), buffer.size());
-
- if(!is) {
- throw UnexpectedEOS(name);
- }
-
- return buffer;
+ return parse<uint8_t, 22>(is, name);
}
void dump_bytes(std::istream& is, std::vector<uint8_t>& buffer, std::string name)