diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.C b/src/fileFormats/vtk/format/foamVtkFormatter.C index b204ad22795410165c657f553ea44b8b63b52cff..7271dd22f5ebbee7037f5dd1484fd8b67ef5046c 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkFormatter.C @@ -116,7 +116,7 @@ Foam::foamVtkFormatter::openTag(const word& tag) Foam::foamVtkFormatter& -Foam::foamVtkFormatter::closeTag(bool isEmpty) +Foam::foamVtkFormatter::closeTag(const bool isEmpty) { if (!inTag_) { @@ -207,20 +207,23 @@ Foam::foamVtkFormatter& Foam::foamVtkFormatter::xmlAttr ( const word& k, - const label v, + const int32_t v, const char quote ) { - if (!inTag_) - { - WarningInFunction - << "xml attribute '" << k << "' but not within a tag!" - << endl; - } + return xmlAttribute(k, v, quote); +} - os_ << ' ' << k << '=' << quote << v << quote; - return *this; +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::xmlAttr +( + const word& k, + const int64_t v, + const char quote +) +{ + return xmlAttribute(k, v, quote); } @@ -232,16 +235,7 @@ Foam::foamVtkFormatter::xmlAttr const char quote ) { - if (!inTag_) - { - WarningInFunction - << "xml attribute '" << k << "' but not within a tag!" - << endl; - } - - os_ << ' ' << k << '=' << quote << v << quote; - - return *this; + return xmlAttribute(k, v, quote); } @@ -253,16 +247,7 @@ Foam::foamVtkFormatter::xmlAttr const char quote ) { - if (!inTag_) - { - WarningInFunction - << "xml attribute '" << k << "' but not within a tag!" - << endl; - } - - os_ << ' ' << k << '=' << quote << v << quote; - - return *this; + return xmlAttribute(k, v, quote); } @@ -283,7 +268,18 @@ Foam::foamVtkFormatter& Foam::foamVtkFormatter::operator() ( const word& k, - const label v + const int32_t v +) +{ + return xmlAttr(k, v); +} + + +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::operator() +( + const word& k, + const int64_t v ) { return xmlAttr(k, v); diff --git a/src/fileFormats/vtk/format/foamVtkFormatter.H b/src/fileFormats/vtk/format/foamVtkFormatter.H index 4fe0cb997773461de2a049b087af731126b359ee..65519b1955a0265fbd09154100be57124c111d69 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatter.H +++ b/src/fileFormats/vtk/format/foamVtkFormatter.H @@ -70,6 +70,16 @@ class foamVtkFormatter mutable bool inTag_; + //- Write XML attribute + template<class Type> + foamVtkFormatter& xmlAttribute + ( + const word&, + const Type&, + const char quote + ); + + protected: // Protected Member Functions @@ -113,9 +123,9 @@ public: virtual void writeSize(const uint64_t) = 0; virtual void write(const uint8_t) = 0; - virtual void write(const label) = 0; - virtual void write(const float) = 0; - virtual void write(const double) = 0; + virtual void write(const label) = 0; + virtual void write(const float) = 0; + virtual void write(const double) = 0; virtual void flush() = 0; @@ -136,7 +146,7 @@ public: //- Close XML tag, optional as an empty container. // Always adds a trailing newline. - foamVtkFormatter& closeTag(bool isEmpty = false); + foamVtkFormatter& closeTag(const bool isEmpty = false); //- End XML tag, optional with sanity check // Always adds a trailing newline. @@ -164,21 +174,28 @@ public: } - //- Write XML attribute foamVtkFormatter& xmlAttr ( const word&, const std::string&, - const char quote='\'' + const char quote = '\'' ); //- Write XML attribute foamVtkFormatter& xmlAttr ( const word&, - const label, - const char quote='\'' + const int32_t, + const char quote = '\'' + ); + + //- Write XML attribute + foamVtkFormatter& xmlAttr + ( + const word&, + const int64_t, + const char quote = '\'' ); //- Write XML attribute @@ -186,7 +203,7 @@ public: ( const word&, const uint64_t, - const char quote='\'' + const char quote = '\'' ); //- Write XML attribute @@ -194,7 +211,7 @@ public: ( const word&, const scalar, - const char quote='\'' + const char quote = '\'' ); @@ -205,7 +222,10 @@ public: foamVtkFormatter& operator()(const word&, const std::string&); //- Write XML attribute - foamVtkFormatter& operator()(const word&, const label); + foamVtkFormatter& operator()(const word&, const int32_t); + + //- Write XML attribute + foamVtkFormatter& operator()(const word&, const int64_t); //- Write XML attribute foamVtkFormatter& operator()(const word&, const uint64_t); diff --git a/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C b/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C index 6e0830e2b1fab52f022a8ef6cfd81dbf15581d03..1cde34a61e278147dca32ef073238687476c8672 100644 --- a/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C +++ b/src/fileFormats/vtk/format/foamVtkFormatterTemplates.C @@ -26,6 +26,28 @@ License // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // +template<class Type> +Foam::foamVtkFormatter& +Foam::foamVtkFormatter::xmlAttribute +( + const word& k, + const Type& v, + const char quote +) +{ + if (!inTag_) + { + WarningInFunction + << "xml attribute '" << k << "' but not within a tag!" + << endl; + } + + os_ << ' ' << k << '=' << quote << v << quote; + + return *this; +} + + template<class Type, int nComp> Foam::foamVtkFormatter& Foam::foamVtkFormatter::openDataArray ( diff --git a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C index 177249b306a84daf44531ffb39668beb836b9a0e..89525ab0baa0ebf2555548a517f0fce491d4c259 100644 --- a/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C +++ b/src/fileFormats/vtk/format/foamVtkLegacyFormatter.C @@ -77,8 +77,9 @@ void Foam::foamVtkLegacyFormatter::writeSize(const uint64_t) void Foam::foamVtkLegacyFormatter::write(const uint8_t val) { - // Can only handle integers - int copy(val); + // Legacy can only handle 32-bit integers. + // Nonetheless promote to 'label' (32 or 64 bit) and deal with it later + label copy(val); write(copy); }