ENH: adjust header management for foamVtk output

- provide headerType typedef in foamVtkFormatter, foamVtkOutput

- remove byteOrder and headerType constants from foamVtkFormatter
  since the same strings can also be obtained from foamVtkPTraits

- additional convenience methods in foamVtkFormatter
This commit is contained in:
Mark Olesen
2017-01-17 10:14:15 +01:00
parent 2cc23a23e7
commit 801076f8d0
4 changed files with 93 additions and 62 deletions

View File

@ -2,7 +2,7 @@
========= | ========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | \\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation | \\/ M anipulation |
------------------------------------------------------------------------------- -------------------------------------------------------------------------------
License License
@ -62,14 +62,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile
vtmFile vtmFile
.xmlHeader() .xmlHeader()
.openTag("VTKFile") .beginVTKFile(content, "1.0");
( "type", content )
( "version", "1.0" )
( "byte_order", foamVtkFormatter::byteOrder )
( "header_type", foamVtkFormatter::headerType )
.closeTag();
vtmFile.tag(content);
forAll(files, i) forAll(files, i)
{ {
@ -80,7 +73,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile
.closeTag(true); .closeTag(true);
} }
vtmFile.endTag(content).endTag("VTKFile"); vtmFile.endTag(content).endVTKFile();
return files.size(); return files.size();
} }

View File

@ -58,6 +58,12 @@ class foamVtkOutput
public: public:
// Public typedefs
//- Use UInt64 for header data
typedef foamVtkFormatter::headerType headerType;
// Forward declarations // Forward declarations
class legacy; class legacy;

View File

@ -23,16 +23,6 @@ License
\*---------------------------------------------------------------------------*/ \*---------------------------------------------------------------------------*/
#include "foamVtkFormatter.H" #include "foamVtkFormatter.H"
#include "foamVtkPTraits.H"
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
const char* const Foam::foamVtkFormatter::byteOrder
= Foam::foamVtkPTraits<endian>::typeName;
const char* const Foam::foamVtkFormatter::headerType =
Foam::foamVtkPTraits<uint64_t>::typeName;
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
@ -145,16 +135,6 @@ Foam::foamVtkFormatter::closeTag(const bool isEmpty)
} }
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::tag(const word& tag)
{
openTag(tag);
closeTag();
return *this;
}
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::endTag(const word& tag) Foam::foamVtkFormatter::endTag(const word& tag)
{ {
@ -186,6 +166,53 @@ Foam::foamVtkFormatter::endTag(const word& tag)
} }
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::tag(const word& tag)
{
openTag(tag);
closeTag();
return *this;
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::beginVTKFile
(
const word& contentType,
const word& contentVersion,
const bool leaveOpen
)
{
openTag("VTKFile");
xmlAttr("type", contentType);
xmlAttr("version", contentVersion);
xmlAttr("byte_order", foamVtkPTraits<Foam::endian>::typeName);
xmlAttr("header_type", foamVtkPTraits<headerType>::typeName);
closeTag();
openTag(contentType);
if (!leaveOpen)
{
closeTag();
}
return *this;
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::beginAppendedData()
{
openTag("AppendedData");
xmlAttr("encoding", encoding());
closeTag();
os_ << '_';
return *this;
}
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::xmlAttr Foam::foamVtkFormatter::xmlAttr
( (
@ -258,55 +285,35 @@ Foam::foamVtkFormatter::xmlAttr
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator() Foam::foamVtkFormatter::operator()(const word& k, const std::string& v)
(
const word& k,
const std::string& v
)
{ {
return xmlAttr(k, v); return xmlAttr(k, v);
} }
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator() Foam::foamVtkFormatter::operator()(const word& k, const int32_t v)
(
const word& k,
const int32_t v
)
{ {
return xmlAttr(k, v); return xmlAttr(k, v);
} }
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator() Foam::foamVtkFormatter::operator()(const word& k, const int64_t v)
(
const word& k,
const int64_t v
)
{ {
return xmlAttr(k, v); return xmlAttr(k, v);
} }
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator() Foam::foamVtkFormatter::operator()(const word& k, const uint64_t v)
(
const word& k,
const uint64_t v
)
{ {
return xmlAttr(k, v); return xmlAttr(k, v);
} }
Foam::foamVtkFormatter& Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator() Foam::foamVtkFormatter::operator()(const word& k, const scalar v)
(
const word& k,
const scalar v
)
{ {
return xmlAttr(k, v); return xmlAttr(k, v);
} }

View File

@ -89,13 +89,10 @@ protected:
public: public:
// Static Data // Public typedefs
//- VTK name for the 'byte_order' attribute //- Use UInt64 for header data
static const char* const byteOrder; typedef uint64_t headerType;
//- VTK name for the 'header_type' attribute (UInt64)
static const char* const headerType;
//- Destructor //- Destructor
@ -161,6 +158,20 @@ public:
//- Write XML tag without any attributes. Combines openTag/closeTag. //- Write XML tag without any attributes. Combines openTag/closeTag.
foamVtkFormatter& tag(const word& tag); foamVtkFormatter& tag(const word& tag);
//- Add a "VTKFile" XML tag for contentType, followed by a tag for
// the contentType itself. Optionally leave the contentType tag
// open for adding additional attributes.
foamVtkFormatter& beginVTKFile
(
const word& contentType,
const word& contentVersion,
const bool leaveOpen = false
);
//- Add a "AppendedData" XML tag with the current encoding and output
// the requisite '_' prefix.
foamVtkFormatter& beginAppendedData();
//- Open "DataArray" XML tag //- Open "DataArray" XML tag
template<class Type, int nComp=0> template<class Type, int nComp=0>
@ -174,11 +185,25 @@ public:
//- End "DataArray" XML tag //- End "DataArray" XML tag
foamVtkFormatter& endDataArray() inline foamVtkFormatter& endDataArray()
{ {
return endTag("DataArray"); return endTag("DataArray");
} }
//- End "AppendedData" XML tag
inline foamVtkFormatter& endAppendedData()
{
flush(); // flush any pending encoded content
os_ << '\n'; // clear separation from content.
return endTag("AppendedData");
}
//- End "VTKFile" XML tag
inline foamVtkFormatter& endVTKFile()
{
return endTag("VTKFile");
}
//- Write XML attribute //- Write XML attribute
foamVtkFormatter& xmlAttr foamVtkFormatter& xmlAttr