/*---------------------------------------------------------------------------*\ ========= | \\ / F ield | OpenFOAM: The Open Source CFD Toolbox \\ / O peration | \\ / A nd | Copyright (C) 2016 OpenCFD Ltd. \\/ M anipulation | ------------------------------------------------------------------------------- License This file is part of OpenFOAM. OpenFOAM is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OpenFOAM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenFOAM. If not, see . \*---------------------------------------------------------------------------*/ #include "foamVtkOutputOptions.H" #include "foamVtkAppendBase64Formatter.H" #include "foamVtkAppendRawFormatter.H" #include "foamVtkAsciiFormatter.H" #include "foamVtkBase64Formatter.H" #include "foamVtkLegacyFormatter.H" #include "IOstream.H" // * * * * * * * * * * * * * * Constructor * * * * * * * * * * * * * // Foam::foamVtkOutputOptions::foamVtkOutputOptions() : type_(ASCII), precision_(IOstream::defaultPrecision()) {} // * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * // Foam::autoPtr Foam::foamVtkOutputOptions::newFormatter ( std::ostream& os ) const { switch (type_) { case (LEGACY | BINARY): return autoPtr ( new foamVtkLegacyFormatter(os) ); case BASE64: // xml insitu return autoPtr ( new foamVtkBase64Formatter(os) ); case (APPEND | BASE64): return autoPtr ( new foamVtkAppendBase64Formatter(os) ); case (APPEND | BINARY): return autoPtr ( new foamVtkAppendRawFormatter(os) ); default: // ASCII (legacy or xml) must always work return autoPtr ( new foamVtkAsciiFormatter(os, precision_) ); } } // * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * // void Foam::foamVtkOutputOptions::ascii(bool b) { if (b) { // Force ASCII: if (type_ & APPEND) { // Append: ascii = base64 (vs raw binary) type_ = (APPEND | BASE64); } else if (type_ & LEGACY) { // Legacy: ascii = ascii type_ = (LEGACY | ASCII); } else { // XML: ascii = ascii type_ = ASCII; } } else { // Non-ASCII: if (type_ & APPEND) { // Append: binary == (raw) binary type_ = APPEND | BINARY; } else if (type_ & LEGACY) { // Legacy: binary = binary type_ = LEGACY | BINARY; } else { // XML: binary == (inline) binary == base64 type_ = BASE64; } } } void Foam::foamVtkOutputOptions::append(bool b) { if (b) { if (!(type_ & APPEND)) { // XML: base64 -> raw binary, ascii -> base64 // Legacy: binary -> raw binary, ascii -> base64 type_ = APPEND | ((type_ & (BASE64 | BINARY)) ? BINARY : BASE64); } } else if (type_ & APPEND) { // Only revert back to inline XML base64 versions // ASCII needs another step. type_ = BASE64; } } void Foam::foamVtkOutputOptions::legacy(bool b) { if (b) { if (type_ & APPEND) { // Append: base64 -> ascii, binary -> binary type_ = (LEGACY | ((type_ & BINARY) ? BINARY : ASCII)); } else if (type_ & LEGACY) { // no-op } else { // XML: ascii -> ascii, base64 -> binary type_ = (LEGACY | ((type_ & BASE64) ? BINARY : ASCII)); } } else if (type_ & LEGACY) { // Legacy: ascii -> xml ascii, binary -> xml base64 type_ = (type_ & BINARY) ? BASE64 : ASCII; } } void Foam::foamVtkOutputOptions::precision(unsigned val) const { precision_ = val; } Foam::Ostream& Foam::foamVtkOutputOptions::info(Ostream& os) const { os << "type: " << type_; switch (type_) { case (LEGACY | ASCII): os << " legacy ascii"; break; case (LEGACY | BINARY): os << " legacy binary"; break; case BASE64: os << " xml insitu base64"; break; case (APPEND | BASE64): os << " xml-append base64"; break; case (APPEND | BINARY): os << " xml-append binary"; break; case ASCII: os << " xml insitu ascii"; break; case BINARY: os << " xml insitu binary - WRONG"; break; default: os << " unknown"; break; } if (legacy()) os << " legacy"; if (xml()) os << " xml"; if (append()) os << " append"; if (ascii()) os << " ascii"; return os; } // ************************************************************************* //