Skip to content
Snippets Groups Projects
Commit 801076f8 authored by Mark Olesen's avatar Mark Olesen
Browse files

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
parent 2cc23a23
No related merge requests found
......@@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2016 OpenCFD Ltd.
\\ / A nd | Copyright (C) 2016-2017 OpenCFD Ltd.
\\/ M anipulation |
-------------------------------------------------------------------------------
License
......@@ -62,14 +62,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile
vtmFile
.xmlHeader()
.openTag("VTKFile")
( "type", content )
( "version", "1.0" )
( "byte_order", foamVtkFormatter::byteOrder )
( "header_type", foamVtkFormatter::headerType )
.closeTag();
vtmFile.tag(content);
.beginVTKFile(content, "1.0");
forAll(files, i)
{
......@@ -80,7 +73,7 @@ Foam::label Foam::foamVtkOutput::writeVtmFile
.closeTag(true);
}
vtmFile.endTag(content).endTag("VTKFile");
vtmFile.endTag(content).endVTKFile();
return files.size();
}
......
......@@ -58,6 +58,12 @@ class foamVtkOutput
public:
// Public typedefs
//- Use UInt64 for header data
typedef foamVtkFormatter::headerType headerType;
// Forward declarations
class legacy;
......
......@@ -23,16 +23,6 @@ License
\*---------------------------------------------------------------------------*/
#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 * * * * * * * * * * * * * * //
......@@ -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::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::xmlAttr
(
......@@ -258,55 +285,35 @@ Foam::foamVtkFormatter::xmlAttr
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator()
(
const word& k,
const std::string& v
)
Foam::foamVtkFormatter::operator()(const word& k, const std::string& v)
{
return xmlAttr(k, v);
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator()
(
const word& k,
const int32_t v
)
Foam::foamVtkFormatter::operator()(const word& k, const int32_t v)
{
return xmlAttr(k, v);
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator()
(
const word& k,
const int64_t v
)
Foam::foamVtkFormatter::operator()(const word& k, const int64_t v)
{
return xmlAttr(k, v);
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator()
(
const word& k,
const uint64_t v
)
Foam::foamVtkFormatter::operator()(const word& k, const uint64_t v)
{
return xmlAttr(k, v);
}
Foam::foamVtkFormatter&
Foam::foamVtkFormatter::operator()
(
const word& k,
const scalar v
)
Foam::foamVtkFormatter::operator()(const word& k, const scalar v)
{
return xmlAttr(k, v);
}
......
......@@ -89,13 +89,10 @@ protected:
public:
// Static Data
// Public typedefs
//- VTK name for the 'byte_order' attribute
static const char* const byteOrder;
//- VTK name for the 'header_type' attribute (UInt64)
static const char* const headerType;
//- Use UInt64 for header data
typedef uint64_t headerType;
//- Destructor
......@@ -161,6 +158,20 @@ public:
//- Write XML tag without any attributes. Combines openTag/closeTag.
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
template<class Type, int nComp=0>
......@@ -174,11 +185,25 @@ public:
//- End "DataArray" XML tag
foamVtkFormatter& endDataArray()
inline foamVtkFormatter& endDataArray()
{
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
foamVtkFormatter& xmlAttr
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment