From e06bf700958e5fdebafbdf5650140ea5821c33d6 Mon Sep 17 00:00:00 2001 From: mattijs Date: Tue, 16 Sep 2008 21:10:49 +0100 Subject: [PATCH] binary read/write --- src/OpenFOAM/meshes/boundBox/boundBox.C | 9 +- src/OpenFOAM/meshes/meshShapes/edge/edge.H | 3 + .../meshes/meshShapes/triFace/triFace.H | 3 + .../primitives/contiguous/contiguous.H | 95 ++++++++++++++++--- .../tools/labelledTri/labelledTri.H | 4 + .../tools/labelledTri/labelledTriI.H | 49 ++++++---- 6 files changed, 125 insertions(+), 38 deletions(-) diff --git a/src/OpenFOAM/meshes/boundBox/boundBox.C b/src/OpenFOAM/meshes/boundBox/boundBox.C index c87e552c85..a4b82f9dc4 100644 --- a/src/OpenFOAM/meshes/boundBox/boundBox.C +++ b/src/OpenFOAM/meshes/boundBox/boundBox.C @@ -79,10 +79,9 @@ boundBox::boundBox(const pointField& points, const bool doReduce) boundBox::boundBox(Istream& is) -: - min_(is), - max_(is) -{} +{ + operator>>(is, *this); +} // * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * // @@ -113,7 +112,7 @@ Istream& operator>>(Istream& is, boundBox& bb) { if (is.format() == IOstream::ASCII) { - return is >> bb.min_ >> bb.max_; + return is >> bb.min_ >> bb.max_; } else { diff --git a/src/OpenFOAM/meshes/meshShapes/edge/edge.H b/src/OpenFOAM/meshes/meshShapes/edge/edge.H index 4e481c24f1..8b37a9f3be 100644 --- a/src/OpenFOAM/meshes/meshShapes/edge/edge.H +++ b/src/OpenFOAM/meshes/meshShapes/edge/edge.H @@ -141,6 +141,9 @@ inline label Hash::operator()(const edge& e) const return e[0]*e[1] + e[0]+e[1]; } +template<> +inline bool contiguous() {return true;} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H index 38301fec58..48b79eebe4 100644 --- a/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H +++ b/src/OpenFOAM/meshes/meshShapes/triFace/triFace.H @@ -166,6 +166,9 @@ inline label Hash::operator()(const triFace& t) const return (t[0]*t[1]*t[2] + t[0]+t[1]+t[2]); } +template<> +inline bool contiguous() {return true;} + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/OpenFOAM/primitives/contiguous/contiguous.H b/src/OpenFOAM/primitives/contiguous/contiguous.H index d634bb0b60..59c206dd22 100644 --- a/src/OpenFOAM/primitives/contiguous/contiguous.H +++ b/src/OpenFOAM/primitives/contiguous/contiguous.H @@ -38,6 +38,8 @@ Description #ifndef contiguous_H #define contiguous_H +#include "label.H" + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam @@ -45,54 +47,117 @@ namespace Foam // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +// Forward declaration of friend functions and operators +template class FixedList; +template class Pair; + + // Assume the data associated with type T is not contiguous template inline bool contiguous() {return false;} -// Specify data associated with primitive types is contiguous + +// Specify data associated with primitive types (and simple fixed size +// containers - only size 2 defined here) is contiguous template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} template<> -inline bool contiguous() {return true;} +inline bool contiguous() {return true;} +template<> +inline bool contiguous >() {return true;} +template<> +inline bool contiguous >() {return true;} // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/triSurface/tools/labelledTri/labelledTri.H b/src/triSurface/tools/labelledTri/labelledTri.H index af61315d80..4470298e8e 100644 --- a/src/triSurface/tools/labelledTri/labelledTri.H +++ b/src/triSurface/tools/labelledTri/labelledTri.H @@ -105,6 +105,10 @@ public: }; +template<> +inline bool contiguous() {return true;} + + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam diff --git a/src/triSurface/tools/labelledTri/labelledTriI.H b/src/triSurface/tools/labelledTri/labelledTriI.H index 43195124ac..075b5b8205 100644 --- a/src/triSurface/tools/labelledTri/labelledTriI.H +++ b/src/triSurface/tools/labelledTri/labelledTriI.H @@ -58,16 +58,7 @@ inline labelledTri::labelledTri inline labelledTri::labelledTri(Istream& is) { - // Read beginning of labelledTri point pair - is.readBegin("labelledTri"); - - is >> static_cast(*this) >> region_; - - // Read end of labelledTri point pair - is.readEnd("labelledTri"); - - // Check state of Istream - is.check("labelledTri::labelledTri(Istream& is)"); + operator>>(is, *this); } @@ -88,13 +79,20 @@ inline label& labelledTri::region() inline Istream& operator>>(Istream& is, labelledTri& t) { - // Read beginning of labelledTri point pair - is.readBegin("labelledTri"); + if (is.format() == IOstream::ASCII) + { + // Read beginning of labelledTri point pair + is.readBegin("labelledTri"); - is >> static_cast(t) >> t.region_; + is >> static_cast(t) >> t.region_; - // Read end of labelledTri point pair - is.readEnd("labelledTri"); + // Read end of labelledTri point pair + is.readEnd("labelledTri"); + } + else + { + is.read(reinterpret_cast(&t), sizeof(labelledTri)); + } // Check state of Ostream is.check("Istream& operator>>(Istream&, labelledTri&)"); @@ -105,9 +103,24 @@ inline Istream& operator>>(Istream& is, labelledTri& t) inline Ostream& operator<<(Ostream& os, const labelledTri& t) { - os << token::BEGIN_LIST - << static_cast(t) << token::SPACE << t.region_ - << token::END_LIST; + if (os.format() == IOstream::ASCII) + { + os << token::BEGIN_LIST + << static_cast(t) << token::SPACE << t.region_ + << token::END_LIST; + } + else + { + os.write + ( + reinterpret_cast(&t), + sizeof(labelledTri) + ); + } + + // Check state of Ostream + os.check("Ostream& operator<<(Ostream&, const labelledTri&)"); + return os; }