mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
Merge branch 'master' of ssh://noisy/home/noisy3/OpenFOAM/OpenFOAM-dev
This commit is contained in:
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2008 OpenCFD Ltd.
|
||||
\\ / A nd | Copyright (C) 1991-2009 OpenCFD Ltd.
|
||||
\\/ M anipulation |
|
||||
-------------------------------------------------------------------------------
|
||||
License
|
||||
|
||||
@ -52,27 +52,47 @@ int main(int argc, char *argv[])
|
||||
list1 = -1;
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest zero\n";
|
||||
list1 = 0;
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest set() with default argument (max_value)\n";
|
||||
list1.set(3);
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest assign between references\n";
|
||||
list1[2] = 3;
|
||||
list1[4] = list1[2];
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest assign between references, with chaining\n";
|
||||
list1[4] = list1[2] = 1;
|
||||
list1[0] = list1[4] = 1;
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest assign between references, with chaining and auto-vivify\n";
|
||||
list1[1] = list1[8] = list1[10] = list1[14] = 2;
|
||||
list1.print(Info);
|
||||
|
||||
{
|
||||
const PackedList<3>& constLst = list1;
|
||||
Info<< "\ntest operator[] const with out-of-range index\n";
|
||||
constLst.print(Info);
|
||||
if (!constLst[20])
|
||||
if (constLst[20])
|
||||
{
|
||||
Info<< "[20] is true (unexpected)\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "[20] is false (expected) list size should be unchanged (const)\n";
|
||||
}
|
||||
constLst.print(Info);
|
||||
|
||||
Info<< "\ntest operator[] non-const with out-of-range index\n";
|
||||
if (!list1[20])
|
||||
if (list1[20])
|
||||
{
|
||||
Info<< "[20] is true (unexpected)\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "[20] is false (expected) but list was resized?? (non-const)\n";
|
||||
}
|
||||
@ -91,6 +111,14 @@ int main(int argc, char *argv[])
|
||||
list1.resize(8, list1.max_value());
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest flip() function\n";
|
||||
list1.flip();
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\nre-flip()\n";
|
||||
list1.flip();
|
||||
list1.print(Info);
|
||||
|
||||
Info<< "\ntest set() function\n";
|
||||
list1.set(1, 5);
|
||||
list1.print(Info);
|
||||
@ -188,15 +216,23 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
Info<< "\ntest assignment of iterator\n";
|
||||
list1.print(Info);
|
||||
PackedList<3>::iterator cit = list1[25];
|
||||
cit.print(Info);
|
||||
Info<< "cend()\n";
|
||||
list1.end().print(Info);
|
||||
PackedList<3>::iterator cit = list1[100];
|
||||
Info<< "out-of-range: ";
|
||||
cit.print(Info);
|
||||
cit = list1[15];
|
||||
Info<< "in-range: ";
|
||||
cit.print(Info);
|
||||
Info<< "out-of-range: ";
|
||||
cit = list1[1000];
|
||||
cit.print(Info);
|
||||
}
|
||||
|
||||
|
||||
for
|
||||
(
|
||||
PackedList<3>::iterator cit = list1[5];
|
||||
PackedList<3>::iterator cit = list1[30];
|
||||
cit != list1.end();
|
||||
++cit
|
||||
)
|
||||
@ -204,14 +240,19 @@ int main(int argc, char *argv[])
|
||||
cit.print(Info);
|
||||
}
|
||||
|
||||
// Info<< "\ntest operator[] auto-vivify\n";
|
||||
// const unsigned int val = list1[45];
|
||||
//
|
||||
// Info<< "list[45]:" << val << "\n";
|
||||
// list1[45] = list1.max_value();
|
||||
// Info<< "list[45]:" << list1[45] << "\n";
|
||||
// list1[49] = list1.max_value();
|
||||
// list1.print(Info);
|
||||
Info<< "\ntest operator[] auto-vivify\n";
|
||||
Info<< "size:" << list1.size() << "\n";
|
||||
|
||||
const unsigned int val = list1[45];
|
||||
|
||||
Info<< "list[45]:" << val << "\n";
|
||||
Info<< "size after read:" << list1.size() << "\n";
|
||||
|
||||
list1[45] = list1.max_value();
|
||||
Info<< "size after write:" << list1.size() << "\n";
|
||||
Info<< "list[45]:" << list1[45] << "\n";
|
||||
list1[49] = list1[100];
|
||||
list1.print(Info);
|
||||
|
||||
|
||||
Info<< "\ntest copy constructor + append\n";
|
||||
@ -235,6 +276,23 @@ int main(int argc, char *argv[])
|
||||
Info<< "removed final value: " << list3.remove() << endl;
|
||||
list3.print(Info);
|
||||
|
||||
|
||||
List<bool> list4(4, true);
|
||||
{
|
||||
const List<bool>& constLst = list4;
|
||||
Info<< "\ntest operator[] const with out-of-range index\n";
|
||||
Info<< constLst << endl;
|
||||
if (constLst[20])
|
||||
{
|
||||
Info<< "[20] is true (unexpected)\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< "[20] is false (expected) list size should be unchanged (const)\n";
|
||||
}
|
||||
Info<< constLst << endl;
|
||||
}
|
||||
|
||||
Info<< "\n\nDone.\n";
|
||||
|
||||
return 0;
|
||||
|
||||
@ -32,6 +32,7 @@ Description
|
||||
|
||||
#include "fileName.H"
|
||||
#include "SubList.H"
|
||||
#include "IOobject.H"
|
||||
#include "IOstreams.H"
|
||||
#include "OSspecific.H"
|
||||
|
||||
@ -61,7 +62,8 @@ int main()
|
||||
<< endl;
|
||||
|
||||
// try with different combination
|
||||
for (label start = 0; start < wrdList.size(); ++start)
|
||||
// The final one should emit warnings
|
||||
for (label start = 0; start <= wrdList.size(); ++start)
|
||||
{
|
||||
fileName instance, local;
|
||||
word name;
|
||||
@ -69,26 +71,28 @@ int main()
|
||||
fileName path(SubList<word>(wrdList, wrdList.size()-start, start));
|
||||
fileName path2 = "." / path;
|
||||
|
||||
path.IOobjectComponents
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobjectComponents for " << path << nl
|
||||
Info<< "IOobject::fileNameComponents for " << path << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
path2.IOobjectComponents
|
||||
IOobject::fileNameComponents
|
||||
(
|
||||
path2,
|
||||
instance,
|
||||
local,
|
||||
name
|
||||
);
|
||||
|
||||
Info<< "IOobjectComponents for " << path2 << nl
|
||||
Info<< "IOobject::fileNameComponents for " << path2 << nl
|
||||
<< " instance = " << instance << nl
|
||||
<< " local = " << local << nl
|
||||
<< " name = " << name << endl;
|
||||
|
||||
@ -69,7 +69,7 @@ void checkFaceEdges
|
||||
|
||||
forAll(f, fp)
|
||||
{
|
||||
label fp1 = (fp + 1) % f.size();
|
||||
label fp1 = f.fcIndex(fp);
|
||||
|
||||
if (edges[myEdges[fp]] != edge(f[fp], f[fp1]))
|
||||
{
|
||||
|
||||
3
applications/test/sha1/Make/files
Normal file
3
applications/test/sha1/Make/files
Normal file
@ -0,0 +1,3 @@
|
||||
testSHA1.C
|
||||
|
||||
EXE = $(FOAM_USER_APPBIN)/testSHA1
|
||||
0
applications/test/sha1/Make/options
Normal file
0
applications/test/sha1/Make/options
Normal file
135
applications/test/sha1/testSHA1.C
Normal file
135
applications/test/sha1/testSHA1.C
Normal file
@ -0,0 +1,135 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Application
|
||||
testSHA1
|
||||
|
||||
Description
|
||||
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "OSHA1stream.H"
|
||||
#include "IStringStream.H"
|
||||
#include "dictionary.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
SHA1 sha;
|
||||
SHA1Digest shaDig;
|
||||
|
||||
std::string str("The quick brown fox jumps over the lazy dog");
|
||||
Info<< shaDig << nl;
|
||||
Info<< SHA1("The quick brown fox jumps over the lazy dog") << nl;
|
||||
|
||||
sha.append("The quick brown fox jumps over the lazy dog");
|
||||
Info<< sha << nl;
|
||||
|
||||
sha.clear();
|
||||
sha.append("The quick brown fox jumps over the lazy dog");
|
||||
shaDig = sha;
|
||||
|
||||
sha.append("\n");
|
||||
Info<< sha << nl;
|
||||
Info<< shaDig << nl;
|
||||
|
||||
if (sha == shaDig)
|
||||
{
|
||||
Info<<"SHA1 digests are identical\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<<"SHA1 digests are different\n";
|
||||
}
|
||||
Info<<"lhs:" << sha << " rhs:" << shaDig << endl;
|
||||
|
||||
// start over:
|
||||
sha.clear();
|
||||
sha.append(str);
|
||||
|
||||
SHA1Digest shaDig_A = sha;
|
||||
|
||||
SHA1 sha_A = sha;
|
||||
|
||||
sha.append("\n");
|
||||
|
||||
Info<< "digest1: " << sha_A << nl;
|
||||
Info<< "digest2: " << sha << nl;
|
||||
|
||||
// start over:
|
||||
sha.clear();
|
||||
sha.append("\"");
|
||||
sha.append(str);
|
||||
sha.append("\"");
|
||||
|
||||
Info<< "digest3: " << sha << nl;
|
||||
|
||||
// try the output buffer interface
|
||||
{
|
||||
OSHA1stream os;
|
||||
|
||||
os << str;
|
||||
Info<< os.digest() << endl;
|
||||
|
||||
os << str;
|
||||
Info<< os.digest() << endl;
|
||||
|
||||
os.rewind();
|
||||
os << "The quick brown fox jumps over the lazy dog";
|
||||
Info<< os.digest() << endl;
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
dictionary dict
|
||||
(
|
||||
IStringStream
|
||||
(
|
||||
"parent { Default_Boundary_Region { type zeroGradient; } }"
|
||||
"inlet_1 { value inlet_1; }"
|
||||
"inlet_2 { value inlet_2; }"
|
||||
"inlet_3 { value inlet_3; }"
|
||||
"\"inlet_.*\" { value XXX; }"
|
||||
) ()
|
||||
);
|
||||
|
||||
Info<< "dict:" << endl;
|
||||
dict.write(Info, false);
|
||||
|
||||
dictionary dict2(dict);
|
||||
|
||||
OSHA1stream os;
|
||||
dict.write(os, false);
|
||||
Info<< os.digest() << endl;
|
||||
|
||||
Info<< dict2.digest() << endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -74,20 +74,17 @@ labelList getSortedEdges
|
||||
const edge& e = edges[edgeI];
|
||||
|
||||
label fp = findIndex(f, e[0]);
|
||||
|
||||
label fp1 = (fp+1) % f.size();
|
||||
label fp1 = f.fcIndex(fp);
|
||||
|
||||
if (f[fp1] == e[1])
|
||||
{
|
||||
// Edgei in fp-fp1 order
|
||||
// EdgeI between fp -> fp1
|
||||
faceEdges[fp] = edgeI;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Edgei between fp-1 and fp
|
||||
label fpMin1 = (fp == 0 ? f.size()-1 : fp-1);
|
||||
|
||||
faceEdges[fpMin1] = edgeI;
|
||||
// EdgeI between fp-1 -> fp
|
||||
faceEdges[f.rcIndex(fp)] = edgeI;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -211,7 +211,7 @@ void Foam::cellSplitter::setRefinement
|
||||
|
||||
// Add other pyramids
|
||||
for (label i = 1; i < cFaces.size(); i++)
|
||||
{
|
||||
{
|
||||
label addedCellI =
|
||||
meshMod.setAction
|
||||
(
|
||||
@ -277,7 +277,7 @@ void Foam::cellSplitter::setRefinement
|
||||
|
||||
label index = findIndex(f0, e[0]);
|
||||
|
||||
bool edgeInFaceOrder = (f0[(index+1) % f0.size()] == e[1]);
|
||||
bool edgeInFaceOrder = (f0[f0.fcIndex(index)] == e[1]);
|
||||
|
||||
// Check if cellI is the face owner
|
||||
|
||||
@ -323,7 +323,7 @@ void Foam::cellSplitter::setRefinement
|
||||
|
||||
label index = findIndex(f1, e[0]);
|
||||
|
||||
bool edgeInFaceOrder = (f1[(index+1) % f1.size()] == e[1]);
|
||||
bool edgeInFaceOrder = (f1[f1.fcIndex(index)] == e[1]);
|
||||
|
||||
// Check if cellI is the face owner
|
||||
|
||||
@ -362,7 +362,7 @@ void Foam::cellSplitter::setRefinement
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Update all existing faces for split owner or neighbour.
|
||||
@ -441,7 +441,7 @@ void Foam::cellSplitter::setRefinement
|
||||
|
||||
label patchID, zoneID, zoneFlip;
|
||||
getFaceInfo(faceI, patchID, zoneID, zoneFlip);
|
||||
|
||||
|
||||
meshMod.setAction
|
||||
(
|
||||
polyModifyFace
|
||||
@ -458,7 +458,7 @@ void Foam::cellSplitter::setRefinement
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
faceUpToDate[faceI] = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -615,7 +615,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
fileName ccmFile(args.additionalArgs()[0]);
|
||||
|
||||
if (!exists(ccmFile))
|
||||
if (!isFile(ccmFile))
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot read file " << ccmFile
|
||||
|
||||
@ -129,14 +129,14 @@ int main(int argc, char *argv[])
|
||||
Info<< "Reading .face file for boundary information" << nl << endl;
|
||||
}
|
||||
|
||||
if (!exists(nodeFile) || !exists(eleFile))
|
||||
if (!isFile(nodeFile) || !isFile(eleFile))
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot read " << nodeFile << " or " << eleFile
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (readFaceFile && !exists(faceFile))
|
||||
if (readFaceFile && !isFile(faceFile))
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot read " << faceFile << endl
|
||||
|
||||
@ -108,7 +108,11 @@ int main(int argc, char *argv[])
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
( dictPath.isDir() ? dictPath/dictName : dictPath ),
|
||||
(
|
||||
isDir(dictPath)
|
||||
? dictPath/dictName
|
||||
: dictPath
|
||||
),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
|
||||
@ -746,7 +746,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
Pout<< "Reading commands from file " << batchFile << endl;
|
||||
|
||||
if (!exists(batchFile))
|
||||
// we also cannot handle .gz files
|
||||
if (!isFile(batchFile, false))
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot open file " << batchFile << exit(FatalError);
|
||||
|
||||
@ -627,7 +627,7 @@ autoPtr<mapPolyMesh> createRegionMesh
|
||||
Info<< "Testing:" << io.objectPath() << endl;
|
||||
|
||||
if (!io.headerOk())
|
||||
//if (!exists(io.objectPath()))
|
||||
// if (!exists(io.objectPath()))
|
||||
{
|
||||
Info<< "Writing dummy " << regionName/io.name() << endl;
|
||||
dictionary dummyDict;
|
||||
|
||||
@ -105,7 +105,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// determine the existing processor count directly
|
||||
label nProcs = 0;
|
||||
while (dir(runTime.path()/(word("processor") + name(nProcs))))
|
||||
while (isDir(runTime.path()/(word("processor") + name(nProcs))))
|
||||
{
|
||||
++nProcs;
|
||||
}
|
||||
@ -480,7 +480,7 @@ int main(int argc, char *argv[])
|
||||
// Any uniform data to copy/link?
|
||||
fileName uniformDir("uniform");
|
||||
|
||||
if (dir(runTime.timePath()/uniformDir))
|
||||
if (isDir(runTime.timePath()/uniformDir))
|
||||
{
|
||||
Info<< "Detected additional non-decomposed files in "
|
||||
<< runTime.timePath()/uniformDir
|
||||
|
||||
@ -59,7 +59,7 @@ manualCoeffs
|
||||
}
|
||||
|
||||
|
||||
//// Is the case distributred
|
||||
//// Is the case distributed
|
||||
//distributed yes;
|
||||
//// Per slave (so nProcs-1 entries) the directory above the case.
|
||||
//roots
|
||||
|
||||
@ -63,7 +63,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// determine the processor count directly
|
||||
label nProcs = 0;
|
||||
while (dir(args.path()/(word("processor") + name(nProcs))))
|
||||
while (isDir(args.path()/(word("processor") + name(nProcs))))
|
||||
{
|
||||
++nProcs;
|
||||
}
|
||||
@ -383,7 +383,7 @@ int main(int argc, char *argv[])
|
||||
// the master processor.
|
||||
|
||||
fileName uniformDir0 = databases[0].timePath()/"uniform";
|
||||
if (dir(uniformDir0))
|
||||
if (isDir(uniformDir0))
|
||||
{
|
||||
cp(uniformDir0, runTime.timePath());
|
||||
}
|
||||
|
||||
@ -355,7 +355,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
while
|
||||
(
|
||||
exists
|
||||
isDir
|
||||
(
|
||||
args.rootPath()
|
||||
/ args.caseName()
|
||||
|
||||
@ -503,7 +503,7 @@ int main(int argc, char *argv[])
|
||||
# include "setRootCase.H"
|
||||
|
||||
// Create processor directory if non-existing
|
||||
if (!Pstream::master() && !dir(args.path()))
|
||||
if (!Pstream::master() && !isDir(args.path()))
|
||||
{
|
||||
Pout<< "Creating case directory " << args.path() << endl;
|
||||
mkDir(args.path());
|
||||
@ -525,7 +525,7 @@ int main(int argc, char *argv[])
|
||||
const fileName meshDir = runTime.path()/masterInstDir/polyMesh::meshSubDir;
|
||||
|
||||
boolList haveMesh(Pstream::nProcs(), false);
|
||||
haveMesh[Pstream::myProcNo()] = dir(meshDir);
|
||||
haveMesh[Pstream::myProcNo()] = isDir(meshDir);
|
||||
Pstream::gatherList(haveMesh);
|
||||
Pstream::scatterList(haveMesh);
|
||||
Info<< "Per processor mesh availability : " << haveMesh << endl;
|
||||
|
||||
@ -131,7 +131,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
if (Pstream::master())
|
||||
{
|
||||
if (dir(postProcPath))
|
||||
if (isDir(postProcPath))
|
||||
{
|
||||
rmDir(postProcPath);
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ int main(int argc, char *argv[])
|
||||
// Ensight and Ensight/data directories must exist
|
||||
// do not remove old data - we might wish to convert new results
|
||||
// or a particular time interval
|
||||
if (dir(ensightDir))
|
||||
if (isDir(ensightDir))
|
||||
{
|
||||
Info<<"Warning: reusing existing directory" << nl
|
||||
<< " " << ensightDir << endl;
|
||||
@ -324,7 +324,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
const word& cloudName = cloudIter.key();
|
||||
|
||||
if (!dir(runTime.timePath()/regionPrefix/"lagrangian"/cloudName))
|
||||
if (!isDir(runTime.timePath()/regionPrefix/"lagrangian"/cloudName))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -260,7 +260,7 @@ int main(int argc, char *argv[])
|
||||
// make a directory called FieldView in the case
|
||||
fileName fvPath(runTime.path()/"Fieldview");
|
||||
|
||||
if (dir(fvPath))
|
||||
if (isDir(fvPath))
|
||||
{
|
||||
rmDir(fvPath);
|
||||
}
|
||||
@ -346,7 +346,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
// Output the magic number.
|
||||
writeInt(fvFile, FV_MAGIC);
|
||||
|
||||
|
||||
// Output file header and version number.
|
||||
writeStr80(fvFile, "FIELDVIEW");
|
||||
|
||||
@ -417,7 +417,7 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
if (volFieldPtrs[fieldI] == NULL)
|
||||
{
|
||||
Info<< " dummy field for "
|
||||
Info<< " dummy field for "
|
||||
<< volFieldNames[fieldI].c_str() << endl;
|
||||
}
|
||||
|
||||
|
||||
@ -333,7 +333,7 @@ int main(int argc, char *argv[])
|
||||
regionPrefix = regionName;
|
||||
}
|
||||
|
||||
if (dir(fvPath))
|
||||
if (isDir(fvPath))
|
||||
{
|
||||
if
|
||||
(
|
||||
|
||||
@ -228,7 +228,7 @@ Foam::vtkPV3Foam::vtkPV3Foam
|
||||
// avoid argList and get rootPath/caseName directly from the file
|
||||
fileName fullCasePath(fileName(FileName).path());
|
||||
|
||||
if (!dir(fullCasePath))
|
||||
if (!isDir(fullCasePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -518,7 +518,7 @@ double* Foam::vtkPV3Foam::findTimes(int& nTimeSteps)
|
||||
|
||||
if
|
||||
(
|
||||
file(runTime.path()/timeName/meshDir_/"points")
|
||||
isFile(runTime.path()/timeName/meshDir_/"points")
|
||||
&& IOobject("points", timeName, meshDir_, runTime).headerOk()
|
||||
)
|
||||
{
|
||||
|
||||
@ -156,7 +156,7 @@ class vtkPV3Foam
|
||||
|
||||
bool empty() const
|
||||
{
|
||||
return (size_ == 0);
|
||||
return !size_;
|
||||
}
|
||||
|
||||
void reset()
|
||||
|
||||
@ -194,7 +194,7 @@ void Foam::vtkFoam::updateSelectedRegions()
|
||||
// Read the selected patches and add to the region list
|
||||
for (int i=0; i<nRegions; i++)
|
||||
{
|
||||
selectedRegions_[i] =
|
||||
selectedRegions_[i] =
|
||||
reader_->GetRegionSelection()->GetArraySetting(i);
|
||||
}
|
||||
}
|
||||
@ -282,7 +282,7 @@ void Foam::vtkFoam::convertMesh()
|
||||
else
|
||||
{
|
||||
// A patch already existent in the list and which
|
||||
// continues to exist found
|
||||
// continues to exist found
|
||||
regioni++;
|
||||
}
|
||||
}
|
||||
@ -391,7 +391,7 @@ Foam::vtkFoam::vtkFoam(const char* const FileName, vtkFoamReader* reader)
|
||||
{
|
||||
fileName fullCasePath(fileName(FileName).path());
|
||||
|
||||
if (!dir(fullCasePath))
|
||||
if (!isDir(fullCasePath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -572,7 +572,7 @@ void Foam::vtkFoam::Update()
|
||||
{
|
||||
Info<< "Reading Mesh" << endl;
|
||||
}
|
||||
meshPtr_ =
|
||||
meshPtr_ =
|
||||
new fvMesh
|
||||
(
|
||||
IOobject
|
||||
|
||||
@ -47,7 +47,7 @@ int USERD_set_filenames
|
||||
}
|
||||
caseDir = tmp;
|
||||
|
||||
if (!dir(rootDir/caseDir))
|
||||
if (!isDir(rootDir/caseDir))
|
||||
{
|
||||
Info<< rootDir/caseDir << " is not a valid directory."
|
||||
<< endl;
|
||||
@ -144,7 +144,7 @@ int USERD_set_filenames
|
||||
}
|
||||
isTensor[n] = isitTensor;
|
||||
}
|
||||
|
||||
|
||||
bool lagrangianNamesFound = false;
|
||||
label n = 0;
|
||||
while (!lagrangianNamesFound && n < Num_time_steps)
|
||||
@ -176,7 +176,7 @@ int USERD_set_filenames
|
||||
Info << "[Found lagrangian]" << endl;
|
||||
|
||||
delete sprayPtr;
|
||||
|
||||
|
||||
sprayPtr = new Cloud<passiveParticle>(*meshPtr);
|
||||
|
||||
IOobjectList objects(*meshPtr, runTime.timeName(), "lagrangian");
|
||||
|
||||
@ -132,8 +132,8 @@ static void errorMsg(const string& msg)
|
||||
// Simple check if directory is valid case directory.
|
||||
static bool validCase(const fileName& rootAndCase)
|
||||
{
|
||||
//if (dir(rootAndCase/"system") && dir(rootAndCase/"constant"))
|
||||
if (dir(rootAndCase/"constant"))
|
||||
//if (isDir(rootAndCase/"system") && isDir(rootAndCase/"constant"))
|
||||
if (isDir(rootAndCase/"constant"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@ -528,7 +528,7 @@ void user_query_file_function
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
fileName rootDir(rootAndCase.path());
|
||||
|
||||
@ -180,7 +180,7 @@ surfaces
|
||||
|
||||
triangleCut
|
||||
{
|
||||
// Cutingplaneusing iso surface
|
||||
// Cutingplane using iso surface
|
||||
type cuttingPlane;
|
||||
planeType pointAndNormal;
|
||||
pointAndNormalDict
|
||||
|
||||
@ -63,7 +63,7 @@ void Foam::calc(const argList& args, const Time& runTime, const fvMesh& mesh)
|
||||
|
||||
volVectorField U(Uheader, mesh);
|
||||
|
||||
if (file(runTime.constantPath()/"thermophysicalProperties"))
|
||||
if (isFile(runTime.constantPath()/"thermophysicalProperties"))
|
||||
{
|
||||
// thermophysical Mach
|
||||
autoPtr<basicThermo> thermo
|
||||
|
||||
@ -1,3 +0,0 @@
|
||||
surfaceCoordinateSystemTransform.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/surfaceCoordinateSystemTransform
|
||||
@ -1,5 +1,5 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/triSurface/lnInclude \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude
|
||||
|
||||
EXE_LIBS = -lsurfMesh
|
||||
EXE_LIBS = -lmeshTools -lsurfMesh
|
||||
|
||||
@ -26,25 +26,30 @@ Application
|
||||
surfaceMeshConvert
|
||||
|
||||
Description
|
||||
Converts from one surface mesh format to another
|
||||
|
||||
Convert between surface formats with optional scaling or
|
||||
transformations (rotate/translate) on a coordinateSystem.
|
||||
|
||||
Usage
|
||||
- surfaceMeshConvert inputFile outputFile [OPTION]
|
||||
|
||||
@param -clean \n
|
||||
Perform some surface checking/cleanup on the input surface
|
||||
Perform some surface checking/cleanup on the input surface.
|
||||
|
||||
@param -orient \n
|
||||
Check face orientation on the input surface
|
||||
@param -scaleIn \<scale\> \n
|
||||
Specify a scaling factor when reading files.
|
||||
|
||||
@param -scale \<scale\> \n
|
||||
Specify a scaling factor for writing the files
|
||||
@param -scaleOut \<scale\> \n
|
||||
Specify a scaling factor when writing files.
|
||||
|
||||
@param -triSurface \n
|
||||
Use triSurface library for input/output
|
||||
@param -dict \<dictionary\> \n
|
||||
Specify an alternative dictionary for constant/coordinateSystems.
|
||||
|
||||
@param -keyed \n
|
||||
Use keyedSurface for input/output
|
||||
@param -from \<coordinateSystem\> \n
|
||||
Specify a coordinate System when reading files.
|
||||
|
||||
@param -to \<coordinateSystem\> \n
|
||||
Specify a coordinate System when writing files.
|
||||
|
||||
Note
|
||||
The filename extensions are used to determine the file format type.
|
||||
@ -54,12 +59,9 @@ Note
|
||||
#include "argList.H"
|
||||
#include "timeSelector.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "triSurface.H"
|
||||
#include "PackedBoolList.H"
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "UnsortedMeshedSurfaces.H"
|
||||
#include "coordinateSystems.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
@ -71,24 +73,21 @@ int main(int argc, char *argv[])
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputFile");
|
||||
argList::validArgs.append("outputFile");
|
||||
argList::validOptions.insert("clean", "");
|
||||
argList::validOptions.insert("orient", "");
|
||||
argList::validOptions.insert("scale", "scale");
|
||||
argList::validOptions.insert("triSurface", "");
|
||||
argList::validOptions.insert("unsorted", "");
|
||||
argList::validOptions.insert("triFace", "");
|
||||
# include "setRootCase.H"
|
||||
const stringList& params = args.additionalArgs();
|
||||
argList::validOptions.insert("clean", "scale");
|
||||
argList::validOptions.insert("scaleIn", "scale");
|
||||
argList::validOptions.insert("scaleOut", "scale");
|
||||
argList::validOptions.insert("dict", "coordinateSystemsDict");
|
||||
argList::validOptions.insert("from", "sourceCoordinateSystem");
|
||||
argList::validOptions.insert("to", "targetCoordinateSystem");
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
if (args.options().found("scale"))
|
||||
{
|
||||
IStringStream(args.options()["scale"])() >> scaleFactor;
|
||||
}
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
fileName importName(params[0]);
|
||||
fileName exportName(params[1]);
|
||||
|
||||
// disable inplace editing
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
@ -96,165 +95,161 @@ int main(int argc, char *argv[])
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
// check that reading/writing is supported
|
||||
if
|
||||
(
|
||||
!meshedSurface::canRead(importName, true)
|
||||
|| !meshedSurface::canWriteType(exportName.ext(), true)
|
||||
!MeshedSurface<face>::canRead(importName, true)
|
||||
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.options().found("triSurface"))
|
||||
|
||||
// get the coordinate transformations
|
||||
autoPtr<coordinateSystem> fromCsys;
|
||||
autoPtr<coordinateSystem> toCsys;
|
||||
|
||||
if (args.options().found("from") || args.options().found("to"))
|
||||
{
|
||||
triSurface surf(importName);
|
||||
autoPtr<IOobject> csDictIoPtr;
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
if (args.options().found("dict"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
fileName dictPath(args.options()["dict"]);
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
csDictIoPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
(
|
||||
isDir(dictPath)
|
||||
? dictPath/coordinateSystems::typeName
|
||||
: dictPath
|
||||
),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
csDictIoPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
coordinateSystems::typeName,
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// write sorted by region
|
||||
surf.write(exportName, true);
|
||||
|
||||
if (!csDictIoPtr->headerOk())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot open coordinateSystems file\n "
|
||||
<< csDictIoPtr->objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
coordinateSystems csLst(csDictIoPtr());
|
||||
|
||||
if (args.options().found("from"))
|
||||
{
|
||||
const word csName(args.options()["from"]);
|
||||
|
||||
label csId = csLst.find(csName);
|
||||
if (csId < 0)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot find -from " << csName << nl
|
||||
<< "available coordinateSystems: " << csLst.toc() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
fromCsys.reset(new coordinateSystem(csLst[csId]));
|
||||
}
|
||||
|
||||
if (args.options().found("to"))
|
||||
{
|
||||
const word csName(args.options()["to"]);
|
||||
|
||||
label csId = csLst.find(csName);
|
||||
if (csId < 0)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot find -to " << csName << nl
|
||||
<< "available coordinateSystems: " << csLst.toc() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
toCsys.reset(new coordinateSystem(csLst[csId]));
|
||||
}
|
||||
|
||||
|
||||
// maybe fix this later
|
||||
if (fromCsys.valid() && toCsys.valid())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
else if (args.options().found("unsorted"))
|
||||
|
||||
scalar scaleIn = 0;
|
||||
scalar scaleOut = 0;
|
||||
if (args.options().found("scaleIn"))
|
||||
{
|
||||
UnsortedMeshedSurface<face> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
IStringStream(args.options()["scaleIn"])() >> scaleIn;
|
||||
}
|
||||
#if 1
|
||||
else if (args.options().found("triFace"))
|
||||
if (args.options().found("scaleOut"))
|
||||
{
|
||||
MeshedSurface<triFace> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
IStringStream(args.options()["scaleOut"])() >> scaleOut;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
|
||||
|
||||
{
|
||||
MeshedSurface<face> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (scaleIn > 0)
|
||||
{
|
||||
Info<< " -scaleIn " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys.valid())
|
||||
{
|
||||
Info<< " -from " << fromCsys().name() << endl;
|
||||
tmp<pointField> tpf = fromCsys().localPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (toCsys.valid())
|
||||
{
|
||||
Info<< " -to " << toCsys().name() << endl;
|
||||
tmp<pointField> tpf = toCsys().globalPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (scaleOut > 0)
|
||||
{
|
||||
Info<< " -scaleOut " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,3 @@
|
||||
surfaceMeshConvertTesting.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/surfaceMeshConvertTesting
|
||||
@ -0,0 +1,5 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/triSurface/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude
|
||||
|
||||
EXE_LIBS = -ltriSurface -lsurfMesh
|
||||
@ -0,0 +1,348 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Application
|
||||
surfaceMeshConvertTesting
|
||||
|
||||
Description
|
||||
Converts from one surface mesh format to another, but primarily
|
||||
used for testing functionality.
|
||||
|
||||
Usage
|
||||
- surfaceMeshConvertTesting inputFile outputFile [OPTION]
|
||||
|
||||
@param -clean \n
|
||||
Perform some surface checking/cleanup on the input surface
|
||||
|
||||
@param -orient \n
|
||||
Check face orientation on the input surface
|
||||
|
||||
@param -scale \<scale\> \n
|
||||
Specify a scaling factor for writing the files
|
||||
|
||||
@param -triSurface \n
|
||||
Use triSurface library for input/output
|
||||
|
||||
@param -keyed \n
|
||||
Use keyedSurface for input/output
|
||||
|
||||
Note
|
||||
The filename extensions are used to determine the file format type.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "timeSelector.H"
|
||||
#include "Time.H"
|
||||
#include "polyMesh.H"
|
||||
#include "triSurface.H"
|
||||
#include "surfMesh.H"
|
||||
#include "surfFields.H"
|
||||
#include "surfPointFields.H"
|
||||
#include "PackedBoolList.H"
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "UnsortedMeshedSurfaces.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputFile");
|
||||
argList::validArgs.append("outputFile");
|
||||
argList::validOptions.insert("clean", "");
|
||||
argList::validOptions.insert("orient", "");
|
||||
argList::validOptions.insert("surfMesh", "");
|
||||
argList::validOptions.insert("scale", "scale");
|
||||
argList::validOptions.insert("triSurface", "");
|
||||
argList::validOptions.insert("unsorted", "");
|
||||
argList::validOptions.insert("triFace", "");
|
||||
# include "setRootCase.H"
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
if (args.options().found("scale"))
|
||||
{
|
||||
IStringStream(args.options()["scale"])() >> scaleFactor;
|
||||
}
|
||||
|
||||
fileName importName(params[0]);
|
||||
fileName exportName(params[1]);
|
||||
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
!MeshedSurface<face>::canRead(importName, true)
|
||||
|| !MeshedSurface<face>::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.options().found("triSurface"))
|
||||
{
|
||||
triSurface surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
// write sorted by region
|
||||
surf.write(exportName, true);
|
||||
}
|
||||
else if (args.options().found("unsorted"))
|
||||
{
|
||||
UnsortedMeshedSurface<face> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
}
|
||||
#if 1
|
||||
else if (args.options().found("triFace"))
|
||||
{
|
||||
MeshedSurface<triFace> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
MeshedSurface<face> surf(importName);
|
||||
|
||||
Info<< "Read surface:" << endl;
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
if (args.options().found("orient"))
|
||||
{
|
||||
Info<< "Checking surface orientation" << endl;
|
||||
PatchTools::checkOrientation(surf, true);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
Info<< "Cleaning up surface" << endl;
|
||||
surf.cleanup(true);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
}
|
||||
surf.write(exportName);
|
||||
|
||||
if (args.options().found("surfMesh"))
|
||||
{
|
||||
Foam::Time runTime
|
||||
(
|
||||
args.rootPath(),
|
||||
args.caseName()
|
||||
);
|
||||
|
||||
surfMesh surfOut
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"mySurf",
|
||||
runTime.instance(),
|
||||
runTime
|
||||
),
|
||||
surf.xfer()
|
||||
);
|
||||
|
||||
Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
|
||||
surfOut.write();
|
||||
|
||||
surfLabelField zoneIds
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"zoneIds",
|
||||
surfOut.instance(),
|
||||
surfOut,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
surfOut,
|
||||
dimless
|
||||
);
|
||||
|
||||
const surfZoneList& zones = surfOut.surfZones();
|
||||
forAll(zones, zoneI)
|
||||
{
|
||||
SubList<label>
|
||||
(
|
||||
zoneIds,
|
||||
zones[zoneI].size(),
|
||||
zones[zoneI].start()
|
||||
) = zoneI;
|
||||
}
|
||||
|
||||
Info<< "write zoneIds (for testing only): "
|
||||
<< zoneIds.objectPath() << endl;
|
||||
zoneIds.write();
|
||||
|
||||
surfPointLabelField pointIds
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
"pointIds",
|
||||
surfOut.instance(),
|
||||
"pointFields",
|
||||
surfOut,
|
||||
IOobject::NO_READ,
|
||||
IOobject::NO_WRITE
|
||||
),
|
||||
surfOut,
|
||||
dimless
|
||||
);
|
||||
|
||||
forAll(pointIds, i)
|
||||
{
|
||||
pointIds[i] = i;
|
||||
}
|
||||
|
||||
Info<< "write pointIds (for testing only): "
|
||||
<< pointIds.objectPath() << endl;
|
||||
pointIds.write();
|
||||
}
|
||||
}
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -0,0 +1,3 @@
|
||||
surfaceMeshExport.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/surfaceMeshExport
|
||||
@ -23,27 +23,36 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Application
|
||||
surfaceMeshCoordinateSystemTransform
|
||||
surfaceMeshExport
|
||||
|
||||
Description
|
||||
|
||||
Transform (scale/rotate/translate) a surface based on
|
||||
a coordinateSystem.
|
||||
Export from surfMesh to various third-party surface formats with
|
||||
optional scaling or transformations (rotate/translate) on a
|
||||
coordinateSystem.
|
||||
|
||||
Usage
|
||||
- surfaceMeshCoordinateSystemTransform inputFile outputFile [OPTION]
|
||||
- surfaceMeshExport outputFile [OPTION]
|
||||
|
||||
@param -clean \n
|
||||
Perform some surface checking/cleanup on the input surface
|
||||
Perform some surface checking/cleanup on the input surface.
|
||||
|
||||
@param -scale \<scale\> \n
|
||||
Specify a scaling factor for writing the files
|
||||
@param -name \<name\> \n
|
||||
Specify an alternative surface name when writing.
|
||||
|
||||
@param -triSurface \n
|
||||
Use triSurface library for input/output
|
||||
@param -scaleIn \<scale\> \n
|
||||
Specify a scaling factor when reading files.
|
||||
|
||||
@param -scaleOut \<scale\> \n
|
||||
Specify a scaling factor when writing files.
|
||||
|
||||
@param -dict \<dictionary\> \n
|
||||
Specify an alternative dictionary for coordinateSystems.
|
||||
Specify an alternative dictionary for constant/coordinateSystems.
|
||||
|
||||
@param -from \<coordinateSystem\> \n
|
||||
Specify a coordinate System when reading files.
|
||||
|
||||
@param -to \<coordinateSystem\> \n
|
||||
Specify a coordinate System when writing files.
|
||||
|
||||
Note
|
||||
The filename extensions are used to determine the file format type.
|
||||
@ -55,7 +64,6 @@ Note
|
||||
#include "Time.H"
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "UnsortedMeshedSurfaces.H"
|
||||
#include "coordinateSystems.H"
|
||||
|
||||
using namespace Foam;
|
||||
@ -66,36 +74,55 @@ using namespace Foam;
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputFile");
|
||||
argList::validArgs.append("outputFile");
|
||||
argList::validOptions.insert("scale", "scale");
|
||||
argList::validOptions.insert("unsorted", "");
|
||||
argList::validOptions.insert("name", "name");
|
||||
argList::validOptions.insert("clean", "scale");
|
||||
argList::validOptions.insert("scaleIn", "scale");
|
||||
argList::validOptions.insert("scaleOut", "scale");
|
||||
argList::validOptions.insert("dict", "coordinateSystemsDict");
|
||||
argList::validOptions.insert("from", "sourceCoordinateSystem");
|
||||
argList::validOptions.insert("to", "targetCoordinateSystem");
|
||||
argList::validOptions.insert("dict", "dictionary");
|
||||
argList::validOptions.insert("to", "targetCoordinateSystem");
|
||||
|
||||
argList args(argc, argv);
|
||||
Time runTime(args.rootPath(), args.caseName());
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
const word dictName("coordinateSystems");
|
||||
fileName exportName(params[0]);
|
||||
word importName("default");
|
||||
|
||||
// check that writing is supported
|
||||
if (!MeshedSurface<face>::canWriteType(exportName.ext(), true))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.options().found("name"))
|
||||
{
|
||||
importName = args.options()["name"];
|
||||
}
|
||||
|
||||
|
||||
// get the coordinate transformations
|
||||
autoPtr<coordinateSystem> fromCsys;
|
||||
autoPtr<coordinateSystem> toCsys;
|
||||
|
||||
if (args.options().found("from") || args.options().found("to"))
|
||||
{
|
||||
autoPtr<IOobject> csDictIoPtr;
|
||||
autoPtr<IOobject> ioPtr;
|
||||
|
||||
if (args.options().found("dict"))
|
||||
{
|
||||
fileName dictPath(args.options()["dict"]);
|
||||
|
||||
csDictIoPtr.set
|
||||
ioPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
( dictPath.isDir() ? dictPath/dictName : dictPath ),
|
||||
(
|
||||
isDir(dictPath)
|
||||
? dictPath/coordinateSystems::typeName
|
||||
: dictPath
|
||||
),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
@ -105,11 +132,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
else
|
||||
{
|
||||
csDictIoPtr.set
|
||||
ioPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
dictName,
|
||||
coordinateSystems::typeName,
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
@ -120,15 +147,15 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
|
||||
if (!csDictIoPtr->headerOk())
|
||||
if (!ioPtr->headerOk())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot open coordinateSystems file\n "
|
||||
<< csDictIoPtr->objectPath() << nl
|
||||
<< ioPtr->objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
coordinateSystems csLst(csDictIoPtr());
|
||||
coordinateSystems csLst(ioPtr());
|
||||
|
||||
if (args.options().found("from"))
|
||||
{
|
||||
@ -167,70 +194,81 @@ int main(int argc, char *argv[])
|
||||
if (fromCsys.valid() && toCsys.valid())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Only allowed -from or -to option at the moment."
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
scalar scaleFactor = 0;
|
||||
if (args.options().found("scale"))
|
||||
{
|
||||
IStringStream(args.options()["scale"])() >> scaleFactor;
|
||||
}
|
||||
|
||||
fileName importName(params[0]);
|
||||
fileName exportName(params[1]);
|
||||
|
||||
if (importName == exportName)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Output file " << exportName << " would overwrite input file."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if
|
||||
surfMesh smesh
|
||||
(
|
||||
!meshedSurface::canRead(importName, true)
|
||||
|| !meshedSurface::canWriteType(exportName.ext(), true)
|
||||
)
|
||||
IOobject
|
||||
(
|
||||
importName,
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE
|
||||
)
|
||||
);
|
||||
|
||||
Info<< "read surfMesh:\n " << smesh.objectPath() << endl;
|
||||
|
||||
|
||||
// Simply copy for now, but really should have a separate write method
|
||||
|
||||
MeshedSurface<face> surf(smesh);
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
return 1;
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
scalar scaleIn = 0;
|
||||
scalar scaleOut = 0;
|
||||
if (args.options().found("scaleIn"))
|
||||
{
|
||||
IStringStream(args.options()["scaleIn"])() >> scaleIn;
|
||||
}
|
||||
if (args.options().found("scaleOut"))
|
||||
{
|
||||
IStringStream(args.options()["scaleOut"])() >> scaleOut;
|
||||
}
|
||||
|
||||
|
||||
if (scaleIn > 0)
|
||||
{
|
||||
MeshedSurface<face> surf(importName);
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
if (fromCsys.valid())
|
||||
{
|
||||
tmp<pointField> tpf = fromCsys().localPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (toCsys.valid())
|
||||
{
|
||||
tmp<pointField> tpf = toCsys().globalPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
Info<< "writing " << exportName;
|
||||
if (scaleFactor <= 0)
|
||||
{
|
||||
Info<< " without scaling" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
Info<< " with scaling " << scaleFactor << endl;
|
||||
surf.scalePoints(scaleFactor);
|
||||
}
|
||||
surf.write(exportName);
|
||||
Info<< " -scaleIn " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys.valid())
|
||||
{
|
||||
Info<< " -from " << fromCsys().name() << endl;
|
||||
tmp<pointField> tpf = fromCsys().localPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (toCsys.valid())
|
||||
{
|
||||
Info<< " -to " << toCsys().name() << endl;
|
||||
tmp<pointField> tpf = toCsys().globalPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (scaleOut > 0)
|
||||
{
|
||||
Info<< " -scaleOut " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
}
|
||||
|
||||
|
||||
surf.writeStats(Info);
|
||||
Info<< endl;
|
||||
|
||||
Info<< "writing " << exportName << endl;
|
||||
surf.write(exportName);
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
@ -0,0 +1,3 @@
|
||||
surfaceMeshImport.C
|
||||
|
||||
EXE = $(FOAM_APPBIN)/surfaceMeshImport
|
||||
@ -0,0 +1,5 @@
|
||||
EXE_INC = \
|
||||
-I$(LIB_SRC)/meshTools/lnInclude \
|
||||
-I$(LIB_SRC)/surfMesh/lnInclude
|
||||
|
||||
EXE_LIBS = -lmeshTools -lsurfMesh
|
||||
@ -0,0 +1,284 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Application
|
||||
surfaceMeshImport
|
||||
|
||||
Description
|
||||
Import from various third-party surface formats into surfMesh
|
||||
with optional scaling or transformations (rotate/translate)
|
||||
on a coordinateSystem.
|
||||
|
||||
Usage
|
||||
- surfaceMeshImport inputFile [OPTION]
|
||||
|
||||
@param -clean \n
|
||||
Perform some surface checking/cleanup on the input surface.
|
||||
|
||||
@param -name \<name\> \n
|
||||
Specify an alternative surface name when writing.
|
||||
|
||||
@param -scaleIn \<scale\> \n
|
||||
Specify a scaling factor when reading files.
|
||||
|
||||
@param -scaleOut \<scale\> \n
|
||||
Specify a scaling factor when writing files.
|
||||
|
||||
@param -dict \<dictionary\> \n
|
||||
Specify an alternative dictionary for constant/coordinateSystems.
|
||||
|
||||
@param -from \<coordinateSystem\> \n
|
||||
Specify a coordinate System when reading files.
|
||||
|
||||
@param -to \<coordinateSystem\> \n
|
||||
Specify a coordinate System when writing files.
|
||||
|
||||
Note
|
||||
The filename extensions are used to determine the file format type.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "argList.H"
|
||||
#include "timeSelector.H"
|
||||
#include "Time.H"
|
||||
|
||||
#include "MeshedSurfaces.H"
|
||||
#include "coordinateSystems.H"
|
||||
|
||||
using namespace Foam;
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
// Main program:
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
argList::noParallel();
|
||||
argList::validArgs.append("inputFile");
|
||||
argList::validOptions.insert("name", "name");
|
||||
argList::validOptions.insert("clean", "scale");
|
||||
argList::validOptions.insert("scaleIn", "scale");
|
||||
argList::validOptions.insert("scaleOut", "scale");
|
||||
argList::validOptions.insert("dict", "coordinateSystemsDict");
|
||||
argList::validOptions.insert("from", "sourceCoordinateSystem");
|
||||
argList::validOptions.insert("to", "targetCoordinateSystem");
|
||||
|
||||
# include "setRootCase.H"
|
||||
# include "createTime.H"
|
||||
|
||||
const stringList& params = args.additionalArgs();
|
||||
|
||||
// try for the latestTime, but create "constant" as needed
|
||||
instantList Times = runTime.times();
|
||||
if (Times.size())
|
||||
{
|
||||
label startTime = Times.size()-1;
|
||||
runTime.setTime(Times[startTime], startTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
runTime.setTime(instant(0, runTime.constant()), 0);
|
||||
}
|
||||
|
||||
|
||||
fileName importName(params[0]);
|
||||
word exportName("default");
|
||||
|
||||
// check that reading is supported
|
||||
if (!MeshedSurface<face>::canRead(importName, true))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (args.options().found("name"))
|
||||
{
|
||||
exportName = args.options()["name"];
|
||||
}
|
||||
|
||||
|
||||
// get the coordinate transformations
|
||||
autoPtr<coordinateSystem> fromCsys;
|
||||
autoPtr<coordinateSystem> toCsys;
|
||||
|
||||
if (args.options().found("from") || args.options().found("to"))
|
||||
{
|
||||
autoPtr<IOobject> ioPtr;
|
||||
|
||||
if (args.options().found("dict"))
|
||||
{
|
||||
fileName dictPath(args.options()["dict"]);
|
||||
|
||||
ioPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
(
|
||||
isDir(dictPath)
|
||||
? dictPath/coordinateSystems::typeName
|
||||
: dictPath
|
||||
),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
ioPtr.set
|
||||
(
|
||||
new IOobject
|
||||
(
|
||||
coordinateSystems::typeName,
|
||||
runTime.constant(),
|
||||
runTime,
|
||||
IOobject::MUST_READ,
|
||||
IOobject::NO_WRITE,
|
||||
false
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if (!ioPtr->headerOk())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot open coordinateSystems file\n "
|
||||
<< ioPtr->objectPath() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
coordinateSystems csLst(ioPtr());
|
||||
|
||||
if (args.options().found("from"))
|
||||
{
|
||||
const word csName(args.options()["from"]);
|
||||
|
||||
label csId = csLst.find(csName);
|
||||
if (csId < 0)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot find -from " << csName << nl
|
||||
<< "available coordinateSystems: " << csLst.toc() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
fromCsys.reset(new coordinateSystem(csLst[csId]));
|
||||
}
|
||||
|
||||
if (args.options().found("to"))
|
||||
{
|
||||
const word csName(args.options()["to"]);
|
||||
|
||||
label csId = csLst.find(csName);
|
||||
if (csId < 0)
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Cannot find -to " << csName << nl
|
||||
<< "available coordinateSystems: " << csLst.toc() << nl
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
toCsys.reset(new coordinateSystem(csLst[csId]));
|
||||
}
|
||||
|
||||
|
||||
// maybe fix this later
|
||||
if (fromCsys.valid() && toCsys.valid())
|
||||
{
|
||||
FatalErrorIn(args.executable())
|
||||
<< "Only allowed '-from' or '-to' option at the moment."
|
||||
<< exit(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
MeshedSurface<face> surf(importName);
|
||||
|
||||
if (args.options().found("clean"))
|
||||
{
|
||||
surf.cleanup(true);
|
||||
}
|
||||
|
||||
|
||||
scalar scaleIn = 0;
|
||||
scalar scaleOut = 0;
|
||||
if (args.options().found("scaleIn"))
|
||||
{
|
||||
IStringStream(args.options()["scaleIn"])() >> scaleIn;
|
||||
}
|
||||
if (args.options().found("scaleOut"))
|
||||
{
|
||||
IStringStream(args.options()["scaleOut"])() >> scaleOut;
|
||||
}
|
||||
|
||||
|
||||
if (scaleIn > 0)
|
||||
{
|
||||
Info<< " -scaleIn " << scaleIn << endl;
|
||||
surf.scalePoints(scaleIn);
|
||||
}
|
||||
|
||||
if (fromCsys.valid())
|
||||
{
|
||||
Info<< " -from " << fromCsys().name() << endl;
|
||||
tmp<pointField> tpf = fromCsys().localPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (toCsys.valid())
|
||||
{
|
||||
Info<< " -to " << toCsys().name() << endl;
|
||||
tmp<pointField> tpf = toCsys().globalPosition(surf.points());
|
||||
surf.movePoints(tpf());
|
||||
}
|
||||
|
||||
if (scaleOut > 0)
|
||||
{
|
||||
Info<< " -scaleOut " << scaleOut << endl;
|
||||
surf.scalePoints(scaleOut);
|
||||
}
|
||||
|
||||
surfMesh smesh
|
||||
(
|
||||
IOobject
|
||||
(
|
||||
exportName,
|
||||
runTime.constant(),
|
||||
runTime
|
||||
),
|
||||
surf.xfer()
|
||||
);
|
||||
|
||||
|
||||
Info<< "writing surfMesh:\n " << smesh.objectPath() << endl;
|
||||
smesh.write();
|
||||
|
||||
Info<< "\nEnd\n" << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -351,7 +351,7 @@ label otherEdge
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Starting from startPoint on startEdge on startFace walk along border
|
||||
// and insert faces along the way. Walk keeps always one point or one edge
|
||||
@ -461,18 +461,8 @@ label sharedFace
|
||||
|
||||
label startIndex = findIndex(f, e.start());
|
||||
|
||||
bool edgeOrder;
|
||||
|
||||
if (f[(startIndex + 1) % f.size()] == e.end())
|
||||
{
|
||||
// points in face in same order as edge
|
||||
edgeOrder = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
// points in face in reverse order as edge
|
||||
edgeOrder = false;
|
||||
}
|
||||
// points in face in same order as edge
|
||||
bool edgeOrder = (f[f.fcIndex(startIndex)] == e.end());
|
||||
|
||||
// Get faces using edge in sorted order. (sorted such that walking
|
||||
// around them in anti-clockwise order corresponds to edge vector
|
||||
@ -485,25 +475,18 @@ label sharedFace
|
||||
if (edgeOrder)
|
||||
{
|
||||
// Get face before firstFaceI
|
||||
if (faceIndex == 0)
|
||||
{
|
||||
return eFaces[eFaces.size() - 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
return eFaces[faceIndex - 1];
|
||||
}
|
||||
return eFaces[eFaces.rcIndex(faceIndex)];
|
||||
}
|
||||
else
|
||||
{
|
||||
// Get face after firstFaceI
|
||||
return eFaces[(faceIndex+1) % eFaces.size()];
|
||||
return eFaces[eFaces.fcIndex(faceIndex)];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Calculate (inward pointing) normals on edges shared by faces in faceToEdge and
|
||||
// averages them to pointNormals.
|
||||
// averages them to pointNormals.
|
||||
void calcPointVecs
|
||||
(
|
||||
const triSurface& surf,
|
||||
@ -602,7 +585,7 @@ void calcPointVecs
|
||||
}
|
||||
|
||||
scalar magMidVec = mag(midVec);
|
||||
|
||||
|
||||
if (magMidVec > SMALL)
|
||||
{
|
||||
midVec /= magMidVec;
|
||||
@ -925,7 +908,7 @@ int main(int argc, char *argv[])
|
||||
newPoints[newPointI] = newPoints[pointI] + 0.1 * minLen * n;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// Renumber all faces in connectedFaces
|
||||
|
||||
@ -17,11 +17,12 @@ wmake libso lagrangian/basic
|
||||
wmake libso triSurface
|
||||
wmake libso edgeMesh
|
||||
wmake libso surfMesh
|
||||
wmake libso meshTools
|
||||
wmake libso finiteVolume
|
||||
|
||||
decompositionAgglomeration/Allwmake
|
||||
|
||||
wmake libso meshTools
|
||||
wmake libso finiteVolume
|
||||
|
||||
wmake libso sampling
|
||||
|
||||
wmake libso dynamicMesh
|
||||
|
||||
@ -23,7 +23,7 @@ License
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
UNIX versions of the functions declared in OSspecific.H.
|
||||
UNIX versions of the functions declared in OSspecific.H
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
@ -218,7 +218,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
// Search user files:
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
fileName searchDir = home()/".OpenFOAM";
|
||||
if (dir(searchDir))
|
||||
if (isDir(searchDir))
|
||||
{
|
||||
// Check for user file in ~/.OpenFOAM/VERSION
|
||||
fileName fullName = searchDir/FOAMversion/name;
|
||||
@ -239,7 +239,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
// Search site files:
|
||||
// ~~~~~~~~~~~~~~~~~~
|
||||
searchDir = getEnv("WM_PROJECT_INST_DIR");
|
||||
if (dir(searchDir))
|
||||
if (isDir(searchDir))
|
||||
{
|
||||
// Check for site file in $WM_PROJECT_INST_DIR/site/VERSION
|
||||
fileName fullName = searchDir/"site"/FOAMversion/name;
|
||||
@ -259,7 +259,7 @@ Foam::fileName Foam::findEtcFile(const fileName& name, bool mandatory)
|
||||
// Search installation files:
|
||||
// ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
searchDir = getEnv("WM_PROJECT_DIR");
|
||||
if (dir(searchDir))
|
||||
if (isDir(searchDir))
|
||||
{
|
||||
// Check for shipped OpenFOAM file in $WM_PROJECT_DIR/etc
|
||||
fileName fullName = searchDir/"etc"/name;
|
||||
@ -432,7 +432,7 @@ bool Foam::mkDir(const fileName& pathName, mode_t mode)
|
||||
|
||||
|
||||
// Set the file mode
|
||||
bool Foam::chmod(const fileName& name, const mode_t m)
|
||||
bool Foam::chMod(const fileName& name, const mode_t m)
|
||||
{
|
||||
return ::chmod(name.c_str(), m) == 0;
|
||||
}
|
||||
@ -476,24 +476,24 @@ Foam::fileName::Type Foam::type(const fileName& name)
|
||||
// Does the name exist in the filing system?
|
||||
bool Foam::exists(const fileName& name)
|
||||
{
|
||||
return mode(name) || file(name);
|
||||
}
|
||||
|
||||
|
||||
// Does the file exist
|
||||
bool Foam::file(const fileName& name)
|
||||
{
|
||||
return S_ISREG(mode(name)) || S_ISREG(mode(name + ".gz"));
|
||||
return mode(name) || isFile(name);
|
||||
}
|
||||
|
||||
|
||||
// Does the directory exist
|
||||
bool Foam::dir(const fileName& name)
|
||||
bool Foam::isDir(const fileName& name)
|
||||
{
|
||||
return S_ISDIR(mode(name));
|
||||
}
|
||||
|
||||
|
||||
// Does the file exist
|
||||
bool Foam::isFile(const fileName& name, const bool checkGzip)
|
||||
{
|
||||
return S_ISREG(mode(name)) || (checkGzip && S_ISREG(mode(name + ".gz")));
|
||||
}
|
||||
|
||||
|
||||
// Return size of file
|
||||
off_t Foam::fileSize(const fileName& name)
|
||||
{
|
||||
@ -641,7 +641,7 @@ bool Foam::cp(const fileName& src, const fileName& dest)
|
||||
}
|
||||
|
||||
// Make sure the destination directory exists.
|
||||
if (!dir(destFile.path()) && !mkDir(destFile.path()))
|
||||
if (!isDir(destFile.path()) && !mkDir(destFile.path()))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -681,7 +681,7 @@ bool Foam::cp(const fileName& src, const fileName& dest)
|
||||
}
|
||||
|
||||
// Make sure the destination directory exists.
|
||||
if (!dir(destFile) && !mkDir(destFile))
|
||||
if (!isDir(destFile) && !mkDir(destFile))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -719,19 +719,19 @@ bool Foam::cp(const fileName& src, const fileName& dest)
|
||||
}
|
||||
|
||||
|
||||
// Create a softlink. destFile should not exist. Returns true if successful.
|
||||
bool Foam::ln(const fileName& src, const fileName& dest)
|
||||
// Create a softlink. dst should not exist. Returns true if successful.
|
||||
bool Foam::ln(const fileName& src, const fileName& dst)
|
||||
{
|
||||
if (Unix::debug)
|
||||
{
|
||||
Info<< "Create softlink from : " << src << " to " << dest
|
||||
Info<< "Create softlink from : " << src << " to " << dst
|
||||
<< endl;
|
||||
}
|
||||
|
||||
if (exists(dest))
|
||||
if (exists(dst))
|
||||
{
|
||||
WarningIn("ln(const fileName&, const fileName&)")
|
||||
<< "destination " << dest << " already exists. Not linking."
|
||||
<< "destination " << dst << " already exists. Not linking."
|
||||
<< endl;
|
||||
return false;
|
||||
}
|
||||
@ -743,40 +743,40 @@ bool Foam::ln(const fileName& src, const fileName& dest)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (symlink(src.c_str(), dest.c_str()) == 0)
|
||||
if (symlink(src.c_str(), dst.c_str()) == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
WarningIn("ln(const fileName&, const fileName&)")
|
||||
<< "symlink from " << src << " to " << dest << " failed." << endl;
|
||||
<< "symlink from " << src << " to " << dst << " failed." << endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Rename srcFile destFile
|
||||
bool Foam::mv(const fileName& srcFile, const fileName& destFile)
|
||||
// Rename srcFile dstFile
|
||||
bool Foam::mv(const fileName& srcFile, const fileName& dstFile)
|
||||
{
|
||||
if (Unix::debug)
|
||||
{
|
||||
Info<< "Move : " << srcFile << " to " << destFile << endl;
|
||||
Info<< "Move : " << srcFile << " to " << dstFile << endl;
|
||||
}
|
||||
|
||||
if
|
||||
(
|
||||
(destFile.type() == fileName::DIRECTORY)
|
||||
&& (srcFile.type() != fileName::DIRECTORY)
|
||||
dstFile.type() == fileName::DIRECTORY
|
||||
&& srcFile.type() != fileName::DIRECTORY
|
||||
)
|
||||
{
|
||||
const fileName destName(destFile/srcFile.name());
|
||||
const fileName dstName(dstFile/srcFile.name());
|
||||
|
||||
return rename(srcFile.c_str(), destName.c_str()) == 0;
|
||||
return rename(srcFile.c_str(), dstName.c_str()) == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return rename(srcFile.c_str(), destFile.c_str()) == 0;
|
||||
return rename(srcFile.c_str(), dstFile.c_str()) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -806,7 +806,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
{
|
||||
if (Unix::debug)
|
||||
{
|
||||
Info<< "rmdir(const fileName&) : "
|
||||
Info<< "rmDir(const fileName&) : "
|
||||
<< "removing directory " << directory << endl;
|
||||
}
|
||||
|
||||
@ -817,7 +817,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
// Attempt to open directory and set the structure pointer
|
||||
if ((source = opendir(directory.c_str())) == NULL)
|
||||
{
|
||||
WarningIn("rmdir(const fileName&)")
|
||||
WarningIn("rmDir(const fileName&)")
|
||||
<< "cannot open directory " << directory << endl;
|
||||
|
||||
return false;
|
||||
@ -837,7 +837,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
{
|
||||
if (!rmDir(path))
|
||||
{
|
||||
WarningIn("rmdir(const fileName&)")
|
||||
WarningIn("rmDir(const fileName&)")
|
||||
<< "failed to remove directory " << fName
|
||||
<< " while removing directory " << directory
|
||||
<< endl;
|
||||
@ -851,7 +851,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
{
|
||||
if (!rm(path))
|
||||
{
|
||||
WarningIn("rmdir(const fileName&)")
|
||||
WarningIn("rmDir(const fileName&)")
|
||||
<< "failed to remove file " << fName
|
||||
<< " while removing directory " << directory
|
||||
<< endl;
|
||||
@ -867,7 +867,7 @@ bool Foam::rmDir(const fileName& directory)
|
||||
|
||||
if (!rm(directory))
|
||||
{
|
||||
WarningIn("rmdir(const fileName&)")
|
||||
WarningIn("rmDir(const fileName&)")
|
||||
<< "failed to remove directory " << directory << endl;
|
||||
|
||||
closedir(source);
|
||||
|
||||
@ -45,6 +45,10 @@ $(strings)/fileName/fileNameIO.C
|
||||
$(strings)/keyType/keyTypeIO.C
|
||||
$(strings)/wordRe/wordReIO.C
|
||||
|
||||
sha1 = primitives/hashes/SHA1
|
||||
$(sha1)/SHA1.C
|
||||
$(sha1)/SHA1Digest.C
|
||||
|
||||
primitives/random/Random.C
|
||||
|
||||
containers/HashTables/HashTable/HashTableName.C
|
||||
|
||||
@ -226,7 +226,7 @@ bool Foam::HashTable<T, Key, Hash>::set
|
||||
const bool protect
|
||||
)
|
||||
{
|
||||
if (tableSize_ == 0)
|
||||
if (!tableSize_)
|
||||
{
|
||||
resize(2);
|
||||
}
|
||||
@ -556,7 +556,7 @@ void Foam::HashTable<T, Key, Hash>::operator=
|
||||
}
|
||||
|
||||
// could be zero-sized from a previous transfer()
|
||||
if (tableSize_ == 0)
|
||||
if (!tableSize_)
|
||||
{
|
||||
resize(rhs.tableSize_);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
|
||||
template<class T, class Key, class Hash>
|
||||
inline bool Foam::HashTable<T, Key, Hash>::empty() const
|
||||
{
|
||||
return (nElmts_ == 0);
|
||||
return !nElmts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@ inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const
|
||||
template<class T, class Key, class Hash>
|
||||
inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const
|
||||
{
|
||||
return (nElmts_ == 0);
|
||||
return !nElmts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -83,7 +83,7 @@ inline Foam::label Foam::DLListBase::size() const
|
||||
|
||||
inline bool Foam::DLListBase::empty() const
|
||||
{
|
||||
return (nElmts_ == 0);
|
||||
return !nElmts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -73,7 +73,7 @@ inline Foam::label Foam::SLListBase::size() const
|
||||
|
||||
inline bool Foam::SLListBase::empty() const
|
||||
{
|
||||
return (nElmts_ == 0);
|
||||
return !nElmts_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -135,10 +135,21 @@ public:
|
||||
inline label fcIndex(const label i) const;
|
||||
|
||||
//- Return the reverse circular index, i.e. the previous index
|
||||
// which returns to the last at the begining of the list
|
||||
// which returns to the last at the beginning of the list
|
||||
inline label rcIndex(const label i) const;
|
||||
|
||||
|
||||
//- Return a const pointer to the first data element,
|
||||
// similar to the STL front() method and the string::data() method
|
||||
// This can be used (with caution) when interfacing with C code.
|
||||
inline const T* cdata() const;
|
||||
|
||||
//- Return a pointer to the first data element,
|
||||
// similar to the STL front() method and the string::data() method
|
||||
// This can be used (with caution) when interfacing with C code.
|
||||
inline T* data();
|
||||
|
||||
|
||||
// Check
|
||||
|
||||
//- Check start is within valid range (0 ... size-1).
|
||||
@ -174,10 +185,10 @@ public:
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Return subscript-checked element of FixedList.
|
||||
//- Return element of FixedList.
|
||||
inline T& operator[](const label);
|
||||
|
||||
//- Return subscript-checked element of constant FixedList.
|
||||
//- Return element of constant FixedList.
|
||||
inline const T& operator[](const label) const;
|
||||
|
||||
//- Assignment from array operator. Takes linear time.
|
||||
@ -282,7 +293,7 @@ public:
|
||||
//- Return size of the largest possible FixedList.
|
||||
inline label max_size() const;
|
||||
|
||||
//- Return true if the FixedList is empty (i.e., if size() == 0).
|
||||
//- Return true if the FixedList is empty (ie, size() is zero).
|
||||
inline bool empty() const;
|
||||
|
||||
//- Swap two FixedLists of the same type in constant time.
|
||||
|
||||
@ -121,7 +121,7 @@ inline Foam::label Foam::FixedList<T, Size>::fcIndex(const label i) const
|
||||
template<class T, Foam::label Size>
|
||||
inline Foam::label Foam::FixedList<T, Size>::rcIndex(const label i) const
|
||||
{
|
||||
return (i == 0 ? Size-1 : i-1);
|
||||
return (i ? i-1 : Size-1);
|
||||
}
|
||||
|
||||
|
||||
@ -195,9 +195,26 @@ inline void Foam::FixedList<T, Size>::transfer(const FixedList<T, Size>& lst)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<class T, Foam::label Size>
|
||||
inline const T*
|
||||
Foam::FixedList<T, Size>::cdata() const
|
||||
{
|
||||
return v_;
|
||||
}
|
||||
|
||||
|
||||
template<class T, Foam::label Size>
|
||||
inline T*
|
||||
Foam::FixedList<T, Size>::data()
|
||||
{
|
||||
return v_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
// Return subscript-checked element access
|
||||
// element access
|
||||
template<class T, Foam::label Size>
|
||||
inline T& Foam::FixedList<T, Size>::operator[](const label i)
|
||||
{
|
||||
@ -208,7 +225,7 @@ inline T& Foam::FixedList<T, Size>::operator[](const label i)
|
||||
}
|
||||
|
||||
|
||||
// Return subscript-checked const element access
|
||||
// const element access
|
||||
template<class T, Foam::label Size>
|
||||
inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
|
||||
{
|
||||
|
||||
@ -119,7 +119,7 @@ Foam::Istream& Foam::operator>>(Foam::Istream& is, FixedList<T, Size>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.begin()), Size*sizeof(T));
|
||||
is.read(reinterpret_cast<char*>(L.data()), Size*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
@ -231,7 +231,7 @@ Foam::Ostream& Foam::operator<<(Ostream& os, const FixedList<T, Size>& L)
|
||||
}
|
||||
else
|
||||
{
|
||||
os.write(reinterpret_cast<const char*>(L.v_), Size*sizeof(T));
|
||||
os.write(reinterpret_cast<const char*>(L.cdata()), Size*sizeof(T));
|
||||
}
|
||||
|
||||
// Check state of IOstream
|
||||
|
||||
@ -117,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, List<T>& L)
|
||||
{
|
||||
if (s)
|
||||
{
|
||||
is.read(reinterpret_cast<char*>(L.begin()), s*sizeof(T));
|
||||
is.read(reinterpret_cast<char*>(L.data()), s*sizeof(T));
|
||||
|
||||
is.fatalCheck
|
||||
(
|
||||
|
||||
@ -90,17 +90,31 @@ void duplicateOrder(const UList<T>&, labelList& order);
|
||||
template<class T>
|
||||
void uniqueOrder(const UList<T>&, labelList& order);
|
||||
|
||||
//- Extract elements of List whose region is certain value.
|
||||
// Use e.g. to extract all selected elements:
|
||||
// subset<boolList, labelList>(selectedElems, true, lst);
|
||||
//- Extract elements of List when select is a certain value.
|
||||
// eg, to extract all selected elements:
|
||||
// subset<bool, labelList>(selectedElems, true, lst);
|
||||
template<class T, class ListType>
|
||||
ListType subset(const UList<T>& regions, const T& region, const ListType&);
|
||||
ListType subset(const UList<T>& select, const T& value, const ListType&);
|
||||
|
||||
//- Inplace extract elements of List whose region is certain value. Use e.g.
|
||||
// to extract all selected elements:
|
||||
// inplaceSubset<boolList, labelList>(selectedElems, true, lst);
|
||||
//- Inplace extract elements of List when select is a certain value.
|
||||
// eg, to extract all selected elements:
|
||||
// inplaceSubset<bool, labelList>(selectedElems, true, lst);
|
||||
template<class T, class ListType>
|
||||
void inplaceSubset(const UList<T>& regions, const T& region, ListType&);
|
||||
void inplaceSubset(const UList<T>& select, const T& value, ListType&);
|
||||
|
||||
//- Extract elements of List when select is true
|
||||
// eg, to extract all selected elements:
|
||||
// subset<boolList, labelList>(selectedElems, lst);
|
||||
// Note a labelHashSet could also be used for the bool-list
|
||||
template<class BoolListType, class ListType>
|
||||
ListType subset(const BoolListType& select, const ListType&);
|
||||
|
||||
//- Inplace extract elements of List when select is true
|
||||
// eg, to extract all selected elements:
|
||||
// inplaceSubset<boolList, labelList>(selectedElems, lst);
|
||||
// Note a labelHashSet could also be used for the bool-list
|
||||
template<class BoolListType, class ListType>
|
||||
void inplaceSubset(const BoolListType& select, ListType&);
|
||||
|
||||
//- Invert one-to-one map. Unmapped elements will be -1.
|
||||
labelList invert(const label len, const UList<label>&);
|
||||
@ -108,8 +122,9 @@ labelList invert(const label len, const UList<label>&);
|
||||
//- Invert one-to-many map. Unmapped elements will be size 0.
|
||||
labelListList invertOneToMany(const label len, const UList<label>&);
|
||||
|
||||
//- Invert many-to-many. Input and output types need to be inherited
|
||||
// from List. E.g. faces to pointFaces.
|
||||
//- Invert many-to-many.
|
||||
// Input and output types need to be inherited from List.
|
||||
// eg, faces to pointFaces.
|
||||
template<class InList, class OutList>
|
||||
void invertManyToMany(const label len, const UList<InList>&, List<OutList>&);
|
||||
|
||||
|
||||
@ -243,16 +243,17 @@ void Foam::uniqueOrder
|
||||
template<class T, class ListType>
|
||||
ListType Foam::subset
|
||||
(
|
||||
const UList<T>& regions,
|
||||
const T& region,
|
||||
const UList<T>& select,
|
||||
const T& value,
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
if (regions.size() < lst.size())
|
||||
// select must at least cover the list range
|
||||
if (select.size() < lst.size())
|
||||
{
|
||||
FatalErrorIn("subset(const UList<T>&, const T&, const ListType&)")
|
||||
<< "Regions is of size " << regions.size()
|
||||
<< "; list it is supposed to index is of size " << lst.size()
|
||||
<< "select is of size " << select.size()
|
||||
<< "; but it must index a list of size " << lst.size()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
@ -261,7 +262,7 @@ ListType Foam::subset
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (regions[elemI] == region)
|
||||
if (select[elemI] == value)
|
||||
{
|
||||
newLst[nElem++] = lst[elemI];
|
||||
}
|
||||
@ -275,23 +276,77 @@ ListType Foam::subset
|
||||
template<class T, class ListType>
|
||||
void Foam::inplaceSubset
|
||||
(
|
||||
const UList<T>& regions,
|
||||
const T& region,
|
||||
const UList<T>& select,
|
||||
const T& value,
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
if (regions.size() < lst.size())
|
||||
// select must at least cover the list range
|
||||
if (select.size() < lst.size())
|
||||
{
|
||||
FatalErrorIn("inplaceSubset(const UList<T>&, const T&, ListType&)")
|
||||
<< "Regions is of size " << regions.size()
|
||||
<< "; list it is supposed to index is of size " << lst.size()
|
||||
<< "select is of size " << select.size()
|
||||
<< "; but it must index a list of size " << lst.size()
|
||||
<< abort(FatalError);
|
||||
}
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (regions[elemI] == region)
|
||||
if (select[elemI] == value)
|
||||
{
|
||||
if (nElem != elemI)
|
||||
{
|
||||
lst[nElem] = lst[elemI];
|
||||
}
|
||||
++nElem;
|
||||
}
|
||||
}
|
||||
|
||||
lst.setSize(nElem);
|
||||
}
|
||||
|
||||
|
||||
template<class BoolListType, class ListType>
|
||||
ListType Foam::subset
|
||||
(
|
||||
const BoolListType& select,
|
||||
const ListType& lst
|
||||
)
|
||||
{
|
||||
// select can have a different size
|
||||
// eg, when it is a PackedBoolList or a labelHashSet
|
||||
|
||||
ListType newLst(lst.size());
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (select[elemI])
|
||||
{
|
||||
newLst[nElem++] = lst[elemI];
|
||||
}
|
||||
}
|
||||
newLst.setSize(nElem);
|
||||
|
||||
return newLst;
|
||||
}
|
||||
|
||||
|
||||
template<class BoolListType, class ListType>
|
||||
void Foam::inplaceSubset
|
||||
(
|
||||
const BoolListType& select,
|
||||
ListType& lst
|
||||
)
|
||||
{
|
||||
// select can have a different size
|
||||
// eg, when it is a PackedBoolList or a labelHashSet
|
||||
|
||||
label nElem = 0;
|
||||
forAll(lst, elemI)
|
||||
{
|
||||
if (select[elemI])
|
||||
{
|
||||
if (nElem != elemI)
|
||||
{
|
||||
|
||||
@ -83,25 +83,25 @@ unsigned int Foam::PackedList<nBits>::count() const
|
||||
|
||||
if (size_)
|
||||
{
|
||||
// mask value for complete chunks
|
||||
// mask value for complete segments
|
||||
unsigned int mask = maskLower(packing());
|
||||
|
||||
unsigned int endIdx = size_ / packing();
|
||||
unsigned int endOff = size_ % packing();
|
||||
const unsigned int endSeg = size_ / packing();
|
||||
const unsigned int endOff = size_ % packing();
|
||||
|
||||
// count bits in complete elements
|
||||
for (unsigned i = 0; i < endIdx; ++i)
|
||||
// count bits in complete segments
|
||||
for (unsigned i = 0; i < endSeg; ++i)
|
||||
{
|
||||
register unsigned int bits = StorageList::operator[](i) & mask;
|
||||
COUNT_PACKEDBITS(c, bits);
|
||||
}
|
||||
|
||||
// count bits in partial chunk
|
||||
// count bits in partial segment
|
||||
if (endOff)
|
||||
{
|
||||
mask = maskLower(endOff);
|
||||
|
||||
register unsigned int bits = StorageList::operator[](endIdx) & mask;
|
||||
register unsigned int bits = StorageList::operator[](endSeg) & mask;
|
||||
COUNT_PACKEDBITS(c, bits);
|
||||
}
|
||||
}
|
||||
@ -118,7 +118,7 @@ bool Foam::PackedList<nBits>::trim()
|
||||
return false;
|
||||
}
|
||||
|
||||
// mask value for complete chunks
|
||||
// mask value for complete segments
|
||||
unsigned int mask = maskLower(packing());
|
||||
|
||||
label currElem = packedLength(size_) - 1;
|
||||
@ -130,7 +130,7 @@ bool Foam::PackedList<nBits>::trim()
|
||||
StorageList::operator[](currElem) &= maskLower(endOff);
|
||||
}
|
||||
|
||||
// test entire chunk
|
||||
// test entire segment
|
||||
while (currElem > 0 && !(StorageList::operator[](currElem) &= mask))
|
||||
{
|
||||
currElem--;
|
||||
@ -162,10 +162,22 @@ bool Foam::PackedList<nBits>::trim()
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
void Foam::PackedList<nBits>::flip()
|
||||
{
|
||||
label packLen = packedLength(size_);
|
||||
|
||||
for (label i=0; i < packLen; i++)
|
||||
{
|
||||
StorageList::operator[](i) = ~StorageList::operator[](i);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
Foam::labelList Foam::PackedList<nBits>::values() const
|
||||
{
|
||||
labelList elems(size());
|
||||
labelList elems(size_);
|
||||
|
||||
forAll(*this, i)
|
||||
{
|
||||
@ -178,10 +190,11 @@ Foam::labelList Foam::PackedList<nBits>::values() const
|
||||
template<unsigned nBits>
|
||||
Foam::Ostream& Foam::PackedList<nBits>::iteratorBase::print(Ostream& os) const
|
||||
{
|
||||
os << "iterator<" << label(nBits) << "> ["
|
||||
<< (index_ * packing() + offset_) << "]"
|
||||
<< " index:" << index_ << " offset:" << offset_
|
||||
<< " value:" << unsigned(*this)
|
||||
os << "iterator<" << label(nBits) << "> ["
|
||||
<< this->index_ << "]"
|
||||
<< " segment:" << label(this->index_ / packing())
|
||||
<< " offset:" << label(this->index_ % packing())
|
||||
<< " value:" << this->get()
|
||||
<< nl;
|
||||
|
||||
return os;
|
||||
@ -194,7 +207,7 @@ Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const
|
||||
os << "PackedList<" << label(nBits) << ">"
|
||||
<< " max_value:" << max_value()
|
||||
<< " packing:" << packing() << nl
|
||||
<< "values: " << size() << "/" << capacity() << "( ";
|
||||
<< "values: " << size_ << "/" << capacity() << "( ";
|
||||
forAll(*this, i)
|
||||
{
|
||||
os << get(i) << ' ';
|
||||
@ -205,17 +218,17 @@ Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const
|
||||
os << ")\n"
|
||||
<< "storage: " << packLen << "/" << StorageList::size() << "( ";
|
||||
|
||||
// mask value for complete chunks
|
||||
// mask value for complete segments
|
||||
unsigned int mask = maskLower(packing());
|
||||
|
||||
for (label i=0; i < packLen; i++)
|
||||
{
|
||||
const StorageType& rawBits = StorageList::operator[](i);
|
||||
|
||||
// the final storage may not be full, modify mask accordingly
|
||||
// the final segment may not be full, modify mask accordingly
|
||||
if (i+1 == packLen)
|
||||
{
|
||||
unsigned endOff = size_ % packing();
|
||||
unsigned int endOff = size_ % packing();
|
||||
|
||||
if (endOff)
|
||||
{
|
||||
@ -229,7 +242,7 @@ Foam::Ostream& Foam::PackedList<nBits>::print(Ostream& os) const
|
||||
|
||||
for (unsigned int testBit = (1 << max_bits()); testBit; testBit >>= 1)
|
||||
{
|
||||
if (testBit & mask)
|
||||
if (mask & testBit)
|
||||
{
|
||||
if (rawBits & testBit)
|
||||
{
|
||||
|
||||
@ -44,9 +44,9 @@ Note
|
||||
Using the iteratorBase as a proxy allows assignment of values
|
||||
between list elements. Thus the following bit of code works as expected:
|
||||
@code
|
||||
blist[1] = blist[5]; // value assignment, not iterator position
|
||||
blist[2] = blist[5] = 4; // propagates value
|
||||
blist[1] = blist[5] = blist[6]; // propagates value
|
||||
list[1] = list[5]; // value assignment, not iterator position
|
||||
list[2] = list[5] = 4; // propagates value
|
||||
list[1] = list[5] = list[6]; // propagates value
|
||||
@endcode
|
||||
|
||||
Using get() or the '[]' operator are similarly fast. Looping and reading
|
||||
@ -58,11 +58,21 @@ Note
|
||||
useful for branching on changed values.
|
||||
|
||||
@code
|
||||
blist[5] = 4;
|
||||
changed = blist.set(5, 8);
|
||||
list[5] = 4;
|
||||
changed = list.set(5, 8);
|
||||
if (changed) ...
|
||||
@endcode
|
||||
|
||||
The lazy evaluation used means that reading an out-of-range element
|
||||
returns zero, but does not affect the list size. Even in a non-const
|
||||
context, only the assigment causes the element to be created.
|
||||
For example,
|
||||
@code
|
||||
list.resize(4);
|
||||
Info<< list[10] << "\n"; // print zero, but doesn't adjust list
|
||||
list[8] = 1;
|
||||
@endcode
|
||||
|
||||
SeeAlso
|
||||
Foam::DynamicList
|
||||
|
||||
@ -120,9 +130,6 @@ class PackedList
|
||||
//- Calculate the list length when packed
|
||||
inline static label packedLength(const label);
|
||||
|
||||
//- Check index I is within valid range [ 0 .. max_value() ]
|
||||
inline void checkIndex(const label) const;
|
||||
|
||||
public:
|
||||
|
||||
// Public data
|
||||
@ -172,22 +179,23 @@ public:
|
||||
|
||||
// Access
|
||||
|
||||
//- The number of elements that can be stored before resizing
|
||||
//- The number of elements that can be stored before reallocating
|
||||
inline label capacity() const;
|
||||
|
||||
//- Number of entries.
|
||||
inline label size() const;
|
||||
|
||||
//- Return true if the list is empty (i.e., if size() == 0).
|
||||
//- Return true if the list is empty (ie, size() is zero).
|
||||
inline bool empty() const;
|
||||
|
||||
//- Get value at index I.
|
||||
// Does not auto-vivify entries.
|
||||
// Never auto-vivify entries.
|
||||
inline unsigned int get(const label) const;
|
||||
|
||||
//- Set value at index I. Return true if value changed.
|
||||
// Does not auto-vivify entries.
|
||||
inline bool set(const label, const unsigned int val);
|
||||
// Does auto-vivify for non-existent entries.
|
||||
// Default value set is the max_value.
|
||||
inline bool set(const label, const unsigned int val = ~0u);
|
||||
|
||||
//- Return the underlying packed storage
|
||||
inline List<unsigned int>& storage();
|
||||
@ -200,9 +208,6 @@ public:
|
||||
// http://en.wikipedia.org/wiki/Hamming_weight
|
||||
unsigned int count() const;
|
||||
|
||||
//- Trim any trailing zero elements
|
||||
bool trim();
|
||||
|
||||
//- Return the values as a labelList
|
||||
labelList values() const;
|
||||
|
||||
@ -211,6 +216,12 @@ public:
|
||||
|
||||
// Edit
|
||||
|
||||
//- Trim any trailing zero elements
|
||||
bool trim();
|
||||
|
||||
//- Invert the bits in the addressable region.
|
||||
void flip();
|
||||
|
||||
//- Alter the size of the underlying storage.
|
||||
// The addressed size will be truncated if needed to fit, but will
|
||||
// remain otherwise untouched.
|
||||
@ -255,12 +266,12 @@ public:
|
||||
inline unsigned int remove();
|
||||
|
||||
//- Get value at index I
|
||||
// Does not auto-vivify entries.
|
||||
// Never auto-vivify entries.
|
||||
inline unsigned int operator[](const label) const;
|
||||
|
||||
//- Set value at index I.
|
||||
// Returns iterator to perform the actual operation.
|
||||
// Does not auto-vivify entries.
|
||||
// Does not auto-vivify entries, but will when assigned to.
|
||||
inline iteratorBase operator[](const label);
|
||||
|
||||
//- Assignment of all entries to the given value. Takes linear time.
|
||||
@ -294,52 +305,27 @@ public:
|
||||
// This also lets us use the default bitwise copy/assignment
|
||||
PackedList* list_;
|
||||
|
||||
//- Element index within storage
|
||||
unsigned index_;
|
||||
|
||||
//- Offset within storage element
|
||||
unsigned offset_;
|
||||
//- Element index
|
||||
label index_;
|
||||
|
||||
// Protected Member Functions
|
||||
|
||||
//- Get value as unsigned
|
||||
//- Get value as unsigned, no range-checking
|
||||
inline unsigned int get() const;
|
||||
|
||||
//- Set value, returning true if changed
|
||||
//- Set value, returning true if changed, no range-checking
|
||||
inline bool set(unsigned int);
|
||||
|
||||
//- Increment to new position
|
||||
inline void incr();
|
||||
|
||||
//- Decrement to new position
|
||||
inline void decr();
|
||||
|
||||
//- Move to new position, but not beyond end()
|
||||
inline void seek(const iteratorBase&);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline iteratorBase();
|
||||
|
||||
//- Copy construct
|
||||
inline iteratorBase(const iteratorBase&);
|
||||
|
||||
//- Construct from base list and position index
|
||||
inline iteratorBase(const PackedList*, const label);
|
||||
|
||||
public:
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Return true if the element is within addressable range
|
||||
inline bool valid() const;
|
||||
|
||||
//- Move iterator to end() if it would otherwise be out-of-range
|
||||
// Returns true if the element was already ok
|
||||
inline bool validate();
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Compare positions
|
||||
@ -350,10 +336,12 @@ public:
|
||||
// This allows packed[0] = packed[3] for assigning values
|
||||
inline unsigned int operator=(const iteratorBase&);
|
||||
|
||||
//- Assign value
|
||||
//- Assign value.
|
||||
// A non-existent entry will be auto-vivified.
|
||||
inline unsigned int operator=(const unsigned int val);
|
||||
|
||||
//- Conversion operator
|
||||
// Never auto-vivify entries.
|
||||
inline operator unsigned int () const;
|
||||
|
||||
//- Print value and information
|
||||
@ -378,6 +366,8 @@ public:
|
||||
inline iterator();
|
||||
|
||||
//- Construct from iterator base, eg iter(packedlist[i])
|
||||
// but also "iterator iter = packedlist[i];"
|
||||
// An out-of-range iterator is assigned end()
|
||||
inline iterator(const iteratorBase&);
|
||||
|
||||
//- Construct from base list and position index
|
||||
@ -386,6 +376,7 @@ public:
|
||||
// Member Operators
|
||||
|
||||
//- Assign from iteratorBase, eg iter = packedlist[i]
|
||||
// An out-of-range iterator is assigned end()
|
||||
inline iterator& operator=(const iteratorBase&);
|
||||
|
||||
//- Return value
|
||||
@ -427,7 +418,9 @@ public:
|
||||
//- Construct null
|
||||
inline const_iterator();
|
||||
|
||||
//- Construct from iterator base
|
||||
//- Construct from iterator base, eg iter(packedlist[i])
|
||||
// but also "const_iterator iter = packedlist[i];"
|
||||
// An out-of-range iterator is assigned end()
|
||||
inline const_iterator(const iteratorBase&);
|
||||
|
||||
//- Construct from base list and position index
|
||||
@ -439,7 +432,7 @@ public:
|
||||
// Member operators
|
||||
|
||||
//- Assign from iteratorBase or derived
|
||||
// eg, iter = packedlist[i] or iter = [non-const]list.begin()
|
||||
// eg, iter = packedlist[i] or even iter = list.begin()
|
||||
inline const_iterator& operator=(const iteratorBase&);
|
||||
|
||||
//- Return referenced value directly
|
||||
|
||||
@ -65,24 +65,6 @@ inline Foam::label Foam::PackedList<nBits>::packedLength(const label nElem)
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline void Foam::PackedList<nBits>::checkIndex(const label i) const
|
||||
{
|
||||
if (!size_)
|
||||
{
|
||||
FatalErrorIn("PackedList<nBits>::checkIndex(const label)")
|
||||
<< "attempt to access element from zero-sized list"
|
||||
<< abort(FatalError);
|
||||
}
|
||||
else if (i < 0 || i >= size_)
|
||||
{
|
||||
FatalErrorIn("PackedList<nBits>::checkIndex(const label)")
|
||||
<< "index " << i << " out of range 0 ... " << size_-1
|
||||
<< abort(FatalError);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
template<unsigned nBits>
|
||||
@ -105,7 +87,7 @@ template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::PackedList(const PackedList<nBits>& lst)
|
||||
:
|
||||
StorageList(lst),
|
||||
size_(lst.size())
|
||||
size_(lst.size_)
|
||||
{}
|
||||
|
||||
|
||||
@ -132,20 +114,7 @@ template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::iteratorBase::iteratorBase()
|
||||
:
|
||||
list_(0),
|
||||
index_(0),
|
||||
offset_(0)
|
||||
{}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::iteratorBase::iteratorBase
|
||||
(
|
||||
const iteratorBase& iter
|
||||
)
|
||||
:
|
||||
list_(iter.list_),
|
||||
index_(iter.index_),
|
||||
offset_(iter.offset_)
|
||||
index_(0)
|
||||
{}
|
||||
|
||||
|
||||
@ -157,8 +126,7 @@ inline Foam::PackedList<nBits>::iteratorBase::iteratorBase
|
||||
)
|
||||
:
|
||||
list_(const_cast<PackedList<nBits>*>(lst)),
|
||||
index_(i / packing()),
|
||||
offset_(i % packing())
|
||||
index_(i)
|
||||
{}
|
||||
|
||||
|
||||
@ -166,8 +134,11 @@ template<unsigned nBits>
|
||||
inline unsigned int
|
||||
Foam::PackedList<nBits>::iteratorBase::get() const
|
||||
{
|
||||
const unsigned int& stored = list_->StorageList::operator[](index_);
|
||||
return (stored >> (nBits * offset_)) & max_value();
|
||||
const unsigned int seg = index_ / packing();
|
||||
const unsigned int off = index_ % packing();
|
||||
|
||||
const unsigned int& stored = list_->StorageList::operator[](seg);
|
||||
return (stored >> (nBits * off)) & max_value();
|
||||
}
|
||||
|
||||
|
||||
@ -175,114 +146,37 @@ template<unsigned nBits>
|
||||
inline bool
|
||||
Foam::PackedList<nBits>::iteratorBase::set(const unsigned int val)
|
||||
{
|
||||
unsigned int& stored = list_->StorageList::operator[](index_);
|
||||
const unsigned int seg = index_ / packing();
|
||||
const unsigned int off = index_ % packing();
|
||||
|
||||
unsigned int& stored = list_->StorageList::operator[](seg);
|
||||
const unsigned int prev = stored;
|
||||
|
||||
const unsigned int startBit = nBits * offset_;
|
||||
const unsigned int startBit = nBits * off;
|
||||
const unsigned int maskNew = max_value() << startBit;
|
||||
|
||||
if (val & ~max_value())
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
FatalErrorIn("PackedList<T>::iteratorBase::set(const unsigned int)")
|
||||
<< "value " << label(val)
|
||||
w << " out-of-range 0 ... " << label(max_value())
|
||||
<< " representable by " << nBits << " bits"
|
||||
<< abort(FatalError);
|
||||
# endif
|
||||
|
||||
// treat overflow as max_value
|
||||
// overflow is max_value, fill everything
|
||||
stored |= maskNew;
|
||||
}
|
||||
else
|
||||
{
|
||||
stored = (stored & ~maskNew) | (maskNew & (val << startBit));
|
||||
stored &= ~maskNew;
|
||||
stored |= maskNew & (val << startBit);
|
||||
}
|
||||
|
||||
return prev != stored;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline void
|
||||
Foam::PackedList<nBits>::iteratorBase::incr()
|
||||
{
|
||||
offset_++;
|
||||
if (offset_ >= packing())
|
||||
{
|
||||
offset_ = 0;
|
||||
index_++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline void
|
||||
Foam::PackedList<nBits>::iteratorBase::decr()
|
||||
{
|
||||
if (!offset_)
|
||||
{
|
||||
offset_ = packing();
|
||||
index_--;
|
||||
}
|
||||
offset_--;
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline void
|
||||
Foam::PackedList<nBits>::iteratorBase::seek
|
||||
(
|
||||
const iteratorBase& iter
|
||||
)
|
||||
{
|
||||
list_ = iter.list_;
|
||||
index_ = iter.index_;
|
||||
offset_ = iter.offset_;
|
||||
|
||||
this->validate();
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline bool
|
||||
Foam::PackedList<nBits>::iteratorBase::valid() const
|
||||
{
|
||||
label elemI = offset_ + index_ * packing();
|
||||
return (elemI < list_->size_);
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline bool
|
||||
Foam::PackedList<nBits>::iteratorBase::validate()
|
||||
{
|
||||
// avoid going past end()
|
||||
unsigned endIdx = list_->size_ / packing();
|
||||
unsigned endOff = list_->size_ % packing();
|
||||
|
||||
if (index_ > endIdx || (index_ == endIdx && offset_ > endOff))
|
||||
{
|
||||
index_ = endIdx;
|
||||
offset_ = endOff;
|
||||
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline bool Foam::PackedList<nBits>::iteratorBase::operator==
|
||||
(
|
||||
const iteratorBase& iter
|
||||
) const
|
||||
{
|
||||
return this->index_ == iter.index_ && this->offset_ == iter.offset_;
|
||||
return this->index_ == iter.index_;
|
||||
}
|
||||
|
||||
|
||||
@ -292,7 +186,7 @@ inline bool Foam::PackedList<nBits>::iteratorBase::operator!=
|
||||
const iteratorBase& iter
|
||||
) const
|
||||
{
|
||||
return this->index_ != iter.index_ || this->offset_ != iter.offset_;
|
||||
return this->index_ != iter.index_;
|
||||
}
|
||||
|
||||
|
||||
@ -310,14 +204,11 @@ template<unsigned nBits>
|
||||
inline unsigned int
|
||||
Foam::PackedList<nBits>::iteratorBase::operator=(const unsigned int val)
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
// lazy evaluation would be nice to keep, but really slows things down
|
||||
label minsize = 1 + offset_ + index_ * packing();
|
||||
if (minsize > list_->size_)
|
||||
// lazy evaluation - increase size on assigment
|
||||
if (index_ >= list_->size_)
|
||||
{
|
||||
list_->resize(minsize);
|
||||
list_->resize(index_ + 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
this->set(val);
|
||||
return val;
|
||||
@ -328,14 +219,11 @@ template<unsigned nBits>
|
||||
inline Foam::PackedList<nBits>::iteratorBase::operator
|
||||
unsigned int () const
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
// lazy evaluation would be nice to keep, but really slows things down
|
||||
label minsize = 1 + offset_ + index_ * packing();
|
||||
if (minsize > list_->size_)
|
||||
// lazy evaluation - return 0 for out-of-range
|
||||
if (index_ >= list_->size_)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return this->get();
|
||||
}
|
||||
@ -365,7 +253,12 @@ inline Foam::PackedList<nBits>::iterator::iterator
|
||||
:
|
||||
iteratorBase(iter)
|
||||
{
|
||||
this->validate();
|
||||
// avoid going past end()
|
||||
// eg, iter = iterator(list, Inf)
|
||||
if (this->index_ > this->list_->size_)
|
||||
{
|
||||
this->index_ = this->list_->size_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -377,7 +270,12 @@ inline Foam::PackedList<nBits>::const_iterator::const_iterator
|
||||
:
|
||||
iteratorBase(iter)
|
||||
{
|
||||
this->validate();
|
||||
// avoid going past end()
|
||||
// eg, iter = iterator(list, Inf)
|
||||
if (this->index_ > this->list_->size_)
|
||||
{
|
||||
this->index_ = this->list_->size_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -417,7 +315,16 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::iterator&
|
||||
Foam::PackedList<nBits>::iterator::operator=(const iteratorBase& iter)
|
||||
{
|
||||
this->seek(iter);
|
||||
this->list_ = iter.list_;
|
||||
this->index_ = iter.index_;
|
||||
|
||||
// avoid going past end()
|
||||
// eg, iter = iterator(list, Inf)
|
||||
if (this->index_ > this->list_->size_)
|
||||
{
|
||||
this->index_ = this->list_->size_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -426,7 +333,16 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::const_iterator&
|
||||
Foam::PackedList<nBits>::const_iterator::operator=(const iteratorBase& iter)
|
||||
{
|
||||
this->seek(iter);
|
||||
this->list_ = iter.list_;
|
||||
this->index_ = iter.index_;
|
||||
|
||||
// avoid going past end()
|
||||
// eg, iter = iterator(list, Inf)
|
||||
if (this->index_ > this->list_->size_)
|
||||
{
|
||||
this->index_ = this->list_->size_;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -435,7 +351,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::iterator&
|
||||
Foam::PackedList<nBits>::iterator::operator++()
|
||||
{
|
||||
this->incr();
|
||||
++this->index_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -444,7 +360,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::const_iterator&
|
||||
Foam::PackedList<nBits>::const_iterator::operator++()
|
||||
{
|
||||
this->incr();
|
||||
++this->index_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -454,7 +370,7 @@ inline typename Foam::PackedList<nBits>::iterator
|
||||
Foam::PackedList<nBits>::iterator::operator++(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
this->incr();
|
||||
++this->index_;
|
||||
return old;
|
||||
}
|
||||
|
||||
@ -464,7 +380,7 @@ inline typename Foam::PackedList<nBits>::const_iterator
|
||||
Foam::PackedList<nBits>::const_iterator::operator++(int)
|
||||
{
|
||||
const_iterator old = *this;
|
||||
this->incr();
|
||||
++this->index_;
|
||||
return old;
|
||||
}
|
||||
|
||||
@ -473,7 +389,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::iterator&
|
||||
Foam::PackedList<nBits>::iterator::operator--()
|
||||
{
|
||||
this->decr();
|
||||
--this->index_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -482,7 +398,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::const_iterator&
|
||||
Foam::PackedList<nBits>::const_iterator::operator--()
|
||||
{
|
||||
this->decr();
|
||||
--this->index_;
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -492,7 +408,7 @@ inline typename Foam::PackedList<nBits>::iterator
|
||||
Foam::PackedList<nBits>::iterator::operator--(int)
|
||||
{
|
||||
iterator old = *this;
|
||||
this->decr();
|
||||
--this->index_;
|
||||
return old;
|
||||
}
|
||||
|
||||
@ -502,7 +418,7 @@ inline typename Foam::PackedList<nBits>::const_iterator
|
||||
Foam::PackedList<nBits>::const_iterator::operator--(int)
|
||||
{
|
||||
const_iterator old = *this;
|
||||
this->decr();
|
||||
--this->index_;
|
||||
return old;
|
||||
}
|
||||
|
||||
@ -567,7 +483,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::iterator
|
||||
Foam::PackedList<nBits>::end()
|
||||
{
|
||||
return iterator(this, this->size());
|
||||
return iterator(this, size_);
|
||||
}
|
||||
|
||||
|
||||
@ -575,7 +491,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::const_iterator
|
||||
Foam::PackedList<nBits>::end() const
|
||||
{
|
||||
return const_iterator(this, this->size());
|
||||
return const_iterator(this, size_);
|
||||
}
|
||||
|
||||
|
||||
@ -583,7 +499,7 @@ template<unsigned nBits>
|
||||
inline typename Foam::PackedList<nBits>::const_iterator
|
||||
Foam::PackedList<nBits>::cend() const
|
||||
{
|
||||
return const_iterator(this, this->size());
|
||||
return const_iterator(this, size_);
|
||||
}
|
||||
|
||||
|
||||
@ -617,20 +533,12 @@ inline void Foam::PackedList<nBits>::resize
|
||||
// fill new elements or newly exposed elements
|
||||
if (size_)
|
||||
{
|
||||
// fill value for complete chunks
|
||||
// fill value for complete segments
|
||||
unsigned int fill = val;
|
||||
|
||||
if (fill & ~max_value())
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
FatalErrorIn("PackedList<T>::resize(label, const unsigned int)")
|
||||
<< "value " << label(val)
|
||||
<< " out-of-range 0 ... " << label(max_value())
|
||||
<< " representable by " << nBits << " bits"
|
||||
<< abort(FatalError);
|
||||
# endif
|
||||
|
||||
// treat overflow as max_value, fill everything
|
||||
// overflow is max_value, fill everything
|
||||
fill = ~0;
|
||||
}
|
||||
else
|
||||
@ -641,26 +549,26 @@ inline void Foam::PackedList<nBits>::resize
|
||||
}
|
||||
}
|
||||
|
||||
unsigned begIdx = size_ / packing();
|
||||
unsigned begOff = size_ % packing();
|
||||
unsigned endIdx = nElem / packing();
|
||||
unsigned int seg = size_ / packing();
|
||||
unsigned int off = size_ % packing();
|
||||
|
||||
// partial chunk, preserve existing value
|
||||
if (begOff)
|
||||
// partial segment, preserve existing value
|
||||
if (off)
|
||||
{
|
||||
unsigned int maskOld = maskLower(begOff);
|
||||
unsigned int maskOld = maskLower(off);
|
||||
|
||||
StorageList::operator[](begIdx) &= maskOld;
|
||||
StorageList::operator[](begIdx) |= ~maskOld & fill;
|
||||
StorageList::operator[](seg) &= maskOld;
|
||||
StorageList::operator[](seg) |= ~maskOld & fill;
|
||||
|
||||
// continue with the next chunk
|
||||
begIdx++;
|
||||
// continue with the next segment
|
||||
seg++;
|
||||
}
|
||||
|
||||
unsigned int endSeg = nElem / packing();
|
||||
// fill in complete elements
|
||||
while (begIdx < endIdx)
|
||||
while (seg < endSeg)
|
||||
{
|
||||
StorageList::operator[](begIdx++) = fill;
|
||||
StorageList::operator[](seg++) = fill;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -786,17 +694,31 @@ Foam::PackedList<nBits>::xfer()
|
||||
template<unsigned nBits>
|
||||
inline unsigned int Foam::PackedList<nBits>::get(const label i) const
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
checkIndex(i);
|
||||
# ifdef FULLDEBUG
|
||||
if (i < 0)
|
||||
{
|
||||
FatalErrorIn("PackedList<nBits>::get(const label)")
|
||||
<< "negative index " << i << " max=" << size_-1
|
||||
<< abort(FatalError);
|
||||
}
|
||||
# endif
|
||||
|
||||
return iteratorBase(this, i).get();
|
||||
// lazy evaluation - return 0 for out-of-range
|
||||
if (i < size_)
|
||||
{
|
||||
return iteratorBase(this, i).get();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template<unsigned nBits>
|
||||
inline unsigned int Foam::PackedList<nBits>::operator[](const label i) const
|
||||
{
|
||||
// lazy evaluation - return 0 for out-of-range
|
||||
if (i < size_)
|
||||
{
|
||||
return iteratorBase(this, i).get();
|
||||
@ -815,18 +737,21 @@ inline bool Foam::PackedList<nBits>::set
|
||||
const unsigned int val
|
||||
)
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
checkIndex(i);
|
||||
|
||||
if (val & ~max_value())
|
||||
# ifdef FULLDEBUG
|
||||
if (i < 0)
|
||||
{
|
||||
FatalErrorIn("PackedList<T>::set(const label, const unsigned int)")
|
||||
<< "value " << label(val)
|
||||
<< " out-of-range 0 ... " << label(max_value())
|
||||
<< " representable by " << nBits << " bits"
|
||||
FatalErrorIn("PackedList<nBits>::set(const label)")
|
||||
<< "negative index " << i << " max=" << size_-1
|
||||
<< abort(FatalError);
|
||||
}
|
||||
# endif
|
||||
#endif
|
||||
|
||||
// lazy evaluation - increase size on assigment
|
||||
if (i >= size_)
|
||||
{
|
||||
resize(i + 1);
|
||||
}
|
||||
|
||||
return iteratorBase(this, i).set(val);
|
||||
}
|
||||
|
||||
@ -879,14 +804,6 @@ inline void Foam::PackedList<nBits>::operator=(const unsigned int val)
|
||||
|
||||
if (fill & ~max_value())
|
||||
{
|
||||
# ifdef DEBUGList
|
||||
FatalErrorIn("PackedList<T>::operator=(const unsigned int)")
|
||||
<< "value " << label(val)
|
||||
<< " out-of-range 0 ... " << label(max_value())
|
||||
<< " representable by " << nBits << " bits"
|
||||
<< abort(FatalError);
|
||||
# endif
|
||||
|
||||
// treat overflow as max_value
|
||||
fill = ~0;
|
||||
}
|
||||
|
||||
@ -158,7 +158,7 @@ public:
|
||||
//- Return the number of elements in the PtrList
|
||||
inline label size() const;
|
||||
|
||||
//- Return true if the PtrList is empty (i.e., if size() == 0).
|
||||
//- Return true if the PtrList is empty (ie, size() is zero).
|
||||
inline bool empty() const;
|
||||
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ Class
|
||||
|
||||
Description
|
||||
A 1D vector of objects of type \<T\>, where the size of the vector is
|
||||
known and used for subscript bounds checking, etc.
|
||||
known and can be used for subscript bounds checking, etc.
|
||||
|
||||
Storage is not allocated during construction or use but is supplied to
|
||||
the constructor as an argument. This type of list is particularly useful
|
||||
@ -140,6 +140,17 @@ public:
|
||||
label byteSize() const;
|
||||
|
||||
|
||||
//- Return a const pointer to the first data element,
|
||||
// similar to the STL front() method and the string::data() method
|
||||
// This can be used (with caution) when interfacing with C code.
|
||||
inline const T* cdata() const;
|
||||
|
||||
//- Return a pointer to the first data element,
|
||||
// similar to the STL front() method and the string::data() method
|
||||
// This can be used (with caution) when interfacing with C code.
|
||||
inline T* data();
|
||||
|
||||
|
||||
// Check
|
||||
|
||||
//- Check start is within valid range (0 ... size-1).
|
||||
@ -164,10 +175,12 @@ public:
|
||||
|
||||
// Member operators
|
||||
|
||||
//- Return subscript-checked element of UList.
|
||||
//- Return element of UList.
|
||||
inline T& operator[](const label);
|
||||
|
||||
//- Return subscript-checked element of constant UList.
|
||||
//- Return element of constant UList.
|
||||
// Note that the bool specialization adds lazy evaluation so reading
|
||||
// an out-of-range element returns false without any ill-effects
|
||||
inline const T& operator[](const label) const;
|
||||
|
||||
//- Allow cast to a const List<T>&
|
||||
@ -266,7 +279,7 @@ public:
|
||||
//- Return size of the largest possible UList.
|
||||
inline label max_size() const;
|
||||
|
||||
//- Return true if the UList is empty (i.e., if size() == 0).
|
||||
//- Return true if the UList is empty (ie, size() is zero).
|
||||
inline bool empty() const;
|
||||
|
||||
//- Swap two ULists of the same type in constant time.
|
||||
|
||||
@ -25,6 +25,7 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "error.H"
|
||||
#include "pTraits.H"
|
||||
#include "Swap.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
@ -64,7 +65,7 @@ inline Foam::label Foam::UList<T>::fcIndex(const label i) const
|
||||
template<class T>
|
||||
inline Foam::label Foam::UList<T>::rcIndex(const label i) const
|
||||
{
|
||||
return (i == 0 ? size()-1 : i-1);
|
||||
return (i ? i-1 : size()-1);
|
||||
}
|
||||
|
||||
|
||||
@ -113,9 +114,24 @@ inline void Foam::UList<T>::checkIndex(const label i) const
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline const T* Foam::UList<T>::cdata() const
|
||||
{
|
||||
return v_;
|
||||
}
|
||||
|
||||
|
||||
template<class T>
|
||||
inline T* Foam::UList<T>::data()
|
||||
{
|
||||
return v_;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
|
||||
|
||||
// Return subscript-checked element access
|
||||
|
||||
// element access
|
||||
template<class T>
|
||||
inline T& Foam::UList<T>::operator[](const label i)
|
||||
{
|
||||
@ -126,7 +142,28 @@ inline T& Foam::UList<T>::operator[](const label i)
|
||||
}
|
||||
|
||||
|
||||
// Return subscript-checked const element access
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Template specialization for bool
|
||||
template<>
|
||||
inline const bool& Foam::UList<bool>::operator[](const label i) const
|
||||
{
|
||||
// lazy evaluation - return false for out-of-range
|
||||
if (i < size_)
|
||||
{
|
||||
return v_[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
return Foam::pTraits<bool>::zero;
|
||||
}
|
||||
}
|
||||
|
||||
} // end of namespace Foam
|
||||
|
||||
|
||||
// const element access
|
||||
template<class T>
|
||||
inline const T& Foam::UList<T>::operator[](const label i) const
|
||||
{
|
||||
@ -248,7 +285,7 @@ inline Foam::label Foam::UList<T>::max_size() const
|
||||
template<class T>
|
||||
inline bool Foam::UList<T>::empty() const
|
||||
{
|
||||
return (size_ == 0);
|
||||
return !size_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -124,7 +124,7 @@ public:
|
||||
//- Return the number of elements in the UPtrList
|
||||
inline label size() const;
|
||||
|
||||
//- Return true if the UPtrList is empty (i.e., if size() == 0).
|
||||
//- Return true if the UPtrList is empty (ie, size() is zero).
|
||||
inline bool empty() const;
|
||||
|
||||
|
||||
|
||||
@ -35,6 +35,85 @@ namespace Foam
|
||||
defineTypeNameAndDebug(IOobject, 0);
|
||||
}
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
// Return components following the IOobject requirements
|
||||
//
|
||||
// behaviour
|
||||
// input IOobject(instance, local, name)
|
||||
// ----- ------
|
||||
// "foo" ("", "", "foo")
|
||||
// "foo/bar" ("foo", "", "bar")
|
||||
// "/XXX" ERROR - no absolute path
|
||||
// "foo/bar/" ERROR - no name
|
||||
// "foo/xxx/bar" ("foo", "xxx", "bar")
|
||||
// "foo/xxx/yyy/bar" ("foo", "xxx/yyy", "bar")
|
||||
bool Foam::IOobject::IOobject::fileNameComponents
|
||||
(
|
||||
const fileName& path,
|
||||
fileName& instance,
|
||||
fileName& local,
|
||||
word& name
|
||||
)
|
||||
{
|
||||
instance.clear();
|
||||
local.clear();
|
||||
name.clear();
|
||||
|
||||
// called with directory
|
||||
if (!isDir(path))
|
||||
{
|
||||
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||
<< " called with directory: " << path << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
string::size_type first = path.find('/');
|
||||
|
||||
if (first == 0)
|
||||
{
|
||||
// called with absolute path
|
||||
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||
<< "called with absolute path: " << path << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if (first == string::npos)
|
||||
{
|
||||
// no '/' found - no instance or local
|
||||
|
||||
// check afterwards
|
||||
name.string::operator=(path);
|
||||
}
|
||||
else
|
||||
{
|
||||
instance = path.substr(0, first);
|
||||
|
||||
string::size_type last = path.rfind('/');
|
||||
if (last > first)
|
||||
{
|
||||
// with local
|
||||
local = path.substr(first+1, last-first-1);
|
||||
}
|
||||
|
||||
// check afterwards
|
||||
name.string::operator=(path.substr(last+1));
|
||||
}
|
||||
|
||||
|
||||
// check for valid (and stripped) name, regardless of the debug level
|
||||
if (name.empty() || string::stripInvalid<word>(name))
|
||||
{
|
||||
WarningIn("IOobject::fileNameComponents(const fileName&, ...)")
|
||||
<< "has invalid word for name: \"" << name
|
||||
<< "\"\nwhile processing path: " << path << "\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::IOobject::IOobject
|
||||
@ -118,7 +197,15 @@ Foam::IOobject::IOobject
|
||||
registerObject_(registerObject),
|
||||
objState_(GOOD)
|
||||
{
|
||||
path.IOobjectComponents(instance_, local_, name_);
|
||||
if (!fileNameComponents(path, instance_, local_, name_))
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
"IOobject::IOobject" "(const fileName&, const objectRegistry&, ...)"
|
||||
)
|
||||
<< " invalid path specification\n"
|
||||
<< exit(FatalError);
|
||||
}
|
||||
|
||||
if (objectRegistry::debug)
|
||||
{
|
||||
@ -182,7 +269,7 @@ Foam::fileName Foam::IOobject::filePath() const
|
||||
fileName path = this->path();
|
||||
fileName objectPath = path/name();
|
||||
|
||||
if (file(objectPath))
|
||||
if (isFile(objectPath))
|
||||
{
|
||||
return objectPath;
|
||||
}
|
||||
@ -201,13 +288,13 @@ Foam::fileName Foam::IOobject::filePath() const
|
||||
rootPath()/caseName()
|
||||
/".."/instance()/db_.dbDir()/local()/name();
|
||||
|
||||
if (file(parentObjectPath))
|
||||
if (isFile(parentObjectPath))
|
||||
{
|
||||
return parentObjectPath;
|
||||
}
|
||||
}
|
||||
|
||||
if (!dir(path))
|
||||
if (!isDir(path))
|
||||
{
|
||||
word newInstancePath = time().findInstancePath(instant(instance()));
|
||||
|
||||
@ -219,7 +306,7 @@ Foam::fileName Foam::IOobject::filePath() const
|
||||
/newInstancePath/db_.dbDir()/local()/name()
|
||||
);
|
||||
|
||||
if (file(fName))
|
||||
if (isFile(fName))
|
||||
{
|
||||
return fName;
|
||||
}
|
||||
@ -235,7 +322,7 @@ Foam::Istream* Foam::IOobject::objectStream()
|
||||
{
|
||||
fileName fName = filePath();
|
||||
|
||||
if (fName != fileName::null)
|
||||
if (fName.size())
|
||||
{
|
||||
IFstream* isPtr = new IFstream(fName);
|
||||
|
||||
|
||||
@ -149,7 +149,6 @@ private:
|
||||
//- IOobject state
|
||||
objectState objState_;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
// Protected member functions
|
||||
@ -168,6 +167,18 @@ public:
|
||||
TypeName("IOobject");
|
||||
|
||||
|
||||
// Static Member Functions
|
||||
|
||||
//- Split path into instance, local, name components
|
||||
static bool fileNameComponents
|
||||
(
|
||||
const fileName& path,
|
||||
fileName& instance,
|
||||
fileName& local,
|
||||
word& name
|
||||
);
|
||||
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct from name, instance, registry, io options
|
||||
@ -194,6 +205,7 @@ public:
|
||||
);
|
||||
|
||||
//- Construct from path, registry, io options
|
||||
// Uses fileNameComponents() to split path into components.
|
||||
IOobject
|
||||
(
|
||||
const fileName& path,
|
||||
@ -215,7 +227,7 @@ public:
|
||||
virtual ~IOobject();
|
||||
|
||||
|
||||
// Member functions
|
||||
// Member Functions
|
||||
|
||||
// General access
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ Foam::IOobjectList::IOobjectList
|
||||
{
|
||||
word newInstance = instance;
|
||||
|
||||
if (!dir(db.path(instance)))
|
||||
if (!isDir(db.path(instance)))
|
||||
{
|
||||
newInstance = db.time().findInstancePath(instant(instance));
|
||||
|
||||
@ -59,7 +59,7 @@ Foam::IOobjectList::IOobjectList
|
||||
}
|
||||
|
||||
// Create list file names in directory
|
||||
fileNameList ObjectNames =
|
||||
fileNameList ObjectNames =
|
||||
readDir(db.path(newInstance, db.dbDir()/local), fileName::FILE);
|
||||
|
||||
forAll(ObjectNames, i)
|
||||
|
||||
@ -54,7 +54,7 @@ Foam::IFstreamAllocator::IFstreamAllocator(const fileName& pathname)
|
||||
ifPtr_ = new ifstream(pathname.c_str());
|
||||
|
||||
// If the file is compressed, decompress it before reading.
|
||||
if (!ifPtr_->good() && file(pathname + ".gz"))
|
||||
if (!ifPtr_->good() && isFile(pathname + ".gz", false))
|
||||
{
|
||||
if (IFstream::debug)
|
||||
{
|
||||
@ -120,8 +120,8 @@ Foam::IFstream::IFstream
|
||||
if (debug)
|
||||
{
|
||||
Info<< "IFstream::IFstream(const fileName&,"
|
||||
"streamFormat format=ASCII,"
|
||||
"versionNumber version=currentVersion) : "
|
||||
"streamFormat=ASCII,"
|
||||
"versionNumber=currentVersion) : "
|
||||
"could not open file for input"
|
||||
<< endl << info() << endl;
|
||||
}
|
||||
@ -159,17 +159,18 @@ Foam::IFstream& Foam::IFstream::operator()() const
|
||||
{
|
||||
if (!good())
|
||||
{
|
||||
if (!file(pathname_) && !file(pathname_ + ".gz"))
|
||||
// also checks .gz file
|
||||
if (isFile(pathname_, true))
|
||||
{
|
||||
check("IFstream::operator()");
|
||||
FatalIOError.exit();
|
||||
}
|
||||
else
|
||||
{
|
||||
FatalIOErrorIn("IFstream::operator()", *this)
|
||||
<< "file " << pathname_ << " does not exist"
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
else
|
||||
{
|
||||
check("IFstream::operator()");
|
||||
FatalIOError.exit();
|
||||
}
|
||||
}
|
||||
|
||||
return const_cast<IFstream&>(*this);
|
||||
|
||||
@ -57,7 +57,8 @@ Foam::OFstreamAllocator::OFstreamAllocator
|
||||
|
||||
if (compression == IOstream::COMPRESSED)
|
||||
{
|
||||
if (file(pathname))
|
||||
// get identically named uncompressed version out of the way
|
||||
if (isFile(pathname, false))
|
||||
{
|
||||
rm(pathname);
|
||||
}
|
||||
@ -66,7 +67,8 @@ Foam::OFstreamAllocator::OFstreamAllocator
|
||||
}
|
||||
else
|
||||
{
|
||||
if (file(pathname + ".gz"))
|
||||
// get identically named compressed version out of the way
|
||||
if (isFile(pathname + ".gz", false))
|
||||
{
|
||||
rm(pathname + ".gz");
|
||||
}
|
||||
|
||||
212
src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H
Normal file
212
src/OpenFOAM/db/IOstreams/hashes/OSHA1stream.H
Normal file
@ -0,0 +1,212 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::OSHA1stream
|
||||
|
||||
Description
|
||||
An output stream for calculating SHA1 digests.
|
||||
|
||||
SourceFiles
|
||||
OSHA1stream.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef OSHA1stream_H
|
||||
#define OSHA1stream_H
|
||||
|
||||
#include "OSstream.H"
|
||||
#include "SHA1.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
class osha1stream;
|
||||
class OSHA1stream;
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class sha1streambuf Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- A streambuf class for calculating SHA1 digests
|
||||
class sha1streambuf
|
||||
:
|
||||
public std::streambuf
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- This does all the work and has its own buffering
|
||||
SHA1 sha1_;
|
||||
|
||||
friend class osha1stream;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
sha1streambuf()
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Write
|
||||
|
||||
//- Process unbuffered
|
||||
virtual std::streamsize xsputn(const char* str, std::streamsize n)
|
||||
{
|
||||
sha1_.append(str, n);
|
||||
return n;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class osha1stream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- A basic output stream for calculating SHA1 digests
|
||||
class osha1stream
|
||||
:
|
||||
virtual public std::ios,
|
||||
public std::ostream
|
||||
{
|
||||
// Private data
|
||||
|
||||
sha1streambuf sbuf_;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
osha1stream()
|
||||
:
|
||||
std::ostream(&sbuf_)
|
||||
{}
|
||||
|
||||
// Member Functions
|
||||
|
||||
// Access
|
||||
|
||||
//- This hides both signatures of std::basic_ios::rdbuf()
|
||||
sha1streambuf* rdbuf()
|
||||
{
|
||||
return &sbuf_;
|
||||
}
|
||||
|
||||
//- Full access to the sha1
|
||||
SHA1& sha1()
|
||||
{
|
||||
return sbuf_.sha1_;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class OSHA1stream Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
//- The output stream for calculating SHA1 digests
|
||||
class OSHA1stream
|
||||
:
|
||||
public OSstream
|
||||
{
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Disallow default bitwise copy construct
|
||||
OSHA1stream(const OSHA1stream&);
|
||||
|
||||
//- Disallow default bitwise assignment
|
||||
void operator=(const OSHA1stream&);
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct and set stream status
|
||||
OSHA1stream
|
||||
(
|
||||
streamFormat format=ASCII,
|
||||
versionNumber version=currentVersion
|
||||
)
|
||||
:
|
||||
OSstream
|
||||
(
|
||||
*(new osha1stream),
|
||||
"OSHA1stream.sinkFile_",
|
||||
format,
|
||||
version
|
||||
)
|
||||
{}
|
||||
|
||||
|
||||
// Destructor
|
||||
|
||||
~OSHA1stream()
|
||||
{
|
||||
delete &dynamic_cast<osha1stream&>(stream());
|
||||
}
|
||||
|
||||
|
||||
// Member functions
|
||||
|
||||
// Access
|
||||
|
||||
//- Full access to the sha1
|
||||
Foam::SHA1& sha1()
|
||||
{
|
||||
return dynamic_cast<osha1stream&>(stream()).sha1();
|
||||
}
|
||||
|
||||
//- Return SHA1::Digest for the data processed until now
|
||||
Foam::SHA1Digest digest()
|
||||
{
|
||||
return sha1().digest();
|
||||
}
|
||||
|
||||
// Edit
|
||||
|
||||
//- Clear the SHA1 calculation
|
||||
void rewind()
|
||||
{
|
||||
sha1().clear();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
@ -31,11 +31,7 @@ License
|
||||
|
||||
// * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
defineTypeNameAndDebug(Time, 0);
|
||||
}
|
||||
|
||||
defineTypeNameAndDebug(Foam::Time, 0);
|
||||
|
||||
template<>
|
||||
const char* Foam::NamedEnum<Foam::Time::stopAtControls, 4>::names[] =
|
||||
@ -100,9 +96,11 @@ void Foam::Time::adjustDeltaT()
|
||||
void Foam::Time::setControls()
|
||||
{
|
||||
// default is to resume calculation from "latestTime"
|
||||
word startFrom("latestTime");
|
||||
|
||||
controlDict_.readIfPresent("startFrom", startFrom);
|
||||
word startFrom = controlDict_.lookupOrDefault<word>
|
||||
(
|
||||
"startFrom",
|
||||
"latestTime"
|
||||
);
|
||||
|
||||
if (startFrom == "startTime")
|
||||
{
|
||||
@ -421,7 +419,7 @@ Foam::instant Foam::Time::findClosestTime(const scalar t) const
|
||||
label nearestIndex = -1;
|
||||
scalar deltaT = GREAT;
|
||||
|
||||
for (label i=1; i<times.size(); i++)
|
||||
for (label i=1; i < times.size(); i++)
|
||||
{
|
||||
scalar diff = mag(times[i].value() - t);
|
||||
if (diff < deltaT)
|
||||
|
||||
@ -283,7 +283,7 @@ public:
|
||||
|
||||
//- Return the location of "dir" containing the file "name".
|
||||
// (Used in reading mesh data)
|
||||
// If name is null search for a directory "dir"
|
||||
// If name is null search for the directory "dir" only
|
||||
word findInstance
|
||||
(
|
||||
const fileName& dir,
|
||||
|
||||
@ -42,78 +42,74 @@ Foam::word Foam::Time::findInstance
|
||||
const IOobject::readOption rOpt
|
||||
) const
|
||||
{
|
||||
// Is the mesh data in the current time directory ?
|
||||
// Note: if name is empty, just check the directory itself
|
||||
|
||||
// check the current time directory
|
||||
if
|
||||
(
|
||||
(name.empty() && Foam::dir(path()/timeName()/dir))
|
||||
||
|
||||
name.empty()
|
||||
? isDir(path()/timeName()/dir)
|
||||
:
|
||||
(
|
||||
!name.empty()
|
||||
&& file(path()/timeName()/dir/name)
|
||||
isFile(path()/timeName()/dir/name)
|
||||
&& IOobject(name, timeName(), dir, *this).headerOk()
|
||||
)
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Time::findInstance(const word&, const word&) : "
|
||||
<< "found " << name
|
||||
<< " in " << timeName()/dir
|
||||
Info<< "Time::findInstance(const fileName&, const word&) : "
|
||||
<< "found \"" << name
|
||||
<< "\" in " << timeName()/dir
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return timeName();
|
||||
}
|
||||
|
||||
// Search back through the time directories list to find the time
|
||||
// Search back through the time directories to find the time
|
||||
// closest to and lower than current time
|
||||
|
||||
instantList ts = times();
|
||||
label i;
|
||||
label instanceI;
|
||||
|
||||
for (i=ts.size()-1; i>=0; i--)
|
||||
for (instanceI = ts.size()-1; instanceI >= 0; --instanceI)
|
||||
{
|
||||
if (ts[i].value() <= timeOutputValue())
|
||||
if (ts[instanceI].value() <= timeOutputValue())
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Noting that the current directory has already been searched
|
||||
// for mesh data, start searching from the previously stored time directory
|
||||
|
||||
if (i>=0)
|
||||
// continue searching from here
|
||||
for (; instanceI >= 0; --instanceI)
|
||||
{
|
||||
for (label j=i; j>=0; j--)
|
||||
{
|
||||
if
|
||||
if
|
||||
(
|
||||
name.empty()
|
||||
? isDir(path()/ts[instanceI].name()/dir)
|
||||
:
|
||||
(
|
||||
(name.empty() && Foam::dir(path()/ts[j].name()/dir))
|
||||
||
|
||||
(
|
||||
!name.empty()
|
||||
&& file(path()/ts[j].name()/dir/name)
|
||||
&& IOobject(name, ts[j].name(), dir, *this).headerOk()
|
||||
)
|
||||
isFile(path()/ts[instanceI].name()/dir/name)
|
||||
&& IOobject(name, ts[instanceI].name(), dir, *this).headerOk()
|
||||
)
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Time::findInstance(const word&, "
|
||||
<< "const word&) : "
|
||||
<< "found " << name
|
||||
<< " in " << ts[j].name()/dir
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return ts[j].name();
|
||||
Info<< "Time::findInstance"
|
||||
"(const fileName&,const word&) : "
|
||||
<< "found \"" << name
|
||||
<< "\" in " << ts[instanceI].name()/dir
|
||||
<< endl;
|
||||
}
|
||||
|
||||
return ts[instanceI].name();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// If the mesh data is not in any of the time directories
|
||||
// Try in constant
|
||||
// not in any of the time directories, try constant
|
||||
|
||||
// Note. This needs to be a hard-coded constant, rather than the
|
||||
// constant function of the time, because the latter points to
|
||||
@ -121,20 +117,21 @@ Foam::word Foam::Time::findInstance
|
||||
|
||||
if
|
||||
(
|
||||
(name.empty() && Foam::dir(path()/constant()/dir))
|
||||
|| (
|
||||
!name.empty()
|
||||
&& file(path()/constant()/dir/name)
|
||||
name.empty()
|
||||
? isDir(path()/constant()/dir)
|
||||
:
|
||||
(
|
||||
isFile(path()/constant()/dir/name)
|
||||
&& IOobject(name, constant(), dir, *this).headerOk()
|
||||
)
|
||||
)
|
||||
{
|
||||
if (debug)
|
||||
{
|
||||
Info<< "Time::findInstance(const word&, "
|
||||
<< "const word&) : "
|
||||
<< "found " << name
|
||||
<< " in " << constant()/dir
|
||||
Info<< "Time::findInstance"
|
||||
"(const fileName&,const word&) : "
|
||||
<< "found \"" << name
|
||||
<< "\" in " << constant()/dir
|
||||
<< endl;
|
||||
}
|
||||
|
||||
@ -143,7 +140,10 @@ Foam::word Foam::Time::findInstance
|
||||
|
||||
if (rOpt == IOobject::MUST_READ)
|
||||
{
|
||||
FatalErrorIn("Time::findInstance(const word&, const word&)")
|
||||
FatalErrorIn
|
||||
(
|
||||
"Time::findInstance(const fileName&,const word&)"
|
||||
)
|
||||
<< "Cannot find file \"" << name << "\" in directory "
|
||||
<< constant()/dir
|
||||
<< exit(FatalError);
|
||||
|
||||
@ -103,7 +103,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
const List<instant>& Times
|
||||
) const
|
||||
{
|
||||
return subset(selected(Times), true, Times);
|
||||
return subset(selected(Times), Times);
|
||||
}
|
||||
|
||||
|
||||
@ -112,7 +112,7 @@ void Foam::timeSelector::inplaceSelect
|
||||
List<instant>& Times
|
||||
) const
|
||||
{
|
||||
inplaceSubset(selected(Times), true, Times);
|
||||
inplaceSubset(selected(Times), Times);
|
||||
}
|
||||
|
||||
|
||||
@ -219,7 +219,7 @@ Foam::List<Foam::instant> Foam::timeSelector::select
|
||||
}
|
||||
}
|
||||
|
||||
return subset(selectTimes, true, timeDirs);
|
||||
return subset(selectTimes, timeDirs);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@ -28,6 +28,7 @@ License
|
||||
#include "primitiveEntry.H"
|
||||
#include "dictionaryEntry.H"
|
||||
#include "regExp.H"
|
||||
#include "OSHA1stream.H"
|
||||
|
||||
/* * * * * * * * * * * * * * * Static Member Data * * * * * * * * * * * * * */
|
||||
|
||||
@ -232,6 +233,25 @@ Foam::label Foam::dictionary::endLineNumber() const
|
||||
}
|
||||
|
||||
|
||||
Foam::SHA1Digest Foam::dictionary::digest() const
|
||||
{
|
||||
OSHA1stream os;
|
||||
|
||||
// process entries
|
||||
for
|
||||
(
|
||||
IDLList<entry>::const_iterator iter = begin();
|
||||
iter != end();
|
||||
++iter
|
||||
)
|
||||
{
|
||||
os << *iter;
|
||||
}
|
||||
|
||||
return os.digest();
|
||||
}
|
||||
|
||||
|
||||
bool Foam::dictionary::found(const word& keyword, bool recursive) const
|
||||
{
|
||||
if (hashedEntries_.found(keyword))
|
||||
|
||||
@ -69,6 +69,8 @@ namespace Foam
|
||||
// Forward declaration of friend functions and operators
|
||||
class regExp;
|
||||
class dictionary;
|
||||
class SHA1Digest;
|
||||
|
||||
Istream& operator>>(Istream&, dictionary&);
|
||||
Ostream& operator<<(Ostream&, const dictionary&);
|
||||
|
||||
@ -210,6 +212,9 @@ public:
|
||||
//- Return line number of last token in dictionary
|
||||
label endLineNumber() const;
|
||||
|
||||
//- Return the SHA1 digest of the dictionary contents
|
||||
SHA1Digest digest() const;
|
||||
|
||||
|
||||
// Search and lookup
|
||||
|
||||
|
||||
@ -45,7 +45,7 @@ Foam::dictionaryEntry::dictionaryEntry
|
||||
is.fatalCheck
|
||||
(
|
||||
"dictionaryEntry::dictionaryEntry"
|
||||
"(const dictionary& parentDict, Istream& is)"
|
||||
"(const dictionary& parentDict, Istream&)"
|
||||
);
|
||||
}
|
||||
|
||||
@ -65,7 +65,7 @@ Foam::dictionaryEntry::dictionaryEntry
|
||||
is.fatalCheck
|
||||
(
|
||||
"dictionaryEntry::dictionaryEntry"
|
||||
"(const keyType& keyword, const dictionary& parentDict, Istream& is)"
|
||||
"(const keyType&, const dictionary& parentDict, Istream&)"
|
||||
);
|
||||
}
|
||||
|
||||
@ -74,7 +74,9 @@ Foam::dictionaryEntry::dictionaryEntry
|
||||
|
||||
void Foam::dictionaryEntry::write(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword(keyword());
|
||||
// write keyword with indent but without trailing spaces
|
||||
os.indent();
|
||||
os.write(keyword());
|
||||
dictionary::write(os);
|
||||
}
|
||||
|
||||
|
||||
@ -29,14 +29,10 @@ License
|
||||
#include "Time.H"
|
||||
#include "PstreamReduceOps.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
Istream& regIOobject::readStream()
|
||||
Foam::Istream& Foam::regIOobject::readStream()
|
||||
{
|
||||
if (IFstream::debug)
|
||||
{
|
||||
@ -48,7 +44,7 @@ Istream& regIOobject::readStream()
|
||||
|
||||
if (readOpt() == NO_READ)
|
||||
{
|
||||
FatalErrorIn("regIOobject::readStream(const word&)")
|
||||
FatalErrorIn("regIOobject::readStream()")
|
||||
<< "NO_READ specified for read-constructor of object " << name()
|
||||
<< " of class " << headerClassName()
|
||||
<< abort(FatalError);
|
||||
@ -61,7 +57,7 @@ Istream& regIOobject::readStream()
|
||||
{
|
||||
FatalIOError
|
||||
(
|
||||
"regIOobject::readStream(const word&)",
|
||||
"regIOobject::readStream()",
|
||||
__FILE__,
|
||||
__LINE__,
|
||||
objectPath(),
|
||||
@ -71,7 +67,7 @@ Istream& regIOobject::readStream()
|
||||
}
|
||||
else if (!readHeader(*isPtr_))
|
||||
{
|
||||
FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
|
||||
FatalIOErrorIn("regIOobject::readStream()", *isPtr_)
|
||||
<< "problem while reading header for object " << name()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
@ -86,7 +82,7 @@ Istream& regIOobject::readStream()
|
||||
}
|
||||
|
||||
|
||||
Istream& regIOobject::readStream(const word& aType)
|
||||
Foam::Istream& Foam::regIOobject::readStream(const word& expectName)
|
||||
{
|
||||
if (IFstream::debug)
|
||||
{
|
||||
@ -106,14 +102,14 @@ Istream& regIOobject::readStream(const word& aType)
|
||||
// instantiated is a dictionary
|
||||
if
|
||||
(
|
||||
aType != word::null
|
||||
&& headerClassName() != aType
|
||||
expectName.size()
|
||||
&& headerClassName() != expectName
|
||||
&& headerClassName() != "dictionary"
|
||||
)
|
||||
{
|
||||
FatalIOErrorIn("regIOobject::readStream(const word&)", *isPtr_)
|
||||
<< "unexpected class name " << headerClassName()
|
||||
<< " expected " << aType << endl
|
||||
<< " expected " << expectName << endl
|
||||
<< " while reading object " << name()
|
||||
<< exit(FatalIOError);
|
||||
}
|
||||
@ -123,7 +119,7 @@ Istream& regIOobject::readStream(const word& aType)
|
||||
}
|
||||
|
||||
|
||||
void regIOobject::close()
|
||||
void Foam::regIOobject::close()
|
||||
{
|
||||
if (IFstream::debug)
|
||||
{
|
||||
@ -140,13 +136,13 @@ void regIOobject::close()
|
||||
}
|
||||
|
||||
|
||||
bool regIOobject::readData(Istream&)
|
||||
bool Foam::regIOobject::readData(Istream&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool regIOobject::read()
|
||||
bool Foam::regIOobject::read()
|
||||
{
|
||||
bool ok = readData(readStream(type()));
|
||||
close();
|
||||
@ -154,7 +150,7 @@ bool regIOobject::read()
|
||||
}
|
||||
|
||||
|
||||
bool regIOobject::modified() const
|
||||
bool Foam::regIOobject::modified() const
|
||||
{
|
||||
return
|
||||
(
|
||||
@ -164,7 +160,7 @@ bool regIOobject::modified() const
|
||||
}
|
||||
|
||||
|
||||
bool regIOobject::readIfModified()
|
||||
bool Foam::regIOobject::readIfModified()
|
||||
{
|
||||
if (lastModified_)
|
||||
{
|
||||
@ -213,8 +209,4 @@ bool regIOobject::readIfModified()
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -123,7 +123,7 @@ Foam::List<Foam::scalar> Foam::scalarRanges::select
|
||||
const List<scalar>& values
|
||||
) const
|
||||
{
|
||||
return subset(selected(values), true, values);
|
||||
return subset(selected(values), values);
|
||||
}
|
||||
|
||||
|
||||
@ -132,7 +132,7 @@ void Foam::scalarRanges::inplaceSelect
|
||||
List<scalar>& values
|
||||
) const
|
||||
{
|
||||
inplaceSubset(selected(values), true, values);
|
||||
inplaceSubset(selected(values), values);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -105,7 +105,7 @@ void pointPatchField<Type>::write(Ostream& os) const
|
||||
{
|
||||
os.writeKeyword("type") << type() << token::END_STATEMENT << nl;
|
||||
|
||||
if (patchType_ != word::null)
|
||||
if (patchType_.size())
|
||||
{
|
||||
os.writeKeyword("patchType") << patchType_
|
||||
<< token::END_STATEMENT << nl;
|
||||
|
||||
@ -65,14 +65,14 @@ Foam::JobInfo::JobInfo()
|
||||
<< Foam::exit(FatalError);
|
||||
}
|
||||
|
||||
if (!dir(runningDir) && !mkDir(runningDir))
|
||||
if (!isDir(runningDir) && !mkDir(runningDir))
|
||||
{
|
||||
FatalErrorIn("JobInfo::JobInfo()")
|
||||
<< "Cannot make JobInfo directory " << runningDir
|
||||
<< Foam::exit(FatalError);
|
||||
}
|
||||
|
||||
if (!dir(finishedDir) && !mkDir(finishedDir))
|
||||
if (!isDir(finishedDir) && !mkDir(finishedDir))
|
||||
{
|
||||
FatalErrorIn("JobInfo::JobInfo()")
|
||||
<< "Cannot make JobInfo directory " << finishedDir
|
||||
|
||||
@ -409,7 +409,7 @@ Foam::argList::argList
|
||||
label nProcDirs = 0;
|
||||
while
|
||||
(
|
||||
dir
|
||||
isDir
|
||||
(
|
||||
rootPath_/globalCase_/"processor"
|
||||
+ name(++nProcDirs)
|
||||
@ -624,7 +624,7 @@ void Foam::argList::displayDoc(bool source) const
|
||||
docFile = docDirs[dirI]/executable_ + docExts[extI];
|
||||
docFile.expand();
|
||||
|
||||
if (exists(docFile))
|
||||
if (isFile(docFile))
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
@ -697,7 +697,7 @@ bool Foam::argList::check(bool checkArgs, bool checkOpts) const
|
||||
|
||||
bool Foam::argList::checkRootCase() const
|
||||
{
|
||||
if (!dir(rootPath()))
|
||||
if (!isDir(rootPath()))
|
||||
{
|
||||
FatalError
|
||||
<< executable_
|
||||
@ -707,7 +707,7 @@ bool Foam::argList::checkRootCase() const
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!dir(path()) && Pstream::master())
|
||||
if (!isDir(path()) && Pstream::master())
|
||||
{
|
||||
// Allow slaves on non-existing processor directories, created later
|
||||
FatalError
|
||||
|
||||
@ -63,7 +63,7 @@ bool env(const word&);
|
||||
|
||||
//- Return environment variable of given name
|
||||
// Return string() if the environment is undefined
|
||||
string getEnv(const word& name);
|
||||
string getEnv(const word&);
|
||||
|
||||
//- Set an environment variable
|
||||
bool setEnv(const word& name, const string& value, const bool overwrite);
|
||||
@ -103,29 +103,30 @@ bool chDir(const fileName& dir);
|
||||
//
|
||||
// @return the full path name or fileName() if the name cannot be found
|
||||
// Optionally abort if the file cannot be found
|
||||
fileName findEtcFile(const fileName& name, bool mandatory=false);
|
||||
fileName findEtcFile(const fileName&, bool mandatory=false);
|
||||
|
||||
//- Make a directory and return an error if it could not be created
|
||||
// and does not already exist
|
||||
bool mkDir(const fileName&, mode_t=0777);
|
||||
|
||||
//- Set the file mode
|
||||
bool chmod(const fileName&, const mode_t);
|
||||
bool chMod(const fileName&, const mode_t);
|
||||
|
||||
//- Return the file mode
|
||||
mode_t mode(const fileName&);
|
||||
|
||||
//- Return the file type: FILE or DIRECTORY
|
||||
//- Return the file type: DIRECTORY or FILE
|
||||
fileName::Type type(const fileName&);
|
||||
|
||||
//- Does the name exist in the file system?
|
||||
bool exists(const fileName& name);
|
||||
//- Does the name exist (as DIRECTORY or FILE) in the file system?
|
||||
bool exists(const fileName&);
|
||||
|
||||
//- Does the file exist?
|
||||
bool file(const fileName&);
|
||||
//- Does the name exist as a DIRECTORY in the file system?
|
||||
bool isDir(const fileName&);
|
||||
|
||||
//- Does the directory exist?
|
||||
bool dir(const fileName&);
|
||||
//- Does the name exist as a FILE in the file system?
|
||||
// Optionally enable/disable check for gzip file.
|
||||
bool isFile(const fileName&, const bool checkGzip=true);
|
||||
|
||||
//- Return size of file
|
||||
off_t fileSize(const fileName&);
|
||||
@ -165,10 +166,10 @@ void fdClose(const int);
|
||||
//- Check if machine is up by pinging given port
|
||||
bool ping(const word&, const label port, const label timeOut);
|
||||
|
||||
//- Check if machine is up by ping port 22 = ssh and 222 = rsh
|
||||
//- Check if machine is up by pinging port 22 (ssh) and 222 (rsh)
|
||||
bool ping(const word&, const label timeOut=10);
|
||||
|
||||
//- Executes a command specified in command
|
||||
//- Execute the specified command
|
||||
int system(const string& command);
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
@ -44,7 +44,7 @@ void Foam::interpolationTable<Type>::readTable()
|
||||
// Check that the data are okay
|
||||
check();
|
||||
|
||||
if (this->size() == 0)
|
||||
if (this->empty())
|
||||
{
|
||||
FatalErrorIn
|
||||
(
|
||||
|
||||
@ -82,7 +82,7 @@ public:
|
||||
//- Return true if the reference count is zero
|
||||
bool okToDelete() const
|
||||
{
|
||||
return (count_ == 0);
|
||||
return !count_;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@ inline Foam::label Foam::face::right(const label i) const
|
||||
// Edge to the left of face vertex i
|
||||
inline Foam::label Foam::face::left(const label i) const
|
||||
{
|
||||
return i == 0 ? size() - 1 : (i - 1);
|
||||
return i ? i-1 : size()-1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@ Foam::patchIdentifier::patchIdentifier
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
boundaryIndex_(index),
|
||||
index_(index),
|
||||
physicalType_(physicalType)
|
||||
{}
|
||||
|
||||
@ -50,7 +50,7 @@ Foam::patchIdentifier::patchIdentifier
|
||||
)
|
||||
:
|
||||
name_(name),
|
||||
boundaryIndex_(index)
|
||||
index_(index)
|
||||
{
|
||||
dict.readIfPresent("physicalType", physicalType_);
|
||||
}
|
||||
@ -63,7 +63,7 @@ Foam::patchIdentifier::patchIdentifier
|
||||
)
|
||||
:
|
||||
name_(p.name_),
|
||||
boundaryIndex_(index),
|
||||
index_(index),
|
||||
physicalType_(p.physicalType_)
|
||||
{}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ class patchIdentifier
|
||||
word name_;
|
||||
|
||||
//- Index of patch in boundary
|
||||
label boundaryIndex_;
|
||||
label index_;
|
||||
|
||||
//- Optional physical type
|
||||
mutable word physicalType_;
|
||||
@ -86,14 +86,14 @@ public:
|
||||
patchIdentifier
|
||||
(
|
||||
const word& name,
|
||||
const dictionary& dict,
|
||||
const dictionary&,
|
||||
const label index
|
||||
);
|
||||
|
||||
//- Construct from geometric patch, resetting the index
|
||||
patchIdentifier
|
||||
(
|
||||
const patchIdentifier& p,
|
||||
const patchIdentifier&,
|
||||
const label index
|
||||
);
|
||||
|
||||
@ -132,13 +132,13 @@ public:
|
||||
//- Return the index of this patch in the boundaryMesh
|
||||
label index() const
|
||||
{
|
||||
return boundaryIndex_;
|
||||
return index_;
|
||||
}
|
||||
|
||||
//- Return the index of this patch in the boundaryMesh for modification
|
||||
label& index()
|
||||
{
|
||||
return boundaryIndex_;
|
||||
return index_;
|
||||
}
|
||||
|
||||
//- Write patchIdentifier as a dictionary
|
||||
|
||||
@ -25,35 +25,28 @@ License
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "globalPointPatch.H"
|
||||
#include "globalMeshData.H"
|
||||
#include "triFace.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
defineTypeNameAndDebug(globalPointPatch, 0);
|
||||
defineTypeNameAndDebug(Foam::globalPointPatch, 0);
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
globalPointPatch::globalPointPatch
|
||||
Foam::globalPointPatch::globalPointPatch
|
||||
(
|
||||
const pointBoundaryMesh& bm,
|
||||
const label bi
|
||||
const label index
|
||||
)
|
||||
:
|
||||
pointPatch(bm),
|
||||
coupledPointPatch(bm),
|
||||
boundaryIndex_(bi)
|
||||
index_(index)
|
||||
{}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
globalPointPatch::~globalPointPatch()
|
||||
Foam::globalPointPatch::~globalPointPatch()
|
||||
{}
|
||||
|
||||
|
||||
@ -62,6 +55,4 @@ globalPointPatch::~globalPointPatch()
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// ************************************************************************* //
|
||||
|
||||
@ -47,7 +47,7 @@ namespace Foam
|
||||
{
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class globalPointPatch Declaration
|
||||
Class globalPointPatch Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class globalPointPatch
|
||||
@ -57,11 +57,11 @@ class globalPointPatch
|
||||
{
|
||||
// Private data
|
||||
|
||||
////- Reference to the basic globalMeshData
|
||||
//const globalMeshData& globalMeshData_;
|
||||
// //- Reference to the basic globalMeshData
|
||||
// const globalMeshData& globalMeshData_;
|
||||
|
||||
//- Index in the boundary mesh
|
||||
label boundaryIndex_;
|
||||
label index_;
|
||||
|
||||
|
||||
// Protected Member Functions
|
||||
@ -113,7 +113,7 @@ public:
|
||||
//- Construct from components
|
||||
globalPointPatch
|
||||
(
|
||||
const pointBoundaryMesh& bm,
|
||||
const pointBoundaryMesh&,
|
||||
const label index
|
||||
);
|
||||
|
||||
@ -129,7 +129,7 @@ public:
|
||||
virtual const word& name() const
|
||||
{
|
||||
// There can only be a single patch of this type - therefore
|
||||
// its name is hard-coded.
|
||||
// its name is hard-coded.
|
||||
return type();
|
||||
}
|
||||
|
||||
@ -161,7 +161,7 @@ public:
|
||||
//- Return the index of this patch in the pointBoundaryMesh
|
||||
virtual label index() const
|
||||
{
|
||||
return boundaryIndex_;
|
||||
return index_;
|
||||
}
|
||||
|
||||
//- Return mesh points
|
||||
|
||||
@ -1103,7 +1103,7 @@ void Foam::polyMesh::removeFiles(const fileName& instanceDir) const
|
||||
rm(meshFilesPath/"parallelData");
|
||||
|
||||
// remove subdirectories
|
||||
if (dir(meshFilesPath/"sets"))
|
||||
if (isDir(meshFilesPath/"sets"))
|
||||
{
|
||||
rmDir(meshFilesPath/"sets");
|
||||
}
|
||||
|
||||
@ -867,7 +867,7 @@ bool primitiveMesh::checkFaceAngles
|
||||
forAll(f, fp0)
|
||||
{
|
||||
// Get vertex after fp
|
||||
label fp1 = (fp0 + 1) % f.size();
|
||||
label fp1 = f.fcIndex(fp0);
|
||||
|
||||
// Normalized vector between two consecutive points
|
||||
vector e10(p[f[fp1]] - p[f[fp0]]);
|
||||
@ -1636,12 +1636,12 @@ bool primitiveMesh::checkCommonOrder
|
||||
|
||||
|
||||
// Vertices before and after on curFace
|
||||
label fpPlus1 = (fp+1) % curFace.size();
|
||||
label fpMin1 = (fp == 0 ? curFace.size()-1 : fp-1);
|
||||
label fpPlus1 = curFace.fcIndex(fp);
|
||||
label fpMin1 = curFace.rcIndex(fp);
|
||||
|
||||
// Vertices before and after on nbFace
|
||||
label nbPlus1 = (nb+1) % nbFace.size();
|
||||
label nbMin1 = (nb == 0 ? nbFace.size()-1 : nb-1);
|
||||
label nbPlus1 = nbFace.fcIndex(nb);
|
||||
label nbMin1 = nbFace.rcIndex(nb);
|
||||
|
||||
// Find order of walking by comparing next points on both
|
||||
// faces.
|
||||
|
||||
@ -155,20 +155,10 @@ void Foam::walkPatch::faceToFace
|
||||
|
||||
indexInFace_.append(fp);
|
||||
|
||||
|
||||
// Visit neighbouring faces in order, starting at fp.
|
||||
for (label i = 0; i < f.size(); i++)
|
||||
{
|
||||
label fp1;
|
||||
if (reverse_)
|
||||
{
|
||||
fp1 = (fp == 0 ? f.size()-1 : fp-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
fp1 = (fp + 1) % f.size();
|
||||
}
|
||||
|
||||
label fp1 = reverse_ ? f.rcIndex(fp) : f.fcIndex(fp);
|
||||
label nbr = getNeighbour(faceI, fp, f[fp], f[fp1]);
|
||||
|
||||
if
|
||||
|
||||
455
src/OpenFOAM/primitives/hashes/SHA1/SHA1.C
Normal file
455
src/OpenFOAM/primitives/hashes/SHA1/SHA1.C
Normal file
@ -0,0 +1,455 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Description
|
||||
Functions to compute SHA1 message digest of files or memory blocks
|
||||
according to the NIST specification FIPS-180-1.
|
||||
|
||||
Adapted from the gnulib implementation written by Scott G. Miller with
|
||||
credits to Robert Klep <robert@ilse.nl> -- Expansion function fix
|
||||
|
||||
Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2008 Free Software
|
||||
Foundation, Inc.
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SHA1.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#if defined (__GLIBC__)
|
||||
# include <endian.h>
|
||||
#endif
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
//! @cond fileScope
|
||||
// The bytes used to pad buffer to the next 64-byte boundary.
|
||||
// (RFC 1321, 3.1: Step 1)
|
||||
static const unsigned char fillbuf[64] = { 0x80, 0 /* , 0, 0, ... */ };
|
||||
//! @endcond fileScope
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
|
||||
|
||||
inline uint32_t Foam::SHA1::swapBytes(uint32_t n)
|
||||
{
|
||||
#ifdef __BYTE_ORDER
|
||||
# if (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
return n;
|
||||
# else
|
||||
return (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24));
|
||||
# endif
|
||||
|
||||
#else
|
||||
|
||||
const short x = 0x0100;
|
||||
|
||||
// yields 0x01 for big endian
|
||||
if (*(reinterpret_cast<const char *>(&x)))
|
||||
{
|
||||
return n;
|
||||
}
|
||||
else
|
||||
{
|
||||
return (((n) << 24) | (((n) & 0xff00) << 8) | (((n) >> 8) & 0xff00) | ((n) >> 24));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
Foam::SHA1::set_uint32(unsigned char *cp, uint32_t v)
|
||||
{
|
||||
memcpy(cp, &v, sizeof(uint32_t));
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
|
||||
|
||||
|
||||
void Foam::SHA1::processBytes(const void *data, size_t len)
|
||||
{
|
||||
// already finalized, thus need to restart from nothing
|
||||
if (finalized_)
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
// complete filling of internal buffer
|
||||
if (bufLen_)
|
||||
{
|
||||
size_t remaining = bufLen_;
|
||||
size_t add =
|
||||
(
|
||||
sizeof(buffer_) - remaining > len
|
||||
? len
|
||||
: sizeof(buffer_) - remaining
|
||||
);
|
||||
|
||||
unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_);
|
||||
|
||||
memcpy(&bufp[remaining], data, add);
|
||||
bufLen_ += add;
|
||||
|
||||
if (bufLen_ > 64)
|
||||
{
|
||||
processBlock(buffer_, bufLen_ & ~63);
|
||||
|
||||
bufLen_ &= 63;
|
||||
// The regions in the following copy operation do not (cannot) overlap
|
||||
memcpy(buffer_, &bufp[(remaining + add) & ~63], bufLen_);
|
||||
}
|
||||
|
||||
data = reinterpret_cast<const unsigned char*>(data) + add;
|
||||
len -= add;
|
||||
}
|
||||
|
||||
// Process available complete blocks
|
||||
if (len >= 64)
|
||||
{
|
||||
#if !_STRING_ARCH_unaligned
|
||||
# define alignof(type) offsetof (struct { char c; type x; }, x)
|
||||
# define UNALIGNED_P(p) (((size_t) p) % alignof (uint32_t) != 0)
|
||||
if (UNALIGNED_P (data))
|
||||
{
|
||||
while (len > 64)
|
||||
{
|
||||
processBlock(memcpy (buffer_, data, 64), 64);
|
||||
data = reinterpret_cast<const unsigned char*>(data) + 64;
|
||||
len -= 64;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
processBlock(data, len & ~63);
|
||||
data = reinterpret_cast<const unsigned char*>(data) + (len & ~63);
|
||||
len &= 63;
|
||||
}
|
||||
}
|
||||
|
||||
// Move remaining bytes in internal buffer.
|
||||
if (len > 0)
|
||||
{
|
||||
unsigned char* bufp = reinterpret_cast<unsigned char*>(buffer_);
|
||||
size_t remaining = bufLen_;
|
||||
|
||||
memcpy (&bufp[remaining], data, len);
|
||||
remaining += len;
|
||||
if (remaining >= 64)
|
||||
{
|
||||
processBlock(buffer_, 64);
|
||||
remaining -= 64;
|
||||
memcpy (buffer_, &buffer_[16], remaining);
|
||||
}
|
||||
bufLen_ = remaining;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// SHA1 round constants
|
||||
#define K1 0x5a827999
|
||||
#define K2 0x6ed9eba1
|
||||
#define K3 0x8f1bbcdc
|
||||
#define K4 0xca62c1d6
|
||||
|
||||
// Round functions. Note that F2 is the same as F4.
|
||||
#define F1(B,C,D) ( D ^ ( B & ( C ^ D ) ) )
|
||||
#define F2(B,C,D) (B ^ C ^ D)
|
||||
#define F3(B,C,D) ( ( B & C ) | ( D & ( B | C ) ) )
|
||||
#define F4(B,C,D) (B ^ C ^ D)
|
||||
|
||||
// Process LEN bytes of BUFFER, it is assumed that LEN % 64 == 0.
|
||||
// Most of this code comes from GnuPG's cipher/sha1.c
|
||||
|
||||
void
|
||||
Foam::SHA1::processBlock(const void *data, size_t len)
|
||||
{
|
||||
const uint32_t *words = reinterpret_cast<const uint32_t*>(data);
|
||||
size_t nwords = len / sizeof(uint32_t);
|
||||
const uint32_t *endp = words + nwords;
|
||||
|
||||
// calculate with sixteen words of 32-bits
|
||||
uint32_t x[16];
|
||||
uint32_t a = hashsumA_;
|
||||
uint32_t b = hashsumB_;
|
||||
uint32_t c = hashsumC_;
|
||||
uint32_t d = hashsumD_;
|
||||
uint32_t e = hashsumE_;
|
||||
|
||||
// First increment the byte count.
|
||||
// RFC 1321 specifies the possible length of the file up to 2^64 bits.
|
||||
// Here we only compute the number of bytes. Do a double word increment.
|
||||
bufTotal_[0] += len;
|
||||
if (bufTotal_[0] < len)
|
||||
{
|
||||
++bufTotal_[1];
|
||||
}
|
||||
|
||||
// rotate left uint32_t by n bits
|
||||
#define rol_uint32(x, nbits) (((x) << (nbits)) | ((x) >> (32 - (nbits))))
|
||||
|
||||
#define M(I) ( tm = x[I & 0x0F] ^ x[(I-14) & 0x0F] \
|
||||
^ x[(I-8) & 0x0F] ^ x[(I-3) & 0x0F] \
|
||||
, (x[I & 0x0F] = rol_uint32(tm, 1)) )
|
||||
|
||||
|
||||
#define R(A,B,C,D,E,F,K,M) \
|
||||
do \
|
||||
{ \
|
||||
E += rol_uint32(A, 5) + F(B, C, D) + K + M; \
|
||||
B = rol_uint32(B, 30); \
|
||||
} while(0)
|
||||
|
||||
while (words < endp)
|
||||
{
|
||||
uint32_t tm;
|
||||
for (int t = 0; t < 16; t++)
|
||||
{
|
||||
x[t] = swapBytes (*words);
|
||||
words++;
|
||||
}
|
||||
|
||||
R( a, b, c, d, e, F1, K1, x[ 0] );
|
||||
R( e, a, b, c, d, F1, K1, x[ 1] );
|
||||
R( d, e, a, b, c, F1, K1, x[ 2] );
|
||||
R( c, d, e, a, b, F1, K1, x[ 3] );
|
||||
R( b, c, d, e, a, F1, K1, x[ 4] );
|
||||
R( a, b, c, d, e, F1, K1, x[ 5] );
|
||||
R( e, a, b, c, d, F1, K1, x[ 6] );
|
||||
R( d, e, a, b, c, F1, K1, x[ 7] );
|
||||
R( c, d, e, a, b, F1, K1, x[ 8] );
|
||||
R( b, c, d, e, a, F1, K1, x[ 9] );
|
||||
R( a, b, c, d, e, F1, K1, x[10] );
|
||||
R( e, a, b, c, d, F1, K1, x[11] );
|
||||
R( d, e, a, b, c, F1, K1, x[12] );
|
||||
R( c, d, e, a, b, F1, K1, x[13] );
|
||||
R( b, c, d, e, a, F1, K1, x[14] );
|
||||
R( a, b, c, d, e, F1, K1, x[15] );
|
||||
R( e, a, b, c, d, F1, K1, M(16) );
|
||||
R( d, e, a, b, c, F1, K1, M(17) );
|
||||
R( c, d, e, a, b, F1, K1, M(18) );
|
||||
R( b, c, d, e, a, F1, K1, M(19) );
|
||||
R( a, b, c, d, e, F2, K2, M(20) );
|
||||
R( e, a, b, c, d, F2, K2, M(21) );
|
||||
R( d, e, a, b, c, F2, K2, M(22) );
|
||||
R( c, d, e, a, b, F2, K2, M(23) );
|
||||
R( b, c, d, e, a, F2, K2, M(24) );
|
||||
R( a, b, c, d, e, F2, K2, M(25) );
|
||||
R( e, a, b, c, d, F2, K2, M(26) );
|
||||
R( d, e, a, b, c, F2, K2, M(27) );
|
||||
R( c, d, e, a, b, F2, K2, M(28) );
|
||||
R( b, c, d, e, a, F2, K2, M(29) );
|
||||
R( a, b, c, d, e, F2, K2, M(30) );
|
||||
R( e, a, b, c, d, F2, K2, M(31) );
|
||||
R( d, e, a, b, c, F2, K2, M(32) );
|
||||
R( c, d, e, a, b, F2, K2, M(33) );
|
||||
R( b, c, d, e, a, F2, K2, M(34) );
|
||||
R( a, b, c, d, e, F2, K2, M(35) );
|
||||
R( e, a, b, c, d, F2, K2, M(36) );
|
||||
R( d, e, a, b, c, F2, K2, M(37) );
|
||||
R( c, d, e, a, b, F2, K2, M(38) );
|
||||
R( b, c, d, e, a, F2, K2, M(39) );
|
||||
R( a, b, c, d, e, F3, K3, M(40) );
|
||||
R( e, a, b, c, d, F3, K3, M(41) );
|
||||
R( d, e, a, b, c, F3, K3, M(42) );
|
||||
R( c, d, e, a, b, F3, K3, M(43) );
|
||||
R( b, c, d, e, a, F3, K3, M(44) );
|
||||
R( a, b, c, d, e, F3, K3, M(45) );
|
||||
R( e, a, b, c, d, F3, K3, M(46) );
|
||||
R( d, e, a, b, c, F3, K3, M(47) );
|
||||
R( c, d, e, a, b, F3, K3, M(48) );
|
||||
R( b, c, d, e, a, F3, K3, M(49) );
|
||||
R( a, b, c, d, e, F3, K3, M(50) );
|
||||
R( e, a, b, c, d, F3, K3, M(51) );
|
||||
R( d, e, a, b, c, F3, K3, M(52) );
|
||||
R( c, d, e, a, b, F3, K3, M(53) );
|
||||
R( b, c, d, e, a, F3, K3, M(54) );
|
||||
R( a, b, c, d, e, F3, K3, M(55) );
|
||||
R( e, a, b, c, d, F3, K3, M(56) );
|
||||
R( d, e, a, b, c, F3, K3, M(57) );
|
||||
R( c, d, e, a, b, F3, K3, M(58) );
|
||||
R( b, c, d, e, a, F3, K3, M(59) );
|
||||
R( a, b, c, d, e, F4, K4, M(60) );
|
||||
R( e, a, b, c, d, F4, K4, M(61) );
|
||||
R( d, e, a, b, c, F4, K4, M(62) );
|
||||
R( c, d, e, a, b, F4, K4, M(63) );
|
||||
R( b, c, d, e, a, F4, K4, M(64) );
|
||||
R( a, b, c, d, e, F4, K4, M(65) );
|
||||
R( e, a, b, c, d, F4, K4, M(66) );
|
||||
R( d, e, a, b, c, F4, K4, M(67) );
|
||||
R( c, d, e, a, b, F4, K4, M(68) );
|
||||
R( b, c, d, e, a, F4, K4, M(69) );
|
||||
R( a, b, c, d, e, F4, K4, M(70) );
|
||||
R( e, a, b, c, d, F4, K4, M(71) );
|
||||
R( d, e, a, b, c, F4, K4, M(72) );
|
||||
R( c, d, e, a, b, F4, K4, M(73) );
|
||||
R( b, c, d, e, a, F4, K4, M(74) );
|
||||
R( a, b, c, d, e, F4, K4, M(75) );
|
||||
R( e, a, b, c, d, F4, K4, M(76) );
|
||||
R( d, e, a, b, c, F4, K4, M(77) );
|
||||
R( c, d, e, a, b, F4, K4, M(78) );
|
||||
R( b, c, d, e, a, F4, K4, M(79) );
|
||||
|
||||
a = hashsumA_ += a;
|
||||
b = hashsumB_ += b;
|
||||
c = hashsumC_ += c;
|
||||
d = hashsumD_ += d;
|
||||
e = hashsumE_ += e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Foam::SHA1::calcDigest(SHA1Digest& dig) const
|
||||
{
|
||||
if (bufTotal_[0] || bufTotal_[1])
|
||||
{
|
||||
unsigned char *r = dig.v_;
|
||||
|
||||
set_uint32 (r + 0 * sizeof(uint32_t), swapBytes(hashsumA_));
|
||||
set_uint32 (r + 1 * sizeof(uint32_t), swapBytes(hashsumB_));
|
||||
set_uint32 (r + 2 * sizeof(uint32_t), swapBytes(hashsumC_));
|
||||
set_uint32 (r + 3 * sizeof(uint32_t), swapBytes(hashsumD_));
|
||||
set_uint32 (r + 4 * sizeof(uint32_t), swapBytes(hashsumE_));
|
||||
}
|
||||
else
|
||||
{
|
||||
// no data!
|
||||
dig.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * Selectors * * * * * * * * * * * * * * * * //
|
||||
|
||||
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
void Foam::SHA1::clear()
|
||||
{
|
||||
hashsumA_ = 0x67452301;
|
||||
hashsumB_ = 0xefcdab89;
|
||||
hashsumC_ = 0x98badcfe;
|
||||
hashsumD_ = 0x10325476;
|
||||
hashsumE_ = 0xc3d2e1f0;
|
||||
|
||||
bufTotal_[0] = bufTotal_[1] = 0;
|
||||
bufLen_ = 0;
|
||||
|
||||
finalized_ = false;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::SHA1::finalize()
|
||||
{
|
||||
if (!finalized_)
|
||||
{
|
||||
finalized_ = true;
|
||||
|
||||
// account for unprocessed bytes
|
||||
uint32_t bytes = bufLen_;
|
||||
size_t size = (bytes < 56 ? 64 : 128) / sizeof(uint32_t);
|
||||
|
||||
// count remaining bytes.
|
||||
bufTotal_[0] += bytes;
|
||||
if (bufTotal_[0] < bytes)
|
||||
{
|
||||
++bufTotal_[1];
|
||||
}
|
||||
|
||||
// finalized, but no data!
|
||||
if (!bufTotal_[0] && !bufTotal_[1])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// place the 64-bit file length in *bits* at the end of the buffer.
|
||||
buffer_[size-2] = swapBytes((bufTotal_[1] << 3) | (bufTotal_[0] >> 29));
|
||||
buffer_[size-1] = swapBytes(bufTotal_[0] << 3);
|
||||
|
||||
unsigned char* bufp = reinterpret_cast<unsigned char *>(buffer_);
|
||||
|
||||
memcpy(&bufp[bytes], fillbuf, (size-2) * sizeof(uint32_t) - bytes);
|
||||
|
||||
// Process remaining bytes
|
||||
processBlock(buffer_, size * sizeof(uint32_t));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Foam::SHA1Digest Foam::SHA1::digest() const
|
||||
{
|
||||
SHA1Digest dig;
|
||||
|
||||
if (finalized_)
|
||||
{
|
||||
calcDigest(dig);
|
||||
}
|
||||
else
|
||||
{
|
||||
// avoid disturbing our data - use a copy
|
||||
SHA1 sha(*this);
|
||||
if (sha.finalize())
|
||||
{
|
||||
sha.calcDigest(dig);
|
||||
}
|
||||
}
|
||||
|
||||
return dig;
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
// void Foam::SHA1::operator=(const SHA1& rhs)
|
||||
// {
|
||||
// // Check for assignment to self
|
||||
// if (this == &rhs)
|
||||
// {
|
||||
// FatalErrorIn("Foam::SHA1::operator=(const Foam::SHA1&)")
|
||||
// << "Attempted assignment to self"
|
||||
// << abort(FatalError);
|
||||
// }
|
||||
// }
|
||||
|
||||
// * * * * * * * * * * * * * * Friend Functions * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
185
src/OpenFOAM/primitives/hashes/SHA1/SHA1.H
Normal file
185
src/OpenFOAM/primitives/hashes/SHA1/SHA1.H
Normal file
@ -0,0 +1,185 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::SHA1
|
||||
|
||||
Description
|
||||
Functions to compute SHA1 message digest according to the NIST
|
||||
specification FIPS-180-1.
|
||||
|
||||
Adapted from the gnulib implementation.
|
||||
|
||||
SeeAlso
|
||||
Foam::SHA1Digest
|
||||
|
||||
SourceFiles
|
||||
SHA1I.H
|
||||
SHA1.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SHA1_H
|
||||
#define SHA1_H
|
||||
|
||||
#include <string>
|
||||
#include <cstddef>
|
||||
#include <stdint.h> // C++0x uses <cstdint>
|
||||
|
||||
#include "SHA1Digest.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class SHA1;
|
||||
class SHA1Digest;
|
||||
Ostream& operator<<(Ostream&, const SHA1&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class SHA1 Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class SHA1
|
||||
{
|
||||
// Private data
|
||||
|
||||
//- Track if the hashsum has been finalized (added count, etc)
|
||||
bool finalized_;
|
||||
|
||||
//- The hash sums
|
||||
uint32_t hashsumA_;
|
||||
uint32_t hashsumB_;
|
||||
uint32_t hashsumC_;
|
||||
uint32_t hashsumD_;
|
||||
uint32_t hashsumE_;
|
||||
|
||||
//- The total number processed, saved as 64-bit
|
||||
uint32_t bufTotal_[2];
|
||||
|
||||
//- The number of elements pending in the buffer
|
||||
uint32_t bufLen_;
|
||||
|
||||
//- The input processing buffer
|
||||
uint32_t buffer_[32];
|
||||
|
||||
// Private Member Functions
|
||||
|
||||
//- Swap bytes from internal to network (big-endian) order
|
||||
static inline uint32_t swapBytes(uint32_t);
|
||||
|
||||
//- Copy the 4-byte value into the memory location pointed to by *dst.
|
||||
// If the architecture allows unaligned access this is equivalent to
|
||||
// *(uint32_t *) cp = val
|
||||
static inline void set_uint32(unsigned char *cp, uint32_t);
|
||||
|
||||
//- Process data block-wise, LEN must be a multiple of 64!
|
||||
void processBlock(const void *data, size_t len);
|
||||
|
||||
//- Process for the next LEN bytes, LEN need not be a multiple of 64.
|
||||
void processBytes(const void *data, size_t len);
|
||||
|
||||
//- Calculate current digest from appended data.
|
||||
void calcDigest(SHA1Digest&) const;
|
||||
|
||||
public:
|
||||
|
||||
// Constructors
|
||||
|
||||
//- Construct null
|
||||
inline SHA1();
|
||||
|
||||
//- Construct and append initial std::string
|
||||
explicit inline SHA1(const std::string&);
|
||||
|
||||
//- Construct and append initial string
|
||||
explicit inline SHA1(const char*);
|
||||
|
||||
// Member Functions
|
||||
|
||||
//- Reset the hashed data before appending more
|
||||
void clear();
|
||||
|
||||
//- Append data for processing
|
||||
inline SHA1& append(const char* data, size_t len);
|
||||
|
||||
//- Append string for processing
|
||||
inline SHA1& append(const std::string&);
|
||||
|
||||
//- Append string for processing
|
||||
inline SHA1& append(const char* str);
|
||||
|
||||
//- Finalized the calculations (normally not needed directly).
|
||||
// Returns false if no bytes were passed for processing
|
||||
bool finalize();
|
||||
|
||||
//- Calculate current digest from appended data.
|
||||
SHA1Digest digest() const;
|
||||
|
||||
|
||||
// Member Operators
|
||||
|
||||
//- Equality operator
|
||||
inline bool operator==(const SHA1Digest&) const;
|
||||
|
||||
//- Inequality operator
|
||||
inline bool operator!=(const SHA1Digest&) const;
|
||||
|
||||
//- Equality operator
|
||||
inline bool operator==(const SHA1&) const;
|
||||
|
||||
//- Inequality operator
|
||||
inline bool operator!=(const SHA1&) const;
|
||||
|
||||
//- Convert to a digest, calculate current digest from appended data.
|
||||
inline operator SHA1Digest() const;
|
||||
|
||||
// Friend Functions
|
||||
|
||||
// Friend Operators
|
||||
|
||||
inline friend Ostream& operator<<(Ostream&, const SHA1&);
|
||||
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#include "SHA1I.H"
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
94
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C
Normal file
94
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.C
Normal file
@ -0,0 +1,94 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#include "SHA1Digest.H"
|
||||
#include "IOstreams.H"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
|
||||
|
||||
//! @cond fileScope
|
||||
const char hexChars[] = "0123456789abcdef";
|
||||
//! @endcond fileScope
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::SHA1Digest::SHA1Digest()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
|
||||
|
||||
void Foam::SHA1Digest::clear()
|
||||
{
|
||||
memset(v_, 0, length);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
|
||||
|
||||
bool Foam::SHA1Digest::operator==(const SHA1Digest& rhs) const
|
||||
{
|
||||
for (unsigned i = 0; i < length; ++i)
|
||||
{
|
||||
if (v_[i] != rhs.v_[i])
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool Foam::SHA1Digest::operator!=(const SHA1Digest& rhs) const
|
||||
{
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * * //
|
||||
|
||||
Foam::Ostream& Foam::operator<<(Ostream& os, const SHA1Digest& dig)
|
||||
{
|
||||
const unsigned char *v = dig.v_;
|
||||
|
||||
for (unsigned i = 0; i < dig.length; ++i)
|
||||
{
|
||||
os.write(hexChars[((v[i] >> 4) & 0xF)]);
|
||||
os.write(hexChars[(v[i] & 0xF)]);
|
||||
}
|
||||
|
||||
os.check("Ostream& operator<<(Ostream&, const SHA1Digest&)");
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
// ************************************************************************* //
|
||||
97
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
Normal file
97
src/OpenFOAM/primitives/hashes/SHA1/SHA1Digest.H
Normal file
@ -0,0 +1,97 @@
|
||||
/*---------------------------------------------------------------------------*\
|
||||
========= |
|
||||
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
|
||||
\\ / O peration |
|
||||
\\ / A nd | Copyright (C) 1991-2009 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 2 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, write to the Free Software Foundation,
|
||||
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
Class
|
||||
Foam::SHA1Digest
|
||||
|
||||
Description
|
||||
The SHA1 message digest.
|
||||
|
||||
SeeAlso
|
||||
Foam::SHA1
|
||||
|
||||
SourceFiles
|
||||
SHA1Digest.C
|
||||
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
#ifndef SHA1Digest_H
|
||||
#define SHA1Digest_H
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
namespace Foam
|
||||
{
|
||||
|
||||
// Forward declaration of classes
|
||||
class Ostream;
|
||||
|
||||
// Forward declaration of friend functions and operators
|
||||
class SHA1;
|
||||
class SHA1Digest;
|
||||
Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||
|
||||
|
||||
/*---------------------------------------------------------------------------*\
|
||||
Class SHA1Digest Declaration
|
||||
\*---------------------------------------------------------------------------*/
|
||||
|
||||
class SHA1Digest
|
||||
{
|
||||
public:
|
||||
friend class SHA1;
|
||||
|
||||
//- The length of the digest contents
|
||||
static const unsigned length = 20;
|
||||
|
||||
//- Construct a zero digest
|
||||
SHA1Digest();
|
||||
|
||||
//- Reset the digest to zero
|
||||
void clear();
|
||||
|
||||
//- Equality operator
|
||||
bool operator==(const SHA1Digest&) const;
|
||||
|
||||
//- Inequality operator
|
||||
bool operator!=(const SHA1Digest&) const;
|
||||
|
||||
friend Ostream& operator<<(Ostream&, const SHA1Digest&);
|
||||
|
||||
private:
|
||||
|
||||
//- The digest contents
|
||||
unsigned char v_[length];
|
||||
};
|
||||
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
} // End namespace Foam
|
||||
|
||||
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
|
||||
|
||||
#endif
|
||||
|
||||
// ************************************************************************* //
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user