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

@ -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);
}

View File

@ -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