mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
STYLE: simpler use of autoPtr, unique_ptr for OSspecific, fileFormats
This commit is contained in:
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,10 +45,11 @@ SourceFiles
|
||||
#ifndef fileMonitor_H
|
||||
#define fileMonitor_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "Enum.H"
|
||||
#include "className.H"
|
||||
#include "DynamicList.H"
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -67,7 +68,7 @@ class fileMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Enumeration defining the file state.
|
||||
enum fileState
|
||||
@ -81,7 +82,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
|
||||
const bool useInotify_;
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2015 OpenFOAM Foundation
|
||||
Copyright (C) 2017-2018 OpenCFD Ltd.
|
||||
Copyright (C) 2017-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -45,10 +45,11 @@ SourceFiles
|
||||
#ifndef fileMonitor_H
|
||||
#define fileMonitor_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include "Enum.H"
|
||||
#include "className.H"
|
||||
#include "DynamicList.H"
|
||||
#include <memory>
|
||||
#include <sys/types.h>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -67,7 +68,7 @@ class fileMonitor
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Enumeration defining the file state.
|
||||
enum fileState
|
||||
@ -81,7 +82,7 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
// Private data
|
||||
// Private Data
|
||||
|
||||
//- Whether to use inotify (requires -DFOAM_USE_INOTIFY, see above)
|
||||
const bool useInotify_;
|
||||
@ -99,7 +100,7 @@ private:
|
||||
DynamicList<label> freeWatchFds_;
|
||||
|
||||
//- Watch mechanism (stat or inotify)
|
||||
mutable autoPtr<fileMonitorWatcher> watcher_;
|
||||
mutable std::unique_ptr<fileMonitorWatcher> watcher_;
|
||||
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2011-2016 OpenFOAM Foundation
|
||||
Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -91,10 +91,10 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
|
||||
)
|
||||
{
|
||||
bool compressed = false;
|
||||
autoPtr<std::istream> streamPtr
|
||||
(
|
||||
std::unique_ptr<std::istream> streamPtr
|
||||
{
|
||||
new std::ifstream(filename, std::ios::binary)
|
||||
);
|
||||
};
|
||||
|
||||
// If the file is compressed, decompress it before further checking.
|
||||
if (!streamPtr->good() && isFile(filename + ".gz", false))
|
||||
@ -102,7 +102,7 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
|
||||
compressed = true;
|
||||
streamPtr.reset(new igzstream((filename + ".gz").c_str()));
|
||||
}
|
||||
std::istream& is = streamPtr();
|
||||
auto& is = *streamPtr;
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
@ -156,7 +156,7 @@ int Foam::fileFormats::STLCore::detectBinaryHeader
|
||||
}
|
||||
|
||||
|
||||
Foam::autoPtr<std::istream>
|
||||
std::unique_ptr<std::istream>
|
||||
Foam::fileFormats::STLCore::readBinaryHeader
|
||||
(
|
||||
const fileName& filename,
|
||||
@ -167,10 +167,10 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
bool compressed = false;
|
||||
nTrisEstimated = 0;
|
||||
|
||||
autoPtr<std::istream> streamPtr
|
||||
(
|
||||
std::unique_ptr<std::istream> streamPtr
|
||||
{
|
||||
new std::ifstream(filename, std::ios::binary)
|
||||
);
|
||||
};
|
||||
|
||||
// If the file is compressed, decompress it before reading.
|
||||
if (!streamPtr->good() && isFile(filename + ".gz", false))
|
||||
@ -178,12 +178,10 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
compressed = true;
|
||||
streamPtr.reset(new igzstream((filename + ".gz").c_str()));
|
||||
}
|
||||
std::istream& is = streamPtr();
|
||||
auto& is = *streamPtr;
|
||||
|
||||
if (!is.good())
|
||||
{
|
||||
streamPtr.clear();
|
||||
|
||||
FatalErrorInFunction
|
||||
<< "Cannot read file " << filename
|
||||
<< " or file " << filename + ".gz"
|
||||
@ -198,8 +196,6 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
// Check that stream is OK, if not this may be an ASCII file
|
||||
if (!is.good()) // could check again: startsWithSolid(header)
|
||||
{
|
||||
streamPtr.clear();
|
||||
|
||||
FatalErrorInFunction
|
||||
<< "problem reading header, perhaps file is not binary "
|
||||
<< exit(FatalError);
|
||||
@ -235,8 +231,6 @@ Foam::fileFormats::STLCore::readBinaryHeader
|
||||
|
||||
if (bad)
|
||||
{
|
||||
streamPtr.clear();
|
||||
|
||||
FatalErrorInFunction
|
||||
<< "problem reading number of triangles, perhaps file is not binary"
|
||||
<< exit(FatalError);
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
\\ / A nd | www.openfoam.com
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
Copyright (C) 2016-2017 OpenCFD Ltd.
|
||||
Copyright (C) 2016-2020 OpenCFD Ltd.
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
This file is part of OpenFOAM.
|
||||
@ -39,7 +39,7 @@ SourceFiles
|
||||
|
||||
#include "STLpoint.H"
|
||||
#include "STLtriangle.H"
|
||||
#include "autoPtr.H"
|
||||
#include <memory>
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -56,7 +56,7 @@ class STLCore
|
||||
{
|
||||
public:
|
||||
|
||||
// Public data types
|
||||
// Public Data Types
|
||||
|
||||
//- Enumeration for the format of data in the stream
|
||||
enum STLFormat
|
||||
@ -88,7 +88,8 @@ protected:
|
||||
//- Read STL binary file header.
|
||||
// Return the opened file stream and estimated number of triangles.
|
||||
// The stream is invalid and number of triangles is 0 on error.
|
||||
static autoPtr<std::istream> readBinaryHeader
|
||||
static std::unique_ptr<std::istream>
|
||||
readBinaryHeader
|
||||
(
|
||||
const fileName& filename,
|
||||
label& nTrisEstimated
|
||||
@ -100,9 +101,8 @@ protected:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
//- Default construct
|
||||
STLCore() = default;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -90,17 +90,19 @@ bool Foam::fileFormats::STLReader::readBINARY
|
||||
format_ = STLFormat::UNKNOWN;
|
||||
|
||||
label nTris = 0;
|
||||
autoPtr<istream> streamPtr = readBinaryHeader(filename, nTris);
|
||||
std::unique_ptr<std::istream> streamPtr
|
||||
{
|
||||
readBinaryHeader(filename, nTris)
|
||||
};
|
||||
|
||||
if (!streamPtr.valid())
|
||||
if (!streamPtr)
|
||||
{
|
||||
FatalErrorInFunction
|
||||
<< "Error reading file " << filename
|
||||
<< " or file " << filename + ".gz"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
istream& is = streamPtr();
|
||||
auto& is = *streamPtr;
|
||||
|
||||
#ifdef DEBUG_STLBINARY
|
||||
Info<< "# " << nTris << " facets" << endl;
|
||||
|
||||
@ -211,7 +211,7 @@ Foam::fileName Foam::surfaceWriters::vtkWriter::write()
|
||||
|
||||
const meshedSurf& surf = surface();
|
||||
|
||||
if (writer_.empty() && (Pstream::master() || !parallel_))
|
||||
if (!writer_ && (Pstream::master() || !parallel_))
|
||||
{
|
||||
writer_.reset
|
||||
(
|
||||
|
||||
Reference in New Issue
Block a user