Merge update

This commit is contained in:
Hrvoje Jasak 2010-08-24 16:19:39 +01:00
parent 288efa21ab
commit 54c7d7fb19
2072 changed files with 122654 additions and 35119 deletions

View file

@ -1,8 +1,11 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
chmod a+rX $WM_PROJECT_DIR
chmod a+rX $WM_PROJECT_DIR/doc
chmod -R a+rX Doxygen
( cd Doxygen && ./Allwmake )
Doxygen/Allwmake
# ----------------------------------------------------------------- end-of-file

View file

@ -1,9 +1,12 @@
#!/bin/sh
cd ${0%/*} || exit 1 # run from this directory
set -x
umask 22
rm -rf html latex man
doxygen
# fix permissions (NB: '-X' and not '-x'!)
# fix permissions (NB: '+X' and not '+x'!)
chmod -R a+rX ./
# ----------------------------------------------------------------- end-of-file

View file

@ -788,7 +788,7 @@ TREEVIEW_WIDTH = 250
# configuration options related to the LaTeX output
#---------------------------------------------------------------------------
# Path for OpenFOAM LaTeX macros
# Path for OpenCFD LaTeX macros
@INCLUDE_PATH = $(WM_PROJECT_DIR)/doc/Doxygen/Macros/

View file

@ -1,4 +1,4 @@
Copyright © 2000-2008 OpenFOAM Foundation
Copyright © 2000-2009 OpenCFD Ltd
</td></tr>
</table>
</body>

View file

@ -1,7 +1,7 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html >
<head>open
<head>
<title> OpenFOAM programmer's C++ documentation
</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
@ -12,8 +12,8 @@
<meta name="date" content="2007-04-12 00:02:00">
<link rel="stylesheet" type="text/css" href="../Doxygen.css">
<link rel="stylesheet" type="text/css" href="../tabs.css">
<meta name="keywords" content="computational fluid dynamics, CFD, OpenFOAM, open source CFD, open source">
<meta name="description" content="OpenFOAM, leading open source Computational Fluid Dynamics (CFD)">
<meta name="keywords" content="computational fluid dynamics, CFD, OpenCFD, OpenFOAM, open source CFD, open source">
<meta name="description" content="OpenCFD Ltd, leaders in open source Computational Fluid Dynamics (CFD), the developers and maintainers of OpenFOAM: the open source CFD toolbox. We supply support and contracted developments for OpenFOAM">
</head>
<body>
<a id="openfoam"> </a>
@ -40,6 +40,26 @@ horizontal-align: left; ">
<td valign=top>
<table width=801 border=0 cellspacing=1 cellpadding=0 bgcolor="#ffffff">
<tr>
<td class=leftmenu>&nbsp;
<a href="http://foam.sourceforge.net/doc/Doxygen/html"
class=menuLefton >Source Guide</a>
</td>
<td class=topmenu>
<a href="http://www.opencfd.co.uk/index.html"
class=menuTopoff >OpenCFD</a>
</td>
<td class=topmenu>
<a href="http://www.opencfd.co.uk/solutions/index.html"
class=menuTopoff >Solutions</a>
</td>
<td class=topmenu>
<a href="http://www.opencfd.co.uk/contact/index.html"
class=menuTopoff >Contact</a>
</td>
<td class=topmenu>
<a href="http://www.opencfd.co.uk/openfoam/index.html"
class=menuTopoff >OpenFOAM</a>
</td>
</tr>
<tr>
<td>

View file

@ -0,0 +1,129 @@
%-----------------------------------------------------------------------------
% ========= |
% \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
% \\ / O peration |
% \\ / A nd | Copyright held by original author
% \\/ 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
%
% LaTeX Style file
% tensorOperator.sty
%
% Description
% Standard OpenCFD LaTeX macros for typesetting tensor algebra.
%
%------------------------------------------------------------------------------
% tensor style
% ~~~~~~~~~~~~
\renewcommand{\vec}[1] {\ensuremath{\mathbf #1}}
\newcommand{\gvec}[1] {\ensuremath{\mbox{\boldmath$\bf#1$}}}
% products
% ~~~~~~~~
\newcommand{\anyprod}{\star}
\newcommand{\cprod} {\times}
\newcommand{\dprod} {\,{\scriptscriptstyle \stackrel{\bullet}{{}}}\,}
\newcommand{\ddprod} {\,{\scriptscriptstyle \stackrel{\bullet}{\bullet}}\,}
\newcommand{\tdprod} {\,{\scriptscriptstyle \stackrel{3}{\bullet}}\,}
\newcommand{\tprod} {\,{\scriptscriptstyle \stackrel{\otimes}{{}}}\,}
% operations
% ~~~~~~~~~~
\newcommand{\adj} {\ensuremath{\operatorname{adj}}}
\newcommand{\cof} {\ensuremath{\operatorname{cof}}}
\newcommand{\diag} {\ensuremath{\operatorname{diag}}}
\newcommand{\dev} {\ensuremath{\operatorname{dev}}}
\newcommand{\Hodge} {\ensuremath{\operatorname{\stackrel{\displaystyle \ast}{}}}}
\newcommand{\hyd} {\ensuremath{\operatorname{hyd}}}
\renewcommand{\max} {\ensuremath{\operatorname{max}}}
\renewcommand{\min} {\ensuremath{\operatorname{min}}}
\newcommand{\inv} {\ensuremath{\operatorname{inv}}}
\newcommand{\sym} {\ensuremath{\operatorname{symm}}} % symm ?
\newcommand{\skw} {\ensuremath{\operatorname{skew}}} % skew already defined
\newcommand{\tr} {\ensuremath{\operatorname{tr}}}
\newcommand{\trans}[1] {\ensuremath{#1^{\operatorname{T}}}}
% alternative tensor operators for hypersonics etc.
% ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\newcommand{\devs}[1] {\overset{\scriptscriptstyle\circ}{#1}}
%\newcommand{\trans}[1] {\ensuremath{#1^{\operatorname{T}}}}
\newcommand{\symms}[1] {\overleftrightarrow{#1}}
\newlength{\skewslength}
\newlength{\skewsheight}
\newcommand{\skews}[1]{
\settowidth{\skewslength}{#1}%
\settoheight{\skewsheight}{#1}%
\addtolength{\skewsheight}{0.4mm}%
{\overleftrightarrow{#1}\hspace{-.5\skewslength}%
\rule[\skewsheight]{.4pt}{1.4mm}
\hspace{.5\skewslength}%
}}
%\newcommand{\skew}[1] {\ensuremath{#1^{\operatorname{A}}}}
% spatial derivatives
% ~~~~~~~~~~~~~~~~~~~
\newcommand{\curl}{\ensuremath{\nabla\cprod}}
\renewcommand{\div} {\ensuremath{\nabla\dprod}}
\newcommand{\grad}{\ensuremath{\nabla}}
\newcommand{\laplacian}{\ensuremath{\nabla^{2}}}
% temporal derivatives
% ~~~~~~~~~~~~~~~~~~~~
\newcommand{\ddt}[1] {\ensuremath{\frac{\partial #1}{\partial t }}}
\newcommand{\DDt}[1] {\ensuremath{\frac{D #1}{D t}}}
\newcommand{\DpDt}[2] {\ensuremath{\frac{d_{#1} #2}{d t }}}
\newcommand{\dsdts}[1] {\ensuremath{\frac{\partial ^2 #1}{\partial t^2}}}
\newcommand{\rate}[1] {\ensuremath{\dot{#1}}}
\newcommand{\genDer}{\mathcal{L}}
% time average symbols
% ~~~~~~~~~~~~~~~~~~~~
\newcommand{\av}[1] {\ensuremath{\overline{#1}}}
\newcommand{\corrtwo}[2] {{\dwea{\dprime{#1} \dprime{#2}}}}
\newcommand{\curly}[1] {{\cal #1}}
\newcommand{\dprime}[1] {\ensuremath{{#1}^{^{\prime \prime}}}}
\newcommand{\dwea}[1] {\ensuremath{\widetilde{#1}}}
\newcommand{\dweafluc}[1] {\ensuremath{\dprime{#1}}}
\newcommand{\fluc}[1] {\ensuremath{#1^{\prime}}}
% index style
% ~~~~~~~~~~~
\newcommand{\veci}[2][i] {\ensuremath{#2_{#1}}}
\newcommand{\teni}[2][ij] {\ensuremath{#2_{#1}}}
\newcommand{\tenTi}[2][ji] {\ensuremath{#2_{#1}}}
% index operations
% ~~~~~~~~~~~~~~~~
\newcommand{\deltai}[1] {\ensuremath{\partial_{#1}}}
% Sub-subscripts
% ~~~~~~~~~~~~~~
\newcommand{\eff} {{\scriptscriptstyle e\!f\!\!f\!}}
% unknown use
% ~~~~~~~~~~~
%\font\bigtenrm=cmr12 scaled 1200
%\newcommand{\eexp}[1]{{\hbox{$\textfont1=\bigtenrm e$}}^{\raise3pt
%\hbox{$#1$}}}
% ------------------------------------------------------------------------------

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
ODE
Foam::ODE
Description
Abstract base class for the ODE solvers.
@ -34,7 +34,7 @@ Description
#define ODE_H
#include "scalarField.H"
#include "Matrix.H"
#include "scalarMatrices.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -87,7 +87,7 @@ public:
const scalar x,
const scalarField& y,
scalarField& dfdx,
Matrix<scalar>& dfdy
scalarSquareMatrix& dfdy
) const = 0;
//- Update ODE after the solution, advancing by delta

View file

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
KRR4
Foam::KRR4
Description
Fourth-order Kaps-Rentrop scheme with adjustive time-step size
@ -63,8 +63,8 @@ class KRR4
mutable scalarField g4_;
mutable scalarField yErr_;
mutable scalarField dfdx_;
mutable Matrix<scalar> dfdy_;
mutable Matrix<scalar> a_;
mutable scalarSquareMatrix dfdy_;
mutable scalarSquareMatrix a_;
mutable labelList pivotIndices_;
static const int maxtry = 40;

View file

@ -22,8 +22,6 @@ License
along with OpenFOAM; if not, write to the Free Software Foundation,
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
\*---------------------------------------------------------------------------*/
#include "ODESolver.H"

View file

@ -23,9 +23,10 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
ODESolver
Foam::ODESolver
Description
Selection for ODE solver
SourceFiles
ODESolver.C

View file

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Class
RK
Foam::RK
Description
Fifth-order Cash-Karp embedded Runge-Kutta scheme with error control and

View file

@ -33,6 +33,7 @@ Description
SourceFiles
SIBS.C
SIMPR.C
polyExtrapolate.C
\*---------------------------------------------------------------------------*/
@ -62,8 +63,8 @@ class SIBS
static const scalar safe1, safe2, redMax, redMin, scaleMX;
mutable scalarField a_;
mutable Matrix<scalar> alpha_;
mutable Matrix<scalar> d_p_;
mutable scalarSquareMatrix alpha_;
mutable scalarRectangularMatrix d_p_;
mutable scalarField x_p_;
mutable scalarField err_;
@ -71,7 +72,7 @@ class SIBS
mutable scalarField ySeq_;
mutable scalarField yErr_;
mutable scalarField dfdx_;
mutable Matrix<scalar> dfdy_;
mutable scalarSquareMatrix dfdy_;
mutable label first_, kMax_, kOpt_;
mutable scalar epsOld_, xNew_;
@ -85,13 +86,12 @@ class SIBS
const scalarField& y,
const scalarField& dydx,
const scalarField& dfdx,
const Matrix<scalar>& dfdy,
const scalarSquareMatrix& dfdy,
const scalar deltaX,
const label nSteps,
scalarField& yEnd
) const;
void polyExtrapolate
(
const label iest,
@ -100,7 +100,7 @@ class SIBS
scalarField& yz,
scalarField& dy,
scalarField& x_p,
Matrix<scalar>& d_p
scalarRectangularMatrix& d_p
) const;

View file

@ -25,7 +25,6 @@ License
\*---------------------------------------------------------------------------*/
#include "SIBS.H"
#include "simpleMatrix.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -35,7 +34,7 @@ void Foam::SIBS::SIMPR
const scalarField& y,
const scalarField& dydx,
const scalarField& dfdx,
const Matrix<scalar>& dfdy,
const scalarSquareMatrix& dfdy,
const scalar deltaX,
const label nSteps,
scalarField& yEnd

View file

@ -36,7 +36,7 @@ void Foam::SIBS::polyExtrapolate
scalarField& yz,
scalarField& dy,
scalarField& x,
Matrix<scalar>& d
scalarRectangularMatrix& d
) const
{
label n = yz.size();

View file

@ -2,17 +2,18 @@ signals/sigFpe.C
signals/sigSegv.C
signals/sigInt.C
signals/sigQuit.C
regExp.C
timer.C
fileStat.C
Unix.C
POSIX.C
cpuTime/cpuTime.C
clockTime/clockTime.C
multiThreader/multiThreader.C
#ifndef SunOS64
printStack.C
#else
#ifdef SunOS64
dummyPrintStack.C
#else
printStack.C
#endif
LIB = $(FOAM_LIBBIN)/libOSspecific

View file

View file

@ -23,7 +23,7 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Description
UNIX versions of the functions declated in OSspecific.H.
POSIX versions of the functions declared in OSspecific.H
\*---------------------------------------------------------------------------*/
@ -32,7 +32,7 @@ Description
#endif
#include "OSspecific.H"
#include "Unix.H"
#include "POSIX.H"
#include "foamVersion.H"
#include "fileName.H"
#include "fileStat.H"
@ -56,7 +56,7 @@ Description
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
defineTypeNameAndDebug(Foam::Unix, 0);
defineTypeNameAndDebug(Foam::POSIX, 0);
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -91,7 +91,9 @@ Foam::string Foam::getEnv(const word& envName)
}
else
{
return string::null;
// Return null-constructed string rather than string::null
// to avoid cyclic dependencies in the construction of globals
return string();
}
}
@ -211,23 +213,23 @@ bool Foam::chDir(const fileName& dir)
}
Foam::fileName Foam::dotFoam(const fileName& name)
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;
if (exists(fullName))
if (isFile(fullName))
{
return fullName;
}
// Check for version-independent user file in ~/.OpenFOAM
fullName = searchDir/name;
if (exists(fullName))
if (isFile(fullName))
{
return fullName;
}
@ -237,18 +239,18 @@ Foam::fileName Foam::dotFoam(const fileName& name)
// 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;
if (exists(fullName))
if (isFile(fullName))
{
return fullName;
}
// Check for version-independent site file in $WM_PROJECT_INST_DIR/site
fullName = searchDir/"site"/name;
if (exists(fullName))
if (isFile(fullName))
{
return fullName;
}
@ -257,25 +259,36 @@ Foam::fileName Foam::dotFoam(const fileName& name)
// 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;
if (exists(fullName))
if (isFile(fullName))
{
return fullName;
}
}
// Not found
return fileName::null;
// abort if the file is mandatory, otherwise return null
if (mandatory)
{
cerr<< "--> FOAM FATAL ERROR in Foam::findEtcFile() :"
" could not find mandatory file\n '"
<< name.c_str() << "'\n\n" << std::endl;
::exit(1);
}
// Return null-constructed fileName rather than fileName::null
// to avoid cyclic dependencies in the construction of globals
return fileName();
}
bool Foam::mkDir(const fileName& pathName, mode_t mode)
{
// empty names are meaningless
if (!pathName.size())
if (pathName.empty())
{
return false;
}
@ -419,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;
}
@ -429,7 +442,6 @@ bool Foam::chmod(const fileName& name, const mode_t m)
mode_t Foam::mode(const fileName& name)
{
fileStat fileStatus(name);
if (fileStatus.isValid())
{
return fileStatus.status().st_mode;
@ -462,28 +474,28 @@ Foam::fileName::Type Foam::type(const fileName& name)
// Does the name exist in the filing system?
bool Foam::exists(const fileName& name)
bool Foam::exists(const fileName& name, const bool checkGzip)
{
return mode(name) || file(name);
return mode(name) || isFile(name, checkGzip);
}
// Does the file exist
bool Foam::file(const fileName& name)
{
return S_ISREG(mode(name)) || S_ISREG(mode(name + ".gz"));
}
// Does the directory exist
bool Foam::dir(const fileName& name)
// Does the directory exist?
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::size(const fileName& name)
off_t Foam::fileSize(const fileName& name)
{
fileStat fileStatus(name);
if (fileStatus.isValid())
@ -524,7 +536,7 @@ Foam::fileNameList Foam::readDir
// also used as increment if initial size found to be insufficient
static const int maxNnames = 100;
if (Unix::debug)
if (POSIX::debug)
{
Info<< "readDir(const fileName&, const fileType, const bool filtergz)"
<< " : reading directory " << directory << endl;
@ -533,7 +545,7 @@ Foam::fileNameList Foam::readDir
// Setup empty string list MAXTVALUES long
fileNameList dirEntries(maxNnames);
// Pointers to the Unix director system
// Pointers to the directory entries
DIR *source;
struct dirent *list;
@ -545,7 +557,7 @@ Foam::fileNameList Foam::readDir
{
dirEntries.setSize(0);
if (Unix::debug)
if (POSIX::debug)
{
Info<< "readDir(const fileName&, const fileType, "
"const bool filtergz) : cannot open directory "
@ -559,10 +571,10 @@ Foam::fileNameList Foam::readDir
{
fileName fName(list->d_name);
// ignore files begining with ., i.e. ., .. and .??*
if (fName.size() > 0 && fName[size_t(0)] != '.')
// ignore files begining with ., i.e. '.', '..' and '.*'
if (fName.size() && fName[0] != '.')
{
word fileNameExt = fName.ext();
word fExt = fName.ext();
if
(
@ -570,11 +582,11 @@ Foam::fileNameList Foam::readDir
||
(
type == fileName::FILE
&& fName[fName.size()-1] != '~'
&& fileNameExt != "bak"
&& fileNameExt != "BAK"
&& fileNameExt != "old"
&& fileNameExt != "save"
&& fName[fName.size()-1] != '~'
&& fExt != "bak"
&& fExt != "BAK"
&& fExt != "old"
&& fExt != "save"
)
)
{
@ -585,7 +597,7 @@ Foam::fileNameList Foam::readDir
dirEntries.setSize(dirEntries.size() + maxNnames);
}
if (filtergz && fileNameExt == "gz")
if (filtergz && fExt == "gz")
{
dirEntries[nEntries++] = fName.lessExt();
}
@ -608,17 +620,17 @@ Foam::fileNameList Foam::readDir
}
// Copy, recursively if necessary, the source top the destination
// Copy, recursively if necessary, the source to the destination
bool Foam::cp(const fileName& src, const fileName& dest)
{
fileName destFile(dest);
// Make sure source exists.
if (!exists(src))
{
return false;
}
fileName destFile(dest);
// Check type of source file.
if (src.type() == fileName::FILE)
{
@ -629,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;
}
@ -668,8 +680,8 @@ bool Foam::cp(const fileName& src, const fileName& dest)
destFile = destFile/src.component(src.components().size() -1);
}
// Make sure the destination directory extists.
if (!dir(destFile) && !mkDir(destFile))
// Make sure the destination directory exists.
if (!isDir(destFile) && !mkDir(destFile))
{
return false;
}
@ -678,7 +690,7 @@ bool Foam::cp(const fileName& src, const fileName& dest)
fileNameList contents = readDir(src, fileName::FILE, false);
forAll(contents, i)
{
if (Unix::debug)
if (POSIX::debug)
{
Info<< "Copying : " << src/contents[i]
<< " to " << destFile/contents[i] << endl;
@ -692,7 +704,7 @@ bool Foam::cp(const fileName& src, const fileName& dest)
fileNameList subdirs = readDir(src, fileName::DIRECTORY);
forAll(subdirs, i)
{
if (Unix::debug)
if (POSIX::debug)
{
Info<< "Copying : " << src/subdirs[i]
<< " to " << destFile << endl;
@ -707,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)
if (POSIX::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;
}
@ -731,48 +743,87 @@ 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& src, const fileName& dst)
{
if (Unix::debug)
if (POSIX::debug)
{
Info<< "Move : " << srcFile << " to " << destFile << endl;
Info<< "Move : " << src << " to " << dst << endl;
}
if
(
(destFile.type() == fileName::DIRECTORY)
&& (srcFile.type() != fileName::DIRECTORY)
dst.type() == fileName::DIRECTORY
&& src.type() != fileName::DIRECTORY
)
{
const fileName destName(destFile/srcFile.name());
const fileName dstName(dst/src.name());
return rename(srcFile.c_str(), destName.c_str()) == 0;
return rename(src.c_str(), dstName.c_str()) == 0;
}
else
{
return rename(srcFile.c_str(), destFile.c_str()) == 0;
return rename(src.c_str(), dst.c_str()) == 0;
}
}
// Remove a file returning true if successful otherwise false
//- Rename to a corresponding backup file
// If the backup file already exists, attempt with "01" .. "99" index
bool Foam::mvBak(const fileName& src, const std::string& ext)
{
if (POSIX::debug)
{
Info<< "mvBak : " << src << " to extension " << ext << endl;
}
if (exists(src, false))
{
const int maxIndex = 99;
char index[3];
for (int n = 0; n <= maxIndex; n++)
{
fileName dstName(src + "." + ext);
if (n)
{
sprintf(index, "%02d", n);
dstName += index;
}
// avoid overwriting existing files, except for the last
// possible index where we have no choice
if (!exists(dstName, false) || n == maxIndex)
{
return rename(src.c_str(), dstName.c_str()) == 0;
}
}
}
// fall-through: nothing to do
return false;
}
// Remove a file, returning true if successful otherwise false
bool Foam::rm(const fileName& file)
{
if (Unix::debug)
if (POSIX::debug)
{
Info<< "Removing : " << file << endl;
}
@ -792,20 +843,20 @@ bool Foam::rm(const fileName& file)
// Remove a dirctory and its contents
bool Foam::rmDir(const fileName& directory)
{
if (Unix::debug)
if (POSIX::debug)
{
Info<< "rmdir(const fileName&) : "
Info<< "rmDir(const fileName&) : "
<< "removing directory " << directory << endl;
}
// Pointers to the Unix director system
// Pointers to the directory entries
DIR *source;
struct dirent *list;
// 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;
@ -825,7 +876,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;
@ -839,7 +890,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;
@ -855,7 +906,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);

View file

@ -23,18 +23,18 @@ License
Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Namespace
Foam::Unix
Foam::POSIX
Description
UNIX versions of OS-specific functions.
OS-specific functions implemented in POSIX.
SourceFiles
Unix.C
POSIX.C
\*---------------------------------------------------------------------------*/
#ifndef Unix_H
#define Unix_H
#ifndef POSIX_H
#define POSIX_H
#include "className.H"
@ -45,10 +45,10 @@ namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Unix
namespace POSIX
{
//- Declare name of the class and its debug switch
NamespaceName("Unix");
NamespaceName("POSIX");
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //

View file

@ -159,7 +159,7 @@ void getSymbolForRaw
const word& address
)
{
if (filename.size() > 0 && filename[0] == '/')
if (filename.size() && filename[0] == '/')
{
string fcnt = pOpen
(
@ -305,7 +305,7 @@ void error::printStack(Ostream& os)
string::size_type space = line.rfind(' ') + 1;
fileName libPath = line.substr(space, line.size()-space);
if (libPath.size() > 0 && libPath[0] == '/')
if (libPath.size() && libPath[0] == '/')
{
string offsetString(line.substr(0, line.find('-')));
IStringStream offsetStr(offsetString);
@ -350,7 +350,7 @@ void error::printStack(Ostream& os)
// not an absolute path
if (programFile[0] != '/')
{
string tmp = pOpen("which "+programFile);
string tmp = pOpen("which " + programFile);
if (tmp[0] == '/' || tmp[0] == '~')
{
programFile = tmp;
@ -361,13 +361,13 @@ void error::printStack(Ostream& os)
string::size_type bracketPos = msg.find('(');
if (bracketPos != string::size_type(string::npos))
if (bracketPos != string::npos)
{
string::size_type start = bracketPos+1;
string::size_type plusPos = msg.find('+', start);
if (plusPos != string::size_type(string::npos))
if (plusPos != string::npos)
{
string cName(msg.substr(start, plusPos-start));
@ -394,7 +394,7 @@ void error::printStack(Ostream& os)
{
string::size_type endBracketPos = msg.find(')', start);
if (endBracketPos != string::size_type(string::npos))
if (endBracketPos != string::npos)
{
string fullName(msg.substr(start, endBracketPos-start));

View file

@ -0,0 +1,216 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 <sys/types.h>
#include "regExp.H"
#include "label.H"
#include "string.H"
#include "List.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
Foam::regExp::regExp()
:
preg_(0)
{}
Foam::regExp::regExp(const char* pattern, const bool ignoreCase)
:
preg_(0)
{
set(pattern, ignoreCase);
}
Foam::regExp::regExp(const std::string& pattern, const bool ignoreCase)
:
preg_(0)
{
set(pattern.c_str(), ignoreCase);
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
Foam::regExp::~regExp()
{
clear();
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
void Foam::regExp::set(const char* pattern, const bool ignoreCase) const
{
clear();
// avoid NULL pointer and zero-length patterns
if (pattern && *pattern)
{
preg_ = new regex_t;
int cflags = REG_EXTENDED;
if (ignoreCase)
{
cflags |= REG_ICASE;
}
if (regcomp(preg_, pattern, cflags) != 0)
{
FatalErrorIn
(
"regExp::set(const char*)"
) << "Failed to compile regular expression '" << pattern << "'"
<< exit(FatalError);
}
}
}
void Foam::regExp::set(const std::string& pattern, const bool ignoreCase) const
{
return set(pattern.c_str(), ignoreCase);
}
bool Foam::regExp::clear() const
{
if (preg_)
{
regfree(preg_);
delete preg_;
preg_ = 0;
return true;
}
return false;
}
std::string::size_type Foam::regExp::find(const std::string& str) const
{
if (preg_ && str.size())
{
size_t nmatch = 1;
regmatch_t pmatch[1];
if (regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0)
{
return pmatch[0].rm_so;
}
}
return string::npos;
}
bool Foam::regExp::match(const std::string& str) const
{
if (preg_ && str.size())
{
size_t nmatch = 1;
regmatch_t pmatch[1];
// also verify that the entire string was matched
// pmatch[0] is the entire match
if
(
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(str.size()))
)
{
return true;
}
}
return false;
}
bool Foam::regExp::match(const string& str, List<string>& groups) const
{
if (preg_ && str.size())
{
size_t nmatch = ngroups() + 1;
regmatch_t pmatch[nmatch];
// also verify that the entire string was matched
// pmatch[0] is the entire match
// pmatch[1..] are the (...) sub-groups
if
(
regexec(preg_, str.c_str(), nmatch, pmatch, 0) == 0
&& (pmatch[0].rm_so == 0 && pmatch[0].rm_eo == label(str.size()))
)
{
groups.setSize(ngroups());
label groupI = 0;
for (size_t matchI = 1; matchI < nmatch; matchI++)
{
if (pmatch[matchI].rm_so != -1 && pmatch[matchI].rm_eo != -1)
{
groups[groupI] = str.substr
(
pmatch[matchI].rm_so,
pmatch[matchI].rm_eo - pmatch[matchI].rm_so
);
}
else
{
groups[groupI].clear();
}
groupI++;
}
return true;
}
}
groups.clear();
return false;
}
// * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * * //
void Foam::regExp::operator=(const char* pat)
{
set(pat);
}
void Foam::regExp::operator=(const std::string& pat)
{
set(pat);
}
// ************************************************************************* //

View file

@ -0,0 +1,190 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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::regExp
Description
Wrapper around POSIX extended regular expressions.
SeeAlso
The manpage regex(7) for more information about POSIX regular expressions.
These differ somewhat from @c Perl and @c sed regular expressions.
SourceFiles
regExp.C
\*---------------------------------------------------------------------------*/
#ifndef regExp_H
#define regExp_H
#include <regex.h>
#include <string>
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of classes
class string;
template<class T> class List;
/*---------------------------------------------------------------------------*\
Class regExp Declaration
\*---------------------------------------------------------------------------*/
class regExp
{
// Private data
//- Precompiled regular expression
mutable regex_t* preg_;
// Private member functions
//- Disallow default bitwise copy construct
regExp(const regExp&);
//- Disallow default bitwise assignment
void operator=(const regExp&);
public:
//- Is character a regular expression meta-character?
// any character: '.' \n
// quantifiers: '*', '+', '?' \n
// grouping: '(', '|', ')' \n
// range: '[', ']' \n
//
// Don't bother checking for '{digit}' bounds
inline static bool meta(char c)
{
return
(
(c == '.') // any character
|| (c == '*' || c == '+' || c == '?') // quantifiers
|| (c == '(' || c == ')' || c == '|') // grouping/branching
|| (c == '[' || c == ']') // range
);
}
// Constructors
//- Construct null
regExp();
//- Construct from character array, optionally ignoring case
regExp(const char*, const bool ignoreCase=false);
//- Construct from std::string (or string), optionally ignoring case
regExp(const std::string&, const bool ignoreCase=false);
// Destructor
~regExp();
// Member functions
//- Access
//- Return true if a precompiled expression does not exist
inline bool empty() const
{
return !preg_;
}
//- Does a precompiled expression exist?
inline bool exists() const
{
return preg_ ? true : false;
}
//- Return the number of (groups)
inline int ngroups() const
{
return preg_ ? preg_->re_nsub : 0;
}
//- Editing
//- Compile pattern into a regular expression, optionally ignoring case
void set(const char*, const bool ignoreCase=false) const;
//- Compile pattern into a regular expression, optionally ignoring case
void set(const std::string&, const bool ignoreCase=false) const;
//- Release precompiled expression.
// Returns true if precompiled expression existed before clear
bool clear() const;
//- Searching
//- Find position within string.
// Returns the index where it begins or string::npos if not found
std::string::size_type find(const std::string& str) const;
//- Return true if it matches the entire string
// The begin-of-line (^) and end-of-line ($) anchors are implicit
bool match(const std::string&) const;
//- Return true if it matches and sets the sub-groups matched
// The begin-of-line (^) and end-of-line ($) anchors are implicit
bool match(const string&, List<string>& groups) const;
//- Return true if the regex was found in within string
bool search(const std::string& str) const
{
return std::string::npos != find(str);
}
// Member Operators
//- Assign and compile pattern from a character array
// Always case sensitive
void operator=(const char*);
//- Assign and compile pattern from string
// Always case sensitive
void operator=(const std::string&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -24,8 +24,6 @@ License
\*---------------------------------------------------------------------------*/
#include <stdint.h>
#include "error.H"
#include "sigFpe.H"
@ -69,7 +67,7 @@ void* Foam::sigFpe::my_malloc_hook(size_t size, const void *caller)
result = malloc (size);
// initialize to signalling nan
# ifdef SP
# ifdef WM_SP
const uint32_t sNAN = 0x7ff7fffflu;
@ -178,7 +176,7 @@ Foam::sigFpe::~sigFpe()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigFpe::set()
void Foam::sigFpe::set(const bool verbose)
{
if (oldAction_.sa_handler)
{
@ -191,6 +189,12 @@ void Foam::sigFpe::set()
if (env("FOAM_SIGFPE"))
{
if (verbose)
{
Info<< "SigFpe : Enabling floating point exception trapping"
<< " (FOAM_SIGFPE)." << endl;
}
# ifdef LINUX_GNUC
feenableexcept
@ -241,6 +245,12 @@ void Foam::sigFpe::set()
if (env("FOAM_SETNAN"))
{
if (verbose)
{
Info<< "SetNaN : Initialising allocated memory to NaN"
<< " (FOAM_SETNAN)." << endl;
}
# ifdef LINUX_GNUC
// Set our malloc

View file

@ -107,7 +107,7 @@ public:
// Member functions
void set();
void set(const bool verbose);
};

View file

@ -81,7 +81,7 @@ Foam::sigInt::~sigInt()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigInt::set()
void Foam::sigInt::set(const bool verbose)
{
if (oldAction_.sa_handler)
{

View file

@ -78,7 +78,7 @@ public:
// Member functions
void set();
void set(const bool verbose);
};

View file

@ -83,7 +83,7 @@ Foam::sigQuit::~sigQuit()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigQuit::set()
void Foam::sigQuit::set(const bool verbose)
{
if (oldAction_.sa_handler)
{

View file

@ -78,7 +78,7 @@ public:
// Member functions
void set();
void set(const bool verbose);
};

View file

@ -83,7 +83,7 @@ Foam::sigSegv::~sigSegv()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void Foam::sigSegv::set()
void Foam::sigSegv::set(const bool verbose)
{
if (oldAction_.sa_handler)
{

View file

@ -78,7 +78,7 @@ public:
// Member functions
void set();
void set(const bool verbose);
};

View file

@ -1,4 +0,0 @@
EXE_INC = \
LIB_LIBS = \
-lpthread

View file

@ -3,32 +3,42 @@ global/dimensionedConstants/dimensionedConstants.C
global/argList/argList.C
global/clock/clock.C
primitives/bool/bool.C
primitives/bool/boolIO.C
bools = primitives/bools
$(bools)/bool/bool.C
$(bools)/bool/boolIO.C
$(bools)/Switch/Switch.C
$(bools)/Switch/SwitchIO.C
primitives/char/charIO.C
primitives/int/intIO.C
primitives/uint/uintIO.C
primitives/long/longIO.C
primitives/longLong/longLongIO.C
primitives/ulong/ulongIO.C
primitives/label/label.C
ints = primitives/ints
$(ints)/int/intIO.C
$(ints)/uint/uintIO.C
$(ints)/long/longIO.C
$(ints)/longLong/longLongIO.C
$(ints)/ulong/ulongIO.C
$(ints)/label/label.C
$(ints)/uLabel/uLabel.C
primitives/Scalar/doubleScalar/doubleScalar.C
primitives/Scalar/floatScalar/floatScalar.C
primitives/Scalar/scalar/scalar.C
primitives/labelVector/labelVector.C
primitives/vector/vector.C
primitives/vector2D/vector2D.C
primitives/sphericalTensor/sphericalTensor.C
primitives/sphericalTensor2D/sphericalTensor2D.C
primitives/diagTensor/diagTensor.C
primitives/symmTensor/symmTensor.C
primitives/tensor/tensor.C
primitives/tensor2D/tensor2D.C
primitives/labelSphericalTensor/labelSphericalTensor.C
primitives/labelSymmTensor/labelSymmTensor.C
primitives/labelTensor/labelTensor.C
primitives/DiagTensor/diagTensor/diagTensor.C
primitives/SphericalTensor/sphericalTensor/sphericalTensor.C
primitives/SphericalTensor/labelSphericalTensor/labelSphericalTensor.C
primitives/SymmTensor/labelSymmTensor/labelSymmTensor.C
primitives/SymmTensor/symmTensor/symmTensor.C
primitives/Tensor/labelTensor/labelTensor.C
primitives/Tensor/tensor/tensor.C
primitives/Vector/complexVector/complexVector.C
primitives/Vector/labelVector/labelVector.C
primitives/Vector/vector/vector.C
primitives/Tensor2D/tensor2D/tensor2D.C
primitives/SphericalTensor2D/sphericalTensor2D/sphericalTensor2D.C
primitives/Vector2D/vector2D/vector2D.C
primitives/complex/complex.C
primitives/complexVector/complexVector.C
primitives/quaternion/quaternion.C
primitives/septernion/septernion.C
@ -39,6 +49,14 @@ $(strings)/word/word.C
$(strings)/word/wordIO.C
$(strings)/fileName/fileName.C
$(strings)/fileName/fileNameIO.C
$(strings)/keyType/keyTypeIO.C
$(strings)/wordRe/wordReIO.C
primitives/hashes/Hasher/Hasher.C
sha1 = primitives/hashes/SHA1
$(sha1)/SHA1.C
$(sha1)/SHA1Digest.C
coordinateSystems/coordinateSystem.C
coordinateSystems/coordinateSystems.C
@ -68,6 +86,7 @@ primitiveLists = primitives/Lists
$(primitiveLists)/boolList.C
$(primitiveLists)/labelIOList.C
$(primitiveLists)/scalarList.C
$(primitiveLists)/scalarIOList.C
$(primitiveLists)/vectorList.C
$(primitiveLists)/sphericalTensorList.C
$(primitiveLists)/symmTensorList.C
@ -81,19 +100,14 @@ IOstreams = $(Streams)/IOstreams
$(IOstreams)/IOstream.C
$(IOstreams)/versionNumber.C
$(IOstreams)/Istream.C
$(IOstreams)/IOprint.C
$(IOstreams)/IOcheck.C
$(IOstreams)/Ostream.C
Sstreams = $(Streams)/Sstreams
$(Sstreams)/ISread.C
$(Sstreams)/ISnextValid.C
$(Sstreams)/ISreadToken.C
$(Sstreams)/ISstream.C
$(Sstreams)/OSstream.C
$(Sstreams)/SstreamsPrint.C
$(Sstreams)/readHexLabel.C
$(Sstreams)/OSwrite.C
$(Sstreams)/Sprint.C
$(Sstreams)/prefixOSstream/prefixOSwrite.C
$(Sstreams)/prefixOSstream/prefixOSprint.C
$(Sstreams)/prefixOSstream.C
gzstream = $(Streams)/gzstream
$(gzstream)/gzstream.C
@ -103,19 +117,17 @@ $(Fstreams)/IFstream.C
$(Fstreams)/OFstream.C
Tstreams = $(Streams)/Tstreams
$(Tstreams)/ITread.C
$(Tstreams)/Tprint.C
$(Tstreams)/ITstream.C
StringStreams = $(Streams)/StringStreams
$(StringStreams)/StringStreamPrint.C
$(StringStreams)/StringStreamsPrint.C
Pstreams = $(Streams)/Pstreams
$(Pstreams)/Pstream.C
$(Pstreams)/PstreamCommsStruct.C
$(Pstreams)/IPread.C
$(Pstreams)/OPwrite.C
$(Pstreams)/Pprint.C
$(Pstreams)/IPreadToken.C
$(Pstreams)/IPstream.C
$(Pstreams)/OPstream.C
$(Pstreams)/PstreamsPrint.C
dictionary = db/dictionary
$(dictionary)/dictionary.C
@ -136,6 +148,7 @@ $(dictionaryEntry)/dictionaryEntryIO.C
functionEntries = $(dictionary)/functionEntries
$(functionEntries)/functionEntry/functionEntry.C
$(functionEntries)/includeEntry/includeEntry.C
$(functionEntries)/includeIfPresentEntry/includeIfPresentEntry.C
$(functionEntries)/inputModeEntry/inputModeEntry.C
$(functionEntries)/removeEntry/removeEntry.C
@ -158,14 +171,13 @@ $(regIOobject)/regIOobjectWrite.C
db/IOobjectList/IOobjectList.C
db/objectRegistry/objectRegistry.C
db/functionObject/functionObject.C
db/functionObjectList/functionObjectList.C
db/CallbackRegistry/CallbackRegistryName.C
db/dlLibraryTable/dlLibraryTable.C
Switch = db/Switch
$(Switch)/Switch.C
$(Switch)/SwitchIO.C
db/functionObjects/functionObject/functionObject.C
db/functionObjects/functionObjectList/functionObjectList.C
db/functionObjects/outputFilterOutputControl/outputFilterOutputControl.C
Time = db/Time
$(Time)/TimePaths.C
@ -319,7 +331,6 @@ $(tetCell)/tetCell.C
cellModeller = $(meshShapes)/cellModeller
$(cellModeller)/cellModeller.C
$(cellModeller)/cellModellerIO.C
cellModel = $(meshShapes)/cellModel
$(cellModel)/cellModel.C
@ -383,7 +394,7 @@ faceZone = $(zones)/faceZone
$(faceZone)/faceZone.C
$(faceZone)/newFaceZone.C
pointZone = $(zones)/pointZone
pointZone = $(polyMesh)/zones/pointZone
$(pointZone)/pointZone.C
$(pointZone)/newPointZone.C
@ -434,7 +445,6 @@ $(cellMatcher)/degenerateMatcher.C
mapPolyMesh = $(polyMesh)/mapPolyMesh
$(mapPolyMesh)/mapPolyMesh.C
$(mapPolyMesh)/pointMapper/pointMapper.C
$(mapPolyMesh)/faceMapper/faceMapper.C
$(mapPolyMesh)/cellMapper/cellMapper.C
$(mapPolyMesh)/mapDistribute/mapDistribute.C
@ -486,6 +496,9 @@ meshTools = meshes/meshTools
$(meshTools)/matchPoints.C
$(meshTools)/mergePoints.C
fields/UniformDimensionedFields/uniformDimensionedFields.C
fields/cloud/cloud.C
Fields = fields/Fields
$(Fields)/labelField/labelField.C
$(Fields)/scalarField/scalarField.C
@ -495,8 +508,6 @@ $(Fields)/symmTensorField/symmTensorField.C
$(Fields)/tensorField/tensorField.C
$(Fields)/complexFields/complexFields.C
fields/cloud/cloud.C
$(Fields)/labelField/labelIOField.C
$(Fields)/scalarField/scalarIOField.C
$(Fields)/vectorField/vectorIOField.C
@ -506,6 +517,7 @@ $(Fields)/diagTensorField/diagTensorIOField.C
$(Fields)/symmTensorField/symmTensorIOField.C
$(Fields)/tensorField/tensorIOField.C
$(Fields)/transformField/transformField.C
pointPatchFields = fields/pointPatchFields
$(pointPatchFields)/pointPatchField/pointPatchFields.C

View file

@ -28,22 +28,15 @@ Description
#include "Dictionary.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Null constructor
template<class T>
Dictionary<T>::Dictionary()
Foam::Dictionary<T>::Dictionary()
{}
// Copy constructor
template<class T>
Dictionary<T>::Dictionary(const Dictionary& dict)
Foam::Dictionary<T>::Dictionary(const Dictionary& dict)
:
DictionaryBase<IDLList<T>, T>(dict)
{}
@ -52,10 +45,10 @@ Dictionary<T>::Dictionary(const Dictionary& dict)
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
bool Dictionary<T>::erase(const word& Keyword)
bool Foam::Dictionary<T>::erase(const word& keyword)
{
T* tPtr;
if ((tPtr = this->remove(Keyword)))
if (tPtr = this->remove(keyword))
{
delete tPtr;
return true;
@ -69,6 +62,4 @@ bool Dictionary<T>::erase(const word& Keyword)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -27,8 +27,10 @@ Class
Description
Gerneral purpose template dictionary class which manages the storage
associated with it. It is derived from DictionaryBase instantiated on
a memory managed form of intrusive doubly-linked list of \<T\>.
associated with it.
It is derived from DictionaryBase instantiated on a memory managed form
of intrusive doubly-linked list of \<T\>.
SourceFiles
Dictionary.C
@ -47,7 +49,7 @@ namespace Foam
{
/*---------------------------------------------------------------------------*\
Class Dictionary Declaration
Class Dictionary Declaration
\*---------------------------------------------------------------------------*/
template<class T>
@ -69,11 +71,9 @@ public:
// Member functions
// Editing
//- Remove an entry specified by keyword from the dictionary
// and delete it
bool erase(const word& keyword);
//- Remove an entry specified by keyword and delete the pointer.
// Returns true if the keyword was found
bool erase(const word& keyword);
};

View file

@ -26,15 +26,10 @@ License
#include "DictionaryBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
template<class IDLListType, class T>
void DictionaryBase<IDLListType, T>::addEntries()
void Foam::DictionaryBase<IDLListType, T>::addEntries()
{
for
(
@ -51,12 +46,15 @@ void DictionaryBase<IDLListType, T>::addEntries()
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class IDLListType, class T>
DictionaryBase<IDLListType, T>::DictionaryBase()
Foam::DictionaryBase<IDLListType, T>::DictionaryBase()
{}
template<class IDLListType, class T>
DictionaryBase<IDLListType, T>::DictionaryBase(const DictionaryBase& dict)
Foam::DictionaryBase<IDLListType, T>::DictionaryBase
(
const DictionaryBase& dict
)
:
IDLListType(dict)
{
@ -66,17 +64,20 @@ DictionaryBase<IDLListType, T>::DictionaryBase(const DictionaryBase& dict)
template<class IDLListType, class T>
template<class INew>
DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is, const INew& inewt)
Foam::DictionaryBase<IDLListType, T>::DictionaryBase
(
Istream& is,
const INew& iNew
)
:
IDLListType(is, inewt)
IDLListType(is, iNew)
{
addEntries();
}
// Istream constructor
template<class IDLListType, class T>
DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is)
Foam::DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is)
:
IDLListType(is)
{
@ -88,25 +89,60 @@ DictionaryBase<IDLListType, T>::DictionaryBase(Istream& is)
// Find and return T
template<class IDLListType, class T>
bool DictionaryBase<IDLListType, T>::found(const word& keyword) const
bool Foam::DictionaryBase<IDLListType, T>::found(const word& keyword) const
{
return hashedTs_.found(keyword);
}
// Find and return T*
// Find and return T*, return NULL if not found
template<class IDLListType, class T>
const T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) const
const T* Foam::DictionaryBase<IDLListType, T>::lookupPtr
(
const word& keyword
) const
{
typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword);
if (iter != hashedTs_.end())
{
return *iter;
}
else
{
return NULL;
}
}
// Find and return T*, return NULL if not found
template<class IDLListType, class T>
T* Foam::DictionaryBase<IDLListType, T>::lookupPtr(const word& keyword)
{
typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
if (iter != hashedTs_.end())
{
return *iter;
}
else
{
return NULL;
}
}
// Find and return T*, FatalError if keyword not found
template<class IDLListType, class T>
const T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword) const
{
typename HashTable<T*>::const_iterator iter = hashedTs_.find(keyword);
if (iter == hashedTs_.end())
{
// If keyword not found print error message ...
FatalErrorIn
(
"DictionaryBase<IDLListType, T>::"
"lookup(const word& keyword) const"
"DictionaryBase<IDLListType, T>::lookup(const word&) const"
) << keyword << " is undefined"
<< exit(FatalError);
}
@ -115,18 +151,17 @@ const T* DictionaryBase<IDLListType, T>::lookup(const word& keyword) const
}
// Find and return T*
// Find and return T*, FatalError if keyword not found
template<class IDLListType, class T>
T* DictionaryBase<IDLListType, T>::lookup(const word& keyword)
T* Foam::DictionaryBase<IDLListType, T>::lookup(const word& keyword)
{
typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
if (iter == hashedTs_.end())
{
// If keyword not found print error message ...
FatalErrorIn
(
"DictionaryBase<IDLListType, T>::lookup(const word& keyword)"
"DictionaryBase<IDLListType, T>::lookup(const word&)"
) << keyword << " is undefined"
<< exit(FatalError);
}
@ -137,7 +172,7 @@ T* DictionaryBase<IDLListType, T>::lookup(const word& keyword)
// Return the table of contents
template<class IDLListType, class T>
wordList DictionaryBase<IDLListType, T>::toc() const
Foam::wordList Foam::DictionaryBase<IDLListType, T>::toc() const
{
wordList keywords(this->size());
@ -158,26 +193,28 @@ wordList DictionaryBase<IDLListType, T>::toc() const
// Add at head of dictionary
template<class IDLListType, class T>
void DictionaryBase<IDLListType, T>::insert(const word& keyword, T* tPtr)
void Foam::DictionaryBase<IDLListType, T>::insert(const word& keyword, T* tPtr)
{
IDLListType::insert(tPtr);
// NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, tPtr);
IDLListType::insert(tPtr);
}
// Add at tail of dictionary
template<class IDLListType, class T>
void DictionaryBase<IDLListType, T>::append(const word& keyword, T* tPtr)
void Foam::DictionaryBase<IDLListType, T>::append(const word& keyword, T* tPtr)
{
IDLListType::append(tPtr);
// NOTE: we should probably check that HashTable::insert actually worked
hashedTs_.insert(keyword, tPtr);
IDLListType::append(tPtr);
}
template<class IDLListType, class T>
T* DictionaryBase<IDLListType, T>::remove(const word& Keyword)
T* Foam::DictionaryBase<IDLListType, T>::remove(const word& keyword)
{
typename HashTable<T*>::iterator iter = hashedTs_.find(Keyword);
typename HashTable<T*>::iterator iter = hashedTs_.find(keyword);
if (iter != hashedTs_.end())
{
@ -192,19 +229,29 @@ T* DictionaryBase<IDLListType, T>::remove(const word& Keyword)
}
//- Clear the dictionary
template<class IDLListType, class T>
void DictionaryBase<IDLListType, T>::clear()
void Foam::DictionaryBase<IDLListType, T>::clear()
{
IDLListType::clear();
hashedTs_.clear();
}
template<class IDLListType, class T>
void Foam::DictionaryBase<IDLListType, T>::transfer
(
DictionaryBase<IDLListType, T>& dict
)
{
IDLListType::transfer(dict);
hashedTs_.transfer(dict.hashedTs_);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class IDLListType, class T>
void DictionaryBase<IDLListType, T>::operator=
void Foam::DictionaryBase<IDLListType, T>::operator=
(
const DictionaryBase<IDLListType, T>& dict
)
@ -218,25 +265,11 @@ void DictionaryBase<IDLListType, T>::operator=
}
IDLListType::operator=(dict);
this->hashedTs_.clear();
for
(
typename IDLListType::iterator iter = this->begin();
iter != this->end();
++iter
)
{
this->hashedTs_.insert((*iter).keyword(), &(*iter));
}
this->addEntries();
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "DictionaryBaseIO.C"

View file

@ -29,12 +29,12 @@ Description
Base dictionary class templated on both the form of doubly-linked list
it uses as well as the type it holds.
The double templating allows for the instantiation of forms with and
The double templating allows for the instantiation of forms with or
without storage management.
Note
The IDLListType parameter should itself be a template but this confused
gcc 2.95.2 so it has to be instantiated for T when an intantiation of
gcc 2.95.2 so it has to be instantiated for T when an instantiation of
DictionaryBase is requested
See Also
@ -67,7 +67,7 @@ Ostream& operator<<(Ostream&, const DictionaryBase<IDLListType, T>&);
/*---------------------------------------------------------------------------*\
Class DictionaryBase Declaration
Class DictionaryBase Declaration
\*---------------------------------------------------------------------------*/
template<class IDLListType, class T>
@ -77,7 +77,7 @@ class DictionaryBase
{
// Private data
//- HashTable of the enries held on the DL-list for quick lookup
//- HashTable of the entries held on the IDLListType for quick lookup
HashTable<T*> hashedTs_;
@ -99,10 +99,10 @@ public:
//- Construct from Istream using given Istream constructor class
template<class INew>
DictionaryBase(Istream& is, const INew& inewt);
DictionaryBase(Istream&, const INew&);
//- Construct from Istream
DictionaryBase(Istream& is);
//- Construct from Istream using default Istream constructor class
DictionaryBase(Istream&);
// Member functions
@ -110,7 +110,13 @@ public:
// Search and lookup
//- Search DictionaryBase for given keyword
bool found(const word& keyword) const;
bool found(const word&) const;
//- Find and return an entry if present, otherwise return NULL
const T* lookupPtr(const word&) const;
//- Find and return an entry if present, otherwise return NULL
T* lookupPtr(const word&);
//- Find and return entry
const T* lookup(const word&) const;
@ -125,17 +131,21 @@ public:
// Editing
//- Add at head of dictionary
void insert(const word& keyword, T*);
void insert(const word&, T*);
//- Add at tail of dictionary
void append(const word& keyword, T*);
void append(const word&, T*);
//- Remove and return entry specified by keyword
T* remove(const word& keyword);
//- Remove and return entry specified by keyword.
// Return NULL if the keyword was not found.
T* remove(const word&);
//- Clear the dictionary
void clear();
//- Transfer the contents of the argument into this DictionaryBase
// and annull the argument.
void transfer(DictionaryBase<IDLListType, T>&);
// Member operators

View file

@ -0,0 +1,199 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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
\*---------------------------------------------------------------------------*/
#ifndef HashSet_C
#define HashSet_C
#include "HashSet.H"
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class Key, class Hash>
template<class AnyType, class AnyHash>
Foam::HashSet<Key, Hash>::HashSet
(
const HashTable<AnyType, Key, AnyHash>& h
)
:
HashTable<nil, Key, Hash>(h.size())
{
for
(
typename HashTable<AnyType, Key, AnyHash>::const_iterator
cit = h.cbegin();
cit != h.cend();
++cit
)
{
insert(cit.key());
}
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class Key, class Hash>
inline bool Foam::HashSet<Key, Hash>::operator[](const Key& key) const
{
return found(key);
}
template<class Key, class Hash>
bool Foam::HashSet<Key, Hash>::operator==(const HashSet<Key, Hash>& rhs) const
{
// Are all lhs elements in rhs?
for (const_iterator iter = this->cbegin(); iter != this->cend(); ++iter)
{
if (!rhs.found(iter.key()))
{
return false;
}
}
// Are all rhs elements in lhs?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
if (!found(iter.key()))
{
return false;
}
}
return true;
}
template<class Key, class Hash>
bool Foam::HashSet<Key, Hash>::operator!=(const HashSet<Key, Hash>& rhs) const
{
return !(operator==(rhs));
}
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator|=(const HashSet<Key, Hash>& rhs)
{
// Add rhs elements into lhs
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
insert(iter.key());
}
}
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator&=(const HashSet<Key, Hash>& rhs)
{
// Remove elements not also found in rhs
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (!rhs.found(iter.key()))
{
erase(iter);
}
}
}
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator^=(const HashSet<Key, Hash>& rhs)
{
// Add missed rhs elements, remove duplicate elements
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
if (found(iter.key()))
{
erase(iter.key());
}
else
{
insert(iter.key());
}
}
}
// same as HashTable::erase()
template<class Key, class Hash>
void Foam::HashSet<Key, Hash>::operator-=(const HashSet<Key, Hash>& rhs)
{
// Remove rhs elements from lhs
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
erase(iter.key());
}
}
/* * * * * * * * * * * * * * * * Global operators * * * * * * * * * * * * * */
template<class Key, class Hash>
Foam::HashSet<Key, Hash>
Foam::operator|
(
const HashSet<Key, Hash>& hash1,
const HashSet<Key, Hash>& hash2
)
{
HashSet<Key, Hash> out(hash1);
out |= hash2;
return out;
}
template<class Key, class Hash>
Foam::HashSet<Key, Hash>
Foam::operator&
(
const HashSet<Key, Hash>& hash1,
const HashSet<Key, Hash>& hash2
)
{
HashSet<Key, Hash> out(hash1);
out &= hash2;
return out;
}
template<class Key, class Hash>
Foam::HashSet<Key, Hash>
Foam::operator^
(
const HashSet<Key, Hash>& hash1,
const HashSet<Key, Hash>& hash2
)
{
HashSet<Key, Hash> out(hash1);
out ^= hash2;
return out;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -26,7 +26,7 @@ Class
Foam::HashSet
Description
A HashTable with word keys but without contents.
A HashTable with keys but without contents.
Typedef
Foam::wordHashSet
@ -34,13 +34,19 @@ Typedef
Description
A HashSet with (the default) word keys.
Typedef
Foam::labelHashSet
Description
A HashSet with label keys.
\*---------------------------------------------------------------------------*/
#ifndef HashSet_H
#define HashSet_H
#include "HashTable.H"
#include "empty.H"
#include "nil.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,57 +60,149 @@ namespace Foam
template<class Key=word, class Hash=string::hash>
class HashSet
:
public HashTable<empty, Key, Hash>
public HashTable<nil, Key, Hash>
{
public:
typedef typename HashTable<nil, Key, Hash>::iterator iterator;
typedef typename HashTable<nil, Key, Hash>::const_iterator const_iterator;
// Constructors
//- Construct given initial map size
explicit HashSet(label size = 100)
//- Construct given initial size
HashSet(const label size = 128)
:
HashTable<empty, Key, Hash>(size)
HashTable<nil, Key, Hash>(size)
{}
//- Construct from Istream
explicit HashSet(Istream& is)
HashSet(Istream& is)
:
HashTable<empty, Key, Hash>(is)
HashTable<nil, Key, Hash>(is)
{}
//- Construct from UList of Key
explicit HashSet(const UList<Key>& ul)
HashSet(const UList<Key>& lst)
:
HashTable<empty, Key, Hash>(2*ul.size())
HashTable<nil, Key, Hash>(2*lst.size())
{
forAll (ul, i)
forAll(lst, i)
{
insert(ul[i]);
insert(lst[i]);
}
}
//- Construct as copy
HashSet(const HashSet<Key, Hash>& hs)
:
HashTable<empty, Key, Hash>(hs)
HashTable<nil, Key, Hash>(hs)
{}
//- Construct by transferring the parameter contents
HashSet(const Xfer<HashSet<Key, Hash> >& hs)
:
HashTable<nil, Key, Hash>(hs)
{}
//- Construct by transferring the parameter contents
HashSet(const Xfer<HashTable<nil, Key, Hash> >& hs)
:
HashTable<nil, Key, Hash>(hs)
{}
//- Construct from the keys of another HashTable,
// the type of values held is arbitrary.
template<class AnyType, class AnyHash>
HashSet(const HashTable<AnyType, Key, AnyHash>&);
// Member Functions
// Edit
//- Insert a new hashedEntry
bool insert(const Key& key)
{
return HashTable<empty, Key, Hash>::insert(key, empty());
}
//- Insert a new entry
bool insert(const Key& key)
{
return HashTable<nil, Key, Hash>::insert(key, nil());
}
//- Same as insert (cannot overwrite nil content)
bool set(const Key& key)
{
return HashTable<nil, Key, Hash>::insert(key, nil());
}
// Member Operators
//- Return true if the entry exists, same as found()
inline bool operator[](const Key&) const;
//- Equality. Two hashtables are equal when their contents are equal.
// Independent of table size or order.
bool operator==(const HashSet<Key, Hash>&) const;
//- The opposite of the equality operation.
bool operator!=(const HashSet<Key, Hash>&) const;
//- Combine entries from HashSets
void operator|=(const HashSet<Key, Hash>&);
//- Only retain entries found in both HashSets
void operator&=(const HashSet<Key, Hash>&);
//- Only retain unique entries (xor)
void operator^=(const HashSet<Key, Hash>&);
//- Add entries listed in the given HashSet to this HashSet
inline void operator+=(const HashSet<Key, Hash>& rhs)
{
this->operator|=(rhs);
}
//- Remove entries listed in the given HashSet from this HashSet
void operator-=(const HashSet<Key, Hash>&);
};
// Global Operators
//- Combine entries from HashSets
template<class Key, class Hash>
HashSet<Key,Hash> operator|
(
const HashSet<Key,Hash>& hash1,
const HashSet<Key,Hash>& hash2
);
//- Create a HashSet that only contains entries found in both HashSets
template<class Key, class Hash>
HashSet<Key,Hash> operator&
(
const HashSet<Key,Hash>& hash1,
const HashSet<Key,Hash>& hash2
);
//- Create a HashSet that only contains unique entries (xor)
template<class Key, class Hash>
HashSet<Key,Hash> operator^
(
const HashSet<Key,Hash>& hash1,
const HashSet<Key,Hash>& hash2
);
//- A HashSet with word keys.
typedef HashSet<> wordHashSet;
//- A HashSet with label keys.
typedef HashSet<label, Hash<label> > labelHashSet;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -112,6 +210,12 @@ typedef HashSet<> wordHashSet;
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#ifdef NoRepository
# include "HashSet.C"
#endif
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -30,40 +30,64 @@ License
#include "HashTable.H"
#include "List.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
namespace Foam
template<class T, class Key, class Hash>
Foam::label Foam::HashTable<T, Key, Hash>::canonicalSize(const label size)
{
if (size < 1)
{
return 0;
}
// enforce power of two
unsigned int goodSize = size;
if (goodSize & (goodSize - 1))
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
}
return goodSize;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
HashTable<T, Key, Hash>::HashTable(const label size)
Foam::HashTable<T, Key, Hash>::HashTable(const label size)
:
tableSize_(size),
table_(NULL),
HashTableName(),
nElmts_(0),
tableSize_(canonicalSize(size)),
table_(NULL),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
if (tableSize_)
{
table_ = new hashedEntry*[tableSize_];
for (label i=0; i<tableSize_; i++)
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[i] = 0;
table_[hashIdx] = 0;
}
}
}
template<class T, class Key, class Hash>
HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
Foam::HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
:
HashTableName(),
nElmts_(0),
tableSize_(ht.tableSize_),
table_(NULL),
nElmts_(0),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
@ -71,23 +95,39 @@ HashTable<T, Key, Hash>::HashTable(const HashTable<T, Key, Hash>& ht)
{
table_ = new hashedEntry*[tableSize_];
for (label i=0; i<tableSize_; i++)
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[i] = 0;
table_[hashIdx] = 0;
}
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
for (const_iterator iter = ht.cbegin(); iter != ht.cend(); ++iter)
{
insert(iter.key(), *iter);
}
}
}
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable
(
const Xfer<HashTable<T, Key, Hash> >& ht
)
:
HashTableName(),
nElmts_(0),
tableSize_(0),
table_(NULL),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
transfer(ht());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
HashTable<T, Key, Hash>::~HashTable()
Foam::HashTable<T, Key, Hash>::~HashTable()
{
if (table_)
{
@ -100,15 +140,18 @@ HashTable<T, Key, Hash>::~HashTable()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
bool HashTable<T, Key, Hash>::found(const Key& key) const
bool Foam::HashTable<T, Key, Hash>::found(const Key& key) const
{
if (tableSize_)
if (nElmts_)
{
label ii = Hash()(key, tableSize_);
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* n=table_[ii]; n; n=n->next_)
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == n->key_) return true;
if (key == ep->key_)
{
return true;
}
}
}
@ -125,20 +168,22 @@ bool HashTable<T, Key, Hash>::found(const Key& key) const
template<class T, class Key, class Hash>
typename HashTable<T, Key, Hash>::iterator HashTable<T, Key, Hash>::find
typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::find
(
const Key& key
)
{
if (tableSize_)
if (nElmts_)
{
label ii = Hash()(key, tableSize_);
hashedEntry* prev = 0;
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* n=table_[ii]; n; n=n->next_)
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == n->key_) return iterator(*this, n, ii);
prev = n;
if (key == ep->key_)
{
return iterator(*this, ep, hashIdx);
}
}
}
@ -155,20 +200,22 @@ typename HashTable<T, Key, Hash>::iterator HashTable<T, Key, Hash>::find
template<class T, class Key, class Hash>
typename HashTable<T, Key, Hash>::const_iterator HashTable<T, Key, Hash>::find
typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::find
(
const Key& key
) const
{
if (tableSize_)
if (nElmts_)
{
label ii = Hash()(key, tableSize_);
hashedEntry* prev = 0;
const label hashIdx = hashKeyIndex(key);
for (hashedEntry* n=table_[ii]; n; n=n->next_)
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == n->key_) return const_iterator(*this, n, ii);
prev = n;
if (key == ep->key_)
{
return const_iterator(*this, ep, hashIdx);
}
}
}
@ -180,19 +227,18 @@ typename HashTable<T, Key, Hash>::const_iterator HashTable<T, Key, Hash>::find
}
# endif
return end();
return cend();
}
// Return the table of contents
template<class T, class Key, class Hash>
List<Key> HashTable<T, Key, Hash>::toc() const
Foam::List<Key> Foam::HashTable<T, Key, Hash>::toc() const
{
List<Key> tofc(nElmts_);
label i = 0;
for (const_iterator iter = begin(); iter != end(); ++iter)
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tofc[i++] = iter.key();
}
@ -202,36 +248,37 @@ List<Key> HashTable<T, Key, Hash>::toc() const
template<class T, class Key, class Hash>
bool HashTable<T, Key, Hash>::set
bool Foam::HashTable<T, Key, Hash>::set
(
const Key& key,
const T& newEntry,
const bool protect
)
{
if (tableSize_ == 0)
if (!tableSize_)
{
resize(2);
}
label ii = Hash()(key, tableSize_);
const label hashIdx = hashKeyIndex(key);
hashedEntry* existing = 0;
hashedEntry* prev = 0;
for (hashedEntry* curr = table_[ii]; curr; curr = curr->next_)
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
if (key == curr->key_)
if (key == ep->key_)
{
existing = curr;
existing = ep;
break;
}
prev = curr;
prev = ep;
}
// not found, insert it at the head
if (!existing)
{
table_[ii] = new hashedEntry(key, table_[ii], newEntry);
table_[hashIdx] = new hashedEntry(key, table_[hashIdx], newEntry);
nElmts_++;
if (double(nElmts_)/tableSize_ > 0.8)
@ -256,7 +303,7 @@ bool HashTable<T, Key, Hash>::set
if (debug)
{
Info<< "HashTable<T, Key, Hash>::set"
"(const Key& key, T newEntry, false) : "
"(const Key& key, T newEntry, true) : "
"Cannot insert " << key << " already in hash table\n";
}
# endif
@ -266,16 +313,16 @@ bool HashTable<T, Key, Hash>::set
{
// found - overwrite existing entry
// this corresponds to the Perl convention
hashedEntry* elemPtr = new hashedEntry(key, existing->next_, newEntry);
hashedEntry* ep = new hashedEntry(key, existing->next_, newEntry);
// replace existing element - within list or insert at the head
if (prev)
{
prev->next_ = elemPtr;
prev->next_ = ep;
}
else
{
table_[ii] = elemPtr;
table_[hashIdx] = ep;
}
delete existing;
@ -286,34 +333,34 @@ bool HashTable<T, Key, Hash>::set
template<class T, class Key, class Hash>
bool HashTable<T, Key, Hash>::erase(const iterator& cit)
bool Foam::HashTable<T, Key, Hash>::erase(const iterator& cit)
{
if (cit.elmtPtr_) // note: endIter_ also has 0 elmtPtr_
{
iterator& it = const_cast<iterator&>(cit);
// Search element before elmtPtr_
hashedEntry* prevElmtPtr = 0;
hashedEntry* prev = 0;
for (hashedEntry* n=table_[it.hashIndex_]; n; n=n->next_)
for (hashedEntry* ep = table_[it.hashIndex_]; ep; ep = ep->next_)
{
if (n == it.elmtPtr_)
if (ep == it.elmtPtr_)
{
break;
}
prevElmtPtr = n;
prev = ep;
}
if (prevElmtPtr)
if (prev)
{
// Have element before elmtPtr
prevElmtPtr->next_ = it.elmtPtr_->next_;
prev->next_ = it.elmtPtr_->next_;
delete it.elmtPtr_;
it.elmtPtr_ = prevElmtPtr;
it.elmtPtr_ = prev;
}
else
{
// elmtPtr is first element on SLlist
// elmtPtr is first element on SLList
table_[it.hashIndex_] = it.elmtPtr_->next_;
delete it.elmtPtr_;
@ -334,7 +381,7 @@ bool HashTable<T, Key, Hash>::erase(const iterator& cit)
else
{
// No previous found. Mark with special value which is
// - not end()
// - not end()/cend()
// - handled by operator++
it.elmtPtr_ = reinterpret_cast<hashedEntry*>(this);
it.hashIndex_ = -1;
@ -369,13 +416,13 @@ bool HashTable<T, Key, Hash>::erase(const iterator& cit)
template<class T, class Key, class Hash>
bool HashTable<T, Key, Hash>::erase(const Key& key)
bool Foam::HashTable<T, Key, Hash>::erase(const Key& key)
{
iterator it = find(key);
iterator fnd = find(key);
if (it != end())
if (fnd != end())
{
return erase(it);
return erase(fnd);
}
else
{
@ -385,14 +432,60 @@ bool HashTable<T, Key, Hash>::erase(const Key& key)
template<class T, class Key, class Hash>
void HashTable<T, Key, Hash>::resize(const label newSize)
Foam::label Foam::HashTable<T, Key, Hash>::erase(const UList<Key>& keys)
{
label count = 0;
// Remove listed keys from this table
if (this->size())
{
forAll(keys, keyI)
{
if (erase(keys[keyI]))
{
count++;
}
}
}
return count;
}
template<class T, class Key, class Hash>
template<class AnyType, class AnyHash>
Foam::label Foam::HashTable<T, Key, Hash>::erase
(
const HashTable<AnyType, Key, AnyHash>& rhs
)
{
label count = 0;
// Remove rhs keys from this table - terminates early if possible
// Could optimize depending on which hash is smaller ...
for (iterator iter = begin(); iter != end(); ++iter)
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = canonicalSize(sz);
if (newSize == tableSize_)
{
# ifdef FULLDEBUG
if (debug)
{
Info<< "HashTable<T, Key, Hash>::resize(const label newSize) : "
Info<< "HashTable<T, Key, Hash>::resize(const label) : "
<< "new table size == old table size\n";
}
# endif
@ -402,7 +495,7 @@ void HashTable<T, Key, Hash>::resize(const label newSize)
HashTable<T, Key, Hash>* newTable = new HashTable<T, Key, Hash>(newSize);
for (const_iterator iter = begin(); iter != end(); ++iter)
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
newTable->insert(iter.key(), *iter);
}
@ -420,22 +513,22 @@ void HashTable<T, Key, Hash>::resize(const label newSize)
template<class T, class Key, class Hash>
void HashTable<T, Key, Hash>::clear()
void Foam::HashTable<T, Key, Hash>::clear()
{
if (nElmts_)
{
for (label i=0; i<tableSize_; i++)
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
if (table_[i])
if (table_[hashIdx])
{
hashedEntry* n = table_[i];
while(hashedEntry* next = n->next_)
hashedEntry* ep = table_[hashIdx];
while (hashedEntry* next = ep->next_)
{
delete n;
n = next;
delete ep;
ep = next;
}
delete n;
table_[i] = 0;
delete ep;
table_[hashIdx] = 0;
}
}
nElmts_ = 0;
@ -444,10 +537,22 @@ void HashTable<T, Key, Hash>::clear()
template<class T, class Key, class Hash>
void HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
void Foam::HashTable<T, Key, Hash>::clearStorage()
{
clear();
delete[] table_;
resize(0);
}
template<class T, class Key, class Hash>
void Foam::HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
{
// as per the Destructor
if (table_)
{
clear();
delete[] table_;
}
tableSize_ = ht.tableSize_;
ht.tableSize_ = 0;
@ -463,10 +568,13 @@ void HashTable<T, Key, Hash>::transfer(HashTable<T, Key, Hash>& ht)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
void HashTable<T, Key, Hash>::operator=(const HashTable<T, Key, Hash>& ht)
void Foam::HashTable<T, Key, Hash>::operator=
(
const HashTable<T, Key, Hash>& rhs
)
{
// Check for assignment to self
if (this == &ht)
if (this == &rhs)
{
FatalErrorIn
(
@ -476,18 +584,63 @@ void HashTable<T, Key, Hash>::operator=(const HashTable<T, Key, Hash>& ht)
<< abort(FatalError);
}
clear();
// could be zero-sized from a previous transfer()
if (!tableSize_)
{
resize(rhs.tableSize_);
}
else
{
clear();
}
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
insert(iter.key(), *iter);
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::operator==
(
const HashTable<T, Key, Hash>& rhs
) const
{
// Are all my elements in rhs?
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
const_iterator fnd = rhs.find(iter.key());
if (fnd == rhs.cend() || fnd() != iter())
{
return false;
}
}
// Are all rhs elements in me?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
if (fnd == cend() || fnd() != iter())
{
return false;
}
}
return true;
}
template<class T, class Key, class Hash>
bool Foam::HashTable<T, Key, Hash>::operator!=
(
const HashTable<T, Key, Hash>& rhs
) const
{
return !(operator==(rhs));
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //

View file

@ -28,6 +28,13 @@ Class
Description
An STL-conforming hash table.
Note
Hashing index collisions are handled via chaining using a singly-linked
list with the colliding entry being added to the head of the linked
list. Thus copying the hash table (or indeed even resizing it) will
often result in a different hash order. Use a sorted table-of-contents
when the hash order is important.
SourceFiles
HashTableI.H
HashTable.C
@ -39,7 +46,9 @@ SourceFiles
#define HashTable_H
#include "label.H"
#include "uLabel.H"
#include "word.H"
#include "Xfer.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -49,22 +58,16 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T>
class List;
template<class T> class List;
template<class T> class UList;
template<class T, class Key, class Hash> class HashTable;
template<class T, class Key, class Hash> class HashPtrTable;
template<class T, class Key, class Hash> Istream& operator>>
(
Istream&,
HashTable<T, Key, Hash>&
);
template<class T, class Key, class Hash>
Istream& operator>>(Istream&, HashTable<T, Key, Hash>&);
template<class T, class Key, class Hash> Ostream& operator<<
(
Ostream&,
const HashTable<T, Key, Hash>&
);
template<class T, class Key, class Hash>
Ostream& operator<<(Ostream&, const HashTable<T, Key, Hash>&);
/*---------------------------------------------------------------------------*\
@ -101,7 +104,7 @@ class HashTable
//- Construct given key, next pointer and object
inline hashedEntry
(
const Key& key,
const Key&,
hashedEntry* next,
const T& newEntry
);
@ -113,20 +116,28 @@ class HashTable
// Private data: size of table, the table and current number of elements
//- The current number of elements in table
label nElmts_;
//- Number of primary entries allocated in table (not necessarily used)
label tableSize_;
//- The table of primary entries
hashedEntry** table_;
//- The current number of elements in table
label nElmts_;
// Private Member Functions
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Return the hash index of the Key within the current table size.
// No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const;
//- Assign a new hashedEntry to a possibly already existing key
bool set(const Key& key, const T& newElmt, bool protect);
bool set(const Key&, const T& newElmt, bool protect);
public:
@ -147,14 +158,17 @@ public:
// Constructors
//- Construct given initial table size
HashTable(const label size = 100);
HashTable(const label size = 128);
//- Construct from Istream
HashTable(Istream&, const label size = 100);
HashTable(Istream&, const label size = 128);
//- Construct as copy
HashTable(const HashTable<T, Key, Hash>&);
//- Construct by transferring the parameter contents
HashTable(const Xfer<HashTable<T, Key, Hash> >&);
// Destructor
@ -168,34 +182,50 @@ public:
//- Return number of elements in table.
inline label size() const;
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashedEntry is found in table
bool found(const Key& key) const;
bool found(const Key&) const;
//- Find and return an iterator set at the hashedEntry
// If not found iterator = end()
iterator find(const Key& key);
iterator find(const Key&);
//- Find and return an const_iterator set at the hashedEntry
// If not found iterator = end()
const_iterator find(const Key& key) const;
const_iterator find(const Key&) const;
//- Return the table of contents
List<Key> toc() const;
//- Print information
Ostream& printInfo(Ostream&) const;
// Edit
//- Insert a new hashedEntry
inline bool insert(const Key& key, const T& newElmt);
inline bool insert(const Key&, const T& newElmt);
//- Assign a new hashedEntry, overwriting existing entries
inline bool set(const Key& key, const T& newElmt);
inline bool set(const Key&, const T& newElmt);
//- Erase an hashedEntry specified by given iterator
bool erase(const iterator& it);
bool erase(const iterator&);
//- Erase an hashedEntry specified by given key if in table
bool erase(const Key& key);
bool erase(const Key&);
//- Remove entries given by the listed keys from this HashTable
// Return the number of elements removed
label erase(const UList<Key>&);
//- Remove entries given by the given keys from this HashTable
// Return the number of elements removed.
// The parameter HashTable needs the same type of key, but the
// type of values held and the hashing function are arbitrary.
template<class AnyType, class AnyHash>
label erase(const HashTable<AnyType, Key, AnyHash>&);
//- Resize the hash table for efficiency
void resize(const label newSize);
@ -203,26 +233,40 @@ public:
//- Clear all entries from table
void clear();
//- Clear the table entries and the table itself.
// Equivalent to clear() followed by resize(0)
void clearStorage();
//- Transfer the contents of the argument table into this table
// and annull the argument table.
void transfer(HashTable<T, Key, Hash>&);
//- Transfer contents to the Xfer container
inline Xfer<HashTable<T, Key, Hash> > xfer();
// Member Operators
//- Find and return an hashedEntry
inline T& operator[](const Key& key);
inline T& operator[](const Key&);
//- Find and return an hashedEntry
inline const T& operator[](const Key& key) const;
inline const T& operator[](const Key&) const;
//- Find and return an hashedEntry and
// if it is not present create it null.
inline T& operator()(const Key& key);
//- Find and return an hashedEntry, create it null if not present.
inline T& operator()(const Key&);
//- Assignment
void operator=(const HashTable<T, Key, Hash>&);
//- Equality. Two hash tables are equal if all contents of first are
// also in second and vice versa. So does not depend on table size or
// order!
bool operator==(const HashTable<T, Key, Hash>&) const;
//- The opposite of the equality operation. Takes linear time.
bool operator!=(const HashTable<T, Key, Hash>&) const;
// STL type definitions
@ -253,7 +297,7 @@ public:
// Private data
//- Reference to the HashTable this is an iterator for
HashTable<T, Key, Hash>& curHashTable_;
HashTable<T, Key, Hash>& hashTable_;
//- Current element
hashedEntry* elmtPtr_;
@ -261,7 +305,6 @@ public:
//- Current hash index
label hashIndex_;
public:
// Constructors
@ -274,24 +317,26 @@ public:
label hashIndex
);
// Member operators
inline void operator=(const iterator& iter);
inline void operator=(const iterator&);
inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator& iter) const;
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const const_iterator&) const;
inline T& operator*();
inline T& operator()();
inline const T& operator*() const;
inline const T& operator()() const;
inline iterator& operator++();
inline iterator operator++(int);
inline const Key& key();
inline const Key& key() const;
};
@ -312,7 +357,7 @@ public:
// Private data
//- Reference to the HashTable this is an iterator for
const HashTable<T, Key, Hash>& curHashTable_;
const HashTable<T, Key, Hash>& hashTable_;
//- Current element
const hashedEntry* elmtPtr_;
@ -339,24 +384,30 @@ public:
// Member operators
inline void operator=(const const_iterator& iter);
inline void operator=(const const_iterator&);
inline bool operator==(const const_iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const const_iterator&) const;
inline bool operator==(const iterator& iter) const;
inline bool operator!=(const iterator& iter) const;
inline bool operator==(const iterator&) const;
inline bool operator!=(const iterator&) const;
inline const T& operator*();
inline const T& operator()();
inline const T& operator*() const;
inline const T& operator()() const;
inline const_iterator& operator++();
inline const_iterator operator++(int);
inline const Key& key();
inline const Key& key() const;
};
//- const_iterator set to the beginning of the HashTable
inline const_iterator cbegin() const;
//- const_iterator set to beyond the end of the HashTable
inline const const_iterator& cend() const;
//- const_iterator set to the beginning of the HashTable
inline const_iterator begin() const;
@ -366,19 +417,13 @@ public:
// IOstream Operator
friend Istream& operator>>
#ifndef __CINT__
<T, Key, Hash>
#endif
friend Istream& operator>> <T, Key, Hash>
(
Istream&,
HashTable<T, Key, Hash>&
);
friend Ostream& operator<<
#ifndef __CINT__
<T, Key, Hash>
#endif
friend Ostream& operator<< <T, Key, Hash>
(
Ostream&,
const HashTable<T, Key, Hash>&

View file

@ -26,15 +26,10 @@ License
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline HashTable<T, Key, Hash>::hashedEntry::hashedEntry
inline Foam::HashTable<T, Key, Hash>::hashedEntry::hashedEntry
(
const Key& key,
hashedEntry* next,
@ -47,39 +42,74 @@ inline HashTable<T, Key, Hash>::hashedEntry::hashedEntry
{}
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label
Foam::HashTable<T, Key, Hash>::hashKeyIndex(const Key& key) const
{
// size is power of two - this is the modulus
return Hash()(key) & (tableSize_ - 1);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline label HashTable<T, Key, Hash>::size() const
inline Foam::label Foam::HashTable<T, Key, Hash>::size() const
{
return nElmts_;
}
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::insert(const Key& key, const T& newEntry)
inline bool Foam::HashTable<T, Key, Hash>::empty() const
{
return !nElmts_;
}
template<class T, class Key, class Hash>
inline bool Foam::HashTable<T, Key, Hash>::insert
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, true);
}
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::set(const Key& key, const T& newEntry)
inline bool Foam::HashTable<T, Key, Hash>::set
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, false);
}
template<class T, class Key, class Hash>
inline Foam::Xfer<Foam::HashTable<T, Key, Hash> >
Foam::HashTable<T, Key, Hash>::xfer()
{
return xferMove(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline T& HashTable<T, Key, Hash>::operator[](const Key& key)
inline T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key)
{
iterator iter = find(key);
if (iter == end())
{
FatalErrorIn("HashTable<T, Key, Hash>::operator[](const Key&)")
<< key << " not found in table. Valid entries are "
<< key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
@ -87,15 +117,16 @@ inline T& HashTable<T, Key, Hash>::operator[](const Key& key)
return *iter;
}
template<class T, class Key, class Hash>
inline const T& HashTable<T, Key, Hash>::operator[](const Key& key) const
inline const T& Foam::HashTable<T, Key, Hash>::operator[](const Key& key) const
{
const_iterator iter = find(key);
if (iter == end())
if (iter == cend())
{
FatalErrorIn("HashTable<T, Key, Hash>::operator[](const Key&) const")
<< key << " not found in table. Valid entries are "
<< key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
@ -105,7 +136,7 @@ inline const T& HashTable<T, Key, Hash>::operator[](const Key& key) const
template<class T, class Key, class Hash>
inline T& HashTable<T, Key, Hash>::operator()(const Key& key)
inline T& Foam::HashTable<T, Key, Hash>::operator()(const Key& key)
{
iterator iter = find(key);
@ -124,21 +155,24 @@ inline T& HashTable<T, Key, Hash>::operator()(const Key& key)
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline HashTable<T, Key, Hash>::iterator::iterator
inline Foam::HashTable<T, Key, Hash>::iterator::iterator
(
HashTable<T, Key, Hash>& curHashTable,
HashTable<T, Key, Hash>& hashTbl,
hashedEntry* elmt,
label hashIndex
)
:
curHashTable_(curHashTable),
hashTable_(hashTbl),
elmtPtr_(elmt),
hashIndex_(hashIndex)
{}
template<class T, class Key, class Hash>
inline void HashTable<T, Key, Hash>::iterator::operator=(const iterator& iter)
inline void Foam::HashTable<T, Key, Hash>::iterator::operator=
(
const iterator& iter
)
{
elmtPtr_ = iter.elmtPtr_;
hashIndex_ = iter.hashIndex_;
@ -146,7 +180,7 @@ inline void HashTable<T, Key, Hash>::iterator::operator=(const iterator& iter)
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::iterator::operator==
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator==
(
const iterator& iter
) const
@ -156,7 +190,7 @@ inline bool HashTable<T, Key, Hash>::iterator::operator==
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::iterator::operator!=
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator!=
(
const iterator& iter
) const
@ -166,7 +200,7 @@ inline bool HashTable<T, Key, Hash>::iterator::operator!=
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::iterator::operator==
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator==
(
const const_iterator& iter
) const
@ -176,7 +210,7 @@ inline bool HashTable<T, Key, Hash>::iterator::operator==
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::iterator::operator!=
inline bool Foam::HashTable<T, Key, Hash>::iterator::operator!=
(
const const_iterator& iter
) const
@ -186,28 +220,46 @@ inline bool HashTable<T, Key, Hash>::iterator::operator!=
template<class T, class Key, class Hash>
inline T& HashTable<T, Key, Hash>::iterator::operator*()
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator*()
{
return elmtPtr_->obj_;
}
template<class T, class Key, class Hash>
inline T& HashTable<T, Key, Hash>::iterator::operator()()
inline T&
Foam::HashTable<T, Key, Hash>::iterator::operator()()
{
return operator*();
return elmtPtr_->obj_;
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::iterator::operator*() const
{
return elmtPtr_->obj_;
}
template<class T, class Key, class Hash>
inline const T&
Foam::HashTable<T, Key, Hash>::iterator::operator()() const
{
return elmtPtr_->obj_;
}
template<class T, class Key, class Hash>
inline
typename HashTable<T, Key, Hash>::iterator&
HashTable<T, Key, Hash>::iterator::operator++()
typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::iterator::operator++()
{
// Check for special value from erase. (sets hashIndex to -1)
if (hashIndex_ >= 0)
{
// Do we have additional elements on the singly linked list?
// Do we have additional elements on the SLList?
if (elmtPtr_ && elmtPtr_->next_)
{
elmtPtr_ = elmtPtr_->next_;
@ -218,24 +270,24 @@ HashTable<T, Key, Hash>::iterator::operator++()
// Step to the next table entry
while
(
++hashIndex_ < curHashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_])
++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{}
if (hashIndex_ == curHashTable_.tableSize_)
if (hashIndex_ == hashTable_.tableSize_)
{
// make end iterator
hashIndex_ = 0;
elmtPtr_ = 0;
hashIndex_ = 0;
}
return *this;
}
template<class T, class Key, class Hash>
inline typename HashTable<T, Key, Hash>::iterator
HashTable<T, Key, Hash>::iterator::operator++
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::iterator::operator++
(
int
)
@ -248,20 +300,27 @@ HashTable<T, Key, Hash>::iterator::operator++
template<class T, class Key, class Hash>
inline
const Key& HashTable<T, Key, Hash>::iterator::key()
const Key& Foam::HashTable<T, Key, Hash>::iterator::key() const
{
return elmtPtr_->key_;
}
template<class T, class Key, class Hash>
inline typename HashTable<T, Key, Hash>::iterator
HashTable<T, Key, Hash>::begin()
inline typename Foam::HashTable<T, Key, Hash>::iterator
Foam::HashTable<T, Key, Hash>::begin()
{
label i = 0;
while (table_ && !table_[i] && ++i < tableSize_)
{}
if (nElmts_)
{
while (table_ && !table_[i] && ++i < tableSize_)
{}
}
else
{
i = tableSize_;
}
if (i == tableSize_)
{
@ -282,8 +341,8 @@ HashTable<T, Key, Hash>::begin()
template<class T, class Key, class Hash>
inline const typename HashTable<T, Key, Hash>::iterator&
HashTable<T, Key, Hash>::end()
inline const typename Foam::HashTable<T, Key, Hash>::iterator&
Foam::HashTable<T, Key, Hash>::end()
{
return HashTable<T, Key, Hash>::endIter_;
}
@ -292,33 +351,33 @@ HashTable<T, Key, Hash>::end()
// * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline HashTable<T, Key, Hash>::const_iterator::const_iterator
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const HashTable<T, Key, Hash>& curHashTable,
const HashTable<T, Key, Hash>& hashTbl,
const hashedEntry* elmt,
label hashIndex
)
:
curHashTable_(curHashTable),
hashTable_(hashTbl),
elmtPtr_(elmt),
hashIndex_(hashIndex)
{}
template<class T, class Key, class Hash>
inline HashTable<T, Key, Hash>::const_iterator::const_iterator
inline Foam::HashTable<T, Key, Hash>::const_iterator::const_iterator
(
const iterator& iter
)
:
curHashTable_(iter.curHashTable_),
hashTable_(iter.hashTable_),
elmtPtr_(iter.elmtPtr_),
hashIndex_(iter.hashIndex_)
{}
template<class T, class Key, class Hash>
inline void HashTable<T, Key, Hash>::const_iterator::operator=
inline void Foam::HashTable<T, Key, Hash>::const_iterator::operator=
(
const const_iterator& iter
)
@ -329,7 +388,7 @@ inline void HashTable<T, Key, Hash>::const_iterator::operator=
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::const_iterator::operator==
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator==
(
const const_iterator& iter
) const
@ -339,7 +398,7 @@ inline bool HashTable<T, Key, Hash>::const_iterator::operator==
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::const_iterator::operator!=
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator!=
(
const const_iterator& iter
) const
@ -349,7 +408,7 @@ inline bool HashTable<T, Key, Hash>::const_iterator::operator!=
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::const_iterator::operator==
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator==
(
const iterator& iter
) const
@ -359,7 +418,7 @@ inline bool HashTable<T, Key, Hash>::const_iterator::operator==
template<class T, class Key, class Hash>
inline bool HashTable<T, Key, Hash>::const_iterator::operator!=
inline bool Foam::HashTable<T, Key, Hash>::const_iterator::operator!=
(
const iterator& iter
) const
@ -369,35 +428,36 @@ inline bool HashTable<T, Key, Hash>::const_iterator::operator!=
template<class T, class Key, class Hash>
inline const T& HashTable<T, Key, Hash>::const_iterator::operator*()
inline const T&
Foam::HashTable<T, Key, Hash>::const_iterator::operator*() const
{
return elmtPtr_->obj_;
}
#ifndef __CINT__
template<class T, class Key, class Hash>
inline const T& HashTable<T, Key, Hash>::const_iterator::operator()()
inline const T&
Foam::HashTable<T, Key, Hash>::const_iterator::operator()() const
{
return operator*();
return elmtPtr_->obj_;
}
#endif
template<class T, class Key, class Hash>
inline
typename HashTable<T, Key, Hash>::const_iterator&
HashTable<T, Key, Hash>::const_iterator::operator++()
typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::const_iterator::operator++()
{
if
(
!(elmtPtr_ = elmtPtr_->next_)
&& ++hashIndex_ < curHashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_])
&& ++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{
while
(
++hashIndex_ < curHashTable_.tableSize_
&& !(elmtPtr_ = curHashTable_.table_[hashIndex_])
++hashIndex_ < hashTable_.tableSize_
&& !(elmtPtr_ = hashTable_.table_[hashIndex_])
)
{}
}
@ -407,8 +467,8 @@ HashTable<T, Key, Hash>::const_iterator::operator++()
template<class T, class Key, class Hash>
inline typename HashTable<T, Key, Hash>::const_iterator
HashTable<T, Key, Hash>::const_iterator::operator++
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::const_iterator::operator++
(
int
)
@ -421,20 +481,27 @@ HashTable<T, Key, Hash>::const_iterator::operator++
template<class T, class Key, class Hash>
inline
const Key& HashTable<T, Key, Hash>::const_iterator::key()
const Key& Foam::HashTable<T, Key, Hash>::const_iterator::key() const
{
return elmtPtr_->key_;
}
template<class T, class Key, class Hash>
inline typename HashTable<T, Key, Hash>::const_iterator
HashTable<T, Key, Hash>::begin() const
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::cbegin() const
{
label i = 0;
while (table_ && !table_[i] && ++i < tableSize_)
{}
if (nElmts_)
{
while (table_ && !table_[i] && ++i < tableSize_)
{}
}
else
{
i = tableSize_;
}
if (i == tableSize_)
{
@ -455,15 +522,27 @@ HashTable<T, Key, Hash>::begin() const
template<class T, class Key, class Hash>
inline const typename HashTable<T, Key, Hash>::const_iterator&
HashTable<T, Key, Hash>::end() const
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::cend() const
{
return HashTable<T, Key, Hash>::endConstIter_;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline typename Foam::HashTable<T, Key, Hash>::const_iterator
Foam::HashTable<T, Key, Hash>::begin() const
{
return this->cbegin();
}
template<class T, class Key, class Hash>
inline const typename Foam::HashTable<T, Key, Hash>::const_iterator&
Foam::HashTable<T, Key, Hash>::end() const
{
return HashTable<T, Key, Hash>::endConstIter_;
}
} // End namespace Foam
// ************************************************************************* //

View file

@ -33,38 +33,82 @@ License
template<class T, class Key, class Hash>
Foam::HashTable<T, Key, Hash>::HashTable(Istream& is, const label size)
:
tableSize_(size),
table_(new hashedEntry*[tableSize_]),
HashTableName(),
nElmts_(0),
tableSize_(canonicalSize(size)),
table_(new hashedEntry*[tableSize_]),
endIter_(*this, NULL, 0),
endConstIter_(*this, NULL, 0)
{
for (label i=0; i<tableSize_; i++)
for (label hashIdx = 0; hashIdx < tableSize_; hashIdx++)
{
table_[i] = 0;
table_[hashIdx] = 0;
}
operator>>(is, *this);
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Ostream&
Foam::HashTable<T, Key, Hash>::printInfo(Ostream& os) const
{
label used = 0;
label maxChain = 0;
unsigned avgChain = 0;
for (label hashIdx = 0; hashIdx < tableSize_; ++hashIdx)
{
label count = 0;
for (hashedEntry* ep = table_[hashIdx]; ep; ep = ep->next_)
{
++count;
}
if (count)
{
++used;
avgChain += count;
if (maxChain < count)
{
maxChain = count;
}
}
}
os << "HashTable<T,Key,Hash>"
<< " elements:" << size() << " slots:" << used << "/" << tableSize_
<< " chaining(avg/max):" << (used ? (float(avgChain)/used) : 0)
<< "/" << maxChain << endl;
return os;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
Foam::Istream& Foam::operator>>
(
Istream& is,
HashTable<T, Key, Hash>& L
)
{
is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)");
// Anull list
L.clear();
is.fatalCheck("operator>>(Istream& is, HashTable<T, Key, Hash>& L)");
is.fatalCheck("operator>>(Istream&, HashTable<T, Key, Hash>&)");
token firstToken(is);
is.fatalCheck
(
"operator>>(Istream& is, HashTable<T, Key, Hash>& L) : "
"operator>>(Istream&, HashTable<T, Key, Hash>&) : "
"reading first token"
);
@ -73,7 +117,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
label s = firstToken.labelToken();
// Read beginning of contents
char listDelimiter = is.readBeginList("HashTable<T, Key, Hash>");
char delimiter = is.readBeginList("HashTable<T, Key, Hash>");
if (s)
{
@ -82,7 +126,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
L.resize(2*s);
}
if (listDelimiter == token::BEGIN_LIST)
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
{
@ -101,7 +145,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, HashTable<T, Key, Hash>& L)",
"operator>>(Istream&, HashTable<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
@ -117,7 +161,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, HashTable<T, Key, Hash>& L)",
"operator>>(Istream&, HashTable<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
@ -133,10 +177,13 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
)
{
is.putBack(lastToken);
Key key;
is >> key;
T element;
is >> element;
L.insert(key, element);
is.fatalCheck
@ -152,7 +199,7 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, HashTable<T, Key, Hash>& L)",
"operator>>(Istream&, HashTable<T, Key, Hash>&)",
is
) << "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
@ -166,26 +213,27 @@ Foam::Istream& Foam::operator>>(Istream& is, HashTable<T, Key, Hash>& L)
template<class T, class Key, class Hash>
Foam::Ostream& Foam::operator<<(Ostream& os, const HashTable<T, Key, Hash>& L)
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const HashTable<T, Key, Hash>& L
)
{
// Write size of HashTable
os << nl << L.size();
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write HashTable contents
// Write contents
for
(
typename HashTable<T, Key, Hash>::const_iterator iter = L.begin();
iter != L.end();
typename HashTable<T, Key, Hash>::const_iterator iter = L.cbegin();
iter != L.cend();
++iter
)
{
os << iter.key() << token::SPACE << iter() << nl;
}
// Write end of contents
// Write end delimiter
os << token::END_LIST;
// Check state of IOstream

View file

@ -55,10 +55,15 @@ class Map
public:
typedef typename HashTable<T, label, Hash<label> >::iterator iterator;
typedef typename HashTable<T, label, Hash<label> >::const_iterator
const_iterator;
// Constructors
//- Construct given initial map size
Map(label size = 100)
//- Construct given initial size
Map(const label size = 128)
:
HashTable<T, label, Hash<label> >(size)
{}
@ -74,6 +79,19 @@ public:
:
HashTable<T, label, Hash<label> >(map)
{}
//- Construct by transferring the parameter contents
Map(const Xfer<Map<T> >& map)
:
HashTable<T, label, Hash<label> >(map)
{}
//- Construct by transferring the parameter contents
Map(const Xfer<HashTable<T, label, Hash<label> > >& map)
:
HashTable<T, label, Hash<label> >(map)
{}
};

View file

@ -58,7 +58,7 @@ public:
// Constructors
//- Construct given initial map size
PtrMap(label size = 100)
PtrMap(const label size = 128)
:
HashPtrTable<T, label, Hash<label> >(size)
{}

View file

@ -31,20 +31,42 @@ License
#include "List.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
namespace Foam
template<class T, class Key, class Hash>
Foam::label Foam::StaticHashTable<T, Key, Hash>::canonicalSize(const label size)
{
if (size < 1)
{
return 0;
}
// enforce power of two
unsigned int goodSize = size;
if (goodSize & (goodSize - 1))
{
// brute-force is fast enough
goodSize = 1;
while (goodSize < unsigned(size))
{
goodSize <<= 1;
}
}
return goodSize;
}
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct given initial table size
template<class T, class Key, class Hash>
StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)
:
StaticHashTableName(),
keys_(size),
objects_(size),
keys_(canonicalSize(size)),
objects_(keys_.size()),
nElmts_(0),
endIter_(*this, keys_.size(), 0),
endConstIter_(*this, keys_.size(), 0)
@ -62,7 +84,7 @@ StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)
// Construct as copy
template<class T, class Key, class Hash>
StaticHashTable<T, Key, Hash>::StaticHashTable
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
(
const StaticHashTable<T, Key, Hash>& ht
)
@ -76,34 +98,54 @@ StaticHashTable<T, Key, Hash>::StaticHashTable
{}
template<class T, class Key, class Hash>
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
(
const Xfer< StaticHashTable<T, Key, Hash> >& ht
)
:
StaticHashTableName(),
keys_(0),
objects_(0),
nElmts_(0),
endIter_(*this, 0, 0),
endConstIter_(*this, 0, 0)
{
transfer(ht());
}
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
StaticHashTable<T, Key, Hash>::~StaticHashTable()
Foam::StaticHashTable<T, Key, Hash>::~StaticHashTable()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
bool StaticHashTable<T, Key, Hash>::found(const Key& key) const
bool Foam::StaticHashTable<T, Key, Hash>::found(const Key& key) const
{
label ii = Hash()(key, keys_.size());
const List<Key>& localKeys = keys_[ii];
forAll(localKeys, n)
if (nElmts_)
{
if (localKeys[n] == key)
const label hashIdx = hashKeyIndex(key);
const List<Key>& localKeys = keys_[hashIdx];
forAll(localKeys, elemIdx)
{
return true;
if (key == localKeys[elemIdx])
{
return true;
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::found(const Key& key) : "
Info<< "StaticHashTable<T, Key, Hash>::found(const Key&) : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
@ -113,28 +155,30 @@ bool StaticHashTable<T, Key, Hash>::found(const Key& key) const
template<class T, class Key, class Hash>
typename StaticHashTable<T, Key, Hash>::iterator
StaticHashTable<T, Key, Hash>::find
typename Foam::StaticHashTable<T, Key, Hash>::iterator
Foam::StaticHashTable<T, Key, Hash>::find
(
const Key& key
)
{
label ii = Hash()(key, keys_.size());
const List<Key>& localKeys = keys_[ii];
forAll(localKeys, n)
if (nElmts_)
{
if (localKeys[n] == key)
const label hashIdx = hashKeyIndex(key);
const List<Key>& localKeys = keys_[hashIdx];
forAll(localKeys, elemIdx)
{
return iterator(*this, ii, n);
if (key == localKeys[elemIdx])
{
return iterator(*this, hashIdx, elemIdx);
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::find(const Key& key) : "
Info<< "StaticHashTable<T, Key, Hash>::find(const Key&) : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
@ -144,45 +188,46 @@ StaticHashTable<T, Key, Hash>::find
template<class T, class Key, class Hash>
typename StaticHashTable<T, Key, Hash>::const_iterator
StaticHashTable<T, Key, Hash>::find
typename Foam::StaticHashTable<T, Key, Hash>::const_iterator
Foam::StaticHashTable<T, Key, Hash>::find
(
const Key& key
) const
{
label ii = Hash()(key, keys_.size());
const List<Key>& localKeys = keys_[ii];
forAll(localKeys, n)
if (nElmts_)
{
if (localKeys[n] == key)
const label hashIdx = hashKeyIndex(key);
const List<Key>& localKeys = keys_[hashIdx];
forAll(localKeys, elemIdx)
{
return const_iterator(*this, ii, n);
if (key == localKeys[elemIdx])
{
return const_iterator(*this, hashIdx, elemIdx);
}
}
}
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::find(const Key& key) const : "
Info<< "StaticHashTable<T, Key, Hash>::find(const Key&) const : "
<< "Entry " << key << " not found in hash table\n";
}
# endif
return end();
return cend();
}
// Return the table of contents
template<class T, class Key, class Hash>
List<Key> StaticHashTable<T, Key, Hash>::toc() const
Foam::List<Key> Foam::StaticHashTable<T, Key, Hash>::toc() const
{
List<Key> tofc(nElmts_);
label i = 0;
for (const_iterator iter = begin(); iter != end(); ++iter)
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
tofc[i++] = iter.key();
}
@ -192,57 +237,74 @@ List<Key> StaticHashTable<T, Key, Hash>::toc() const
template<class T, class Key, class Hash>
bool StaticHashTable<T, Key, Hash>::insert(const Key& key, const T& newEntry)
bool Foam::StaticHashTable<T, Key, Hash>::set
(
const Key& key,
const T& newEntry,
const bool protect
)
{
label ii = Hash()(key, keys_.size());
const label hashIdx = hashKeyIndex(key);
List<Key>& localKeys = keys_[hashIdx];
List<Key>& localKeys = keys_[ii];
forAll(localKeys, n)
label existing = localKeys.size();
forAll(localKeys, elemIdx)
{
if (localKeys[n] == key)
if (key == localKeys[elemIdx])
{
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::insert"
"(const Key& key, T newEntry) : "
"Cannot insert " << key << " already in hash table\n";
}
# endif
return false;
existing = elemIdx;
break;
}
}
if (existing == localKeys.size())
{
// not found, append
List<T>& localObjects = objects_[hashIdx];
// Append.
List<T>& localObjects = objects_[ii];
localKeys.setSize(existing+1);
localObjects.setSize(existing+1);
label sz = localKeys.size();
localKeys[existing] = key;
localObjects[existing] = newEntry;
localKeys.setSize(sz+1);
localObjects.setSize(sz+1);
localKeys[sz] = key;
localObjects[sz] = newEntry;
nElmts_++;
nElmts_++;
}
else if (protect)
{
// found - but protected from overwriting
// this corresponds to the STL 'insert' convention
# ifdef FULLDEBUG
if (debug)
{
Info<< "StaticHashTable<T, Key, Hash>::set"
"(const Key& key, T newEntry, true) : "
"Cannot insert " << key << " already in hash table\n";
}
# endif
return false;
}
else
{
// found - overwrite existing entry
// this corresponds to the Perl convention
objects_[hashIdx][existing] = newEntry;
}
return true;
}
template<class T, class Key, class Hash>
bool StaticHashTable<T, Key, Hash>::erase(const iterator& it)
bool Foam::StaticHashTable<T, Key, Hash>::erase(const iterator& cit)
{
if (it != end())
if (cit != end())
{
List<Key>& localKeys = keys_[it.hashIndex_];
List<T>& localObjects = objects_[it.hashIndex_];
List<Key>& localKeys = keys_[cit.hashIndex_];
List<T>& localObjects = objects_[cit.hashIndex_];
// Copy down
for (label i = it.elementIndex_+1; i < localKeys.size(); i++)
for (label i = cit.elemIndex_+1; i < localKeys.size(); i++)
{
localKeys[i-1] = localKeys[i];
localObjects[i-1] = localObjects[i];
@ -250,12 +312,39 @@ bool StaticHashTable<T, Key, Hash>::erase(const iterator& it)
localKeys.setSize(localKeys.size()-1);
localObjects.setSize(localObjects.size()-1);
// adjust iterator after erase
iterator& it = const_cast<iterator&>(cit);
it.elemIndex_--;
if (it.elemIndex_ < 0)
{
// No previous element in the local list
// Search back for previous non-zero table entry
while (--it.hashIndex_ >= 0 && !objects_[it.hashIndex_].size())
{}
if (it.hashIndex_ >= 0)
{
// The last element in the local list
it.elemIndex_ = objects_[it.hashIndex_].size() - 1;
}
else
{
// No previous found. Mark with special value which is
// - not end()
// - handled by operator++
it.hashIndex_ = -1;
it.elemIndex_ = 0;
}
}
nElmts_--;
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::erase(iterator&) : "
Info<< "StaticHashTable<T, Key, Hash>::erase(iterator&) : "
<< "hashedEntry removed.\n";
}
# endif
@ -267,7 +356,7 @@ bool StaticHashTable<T, Key, Hash>::erase(const iterator& it)
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::erase(iterator&) : "
Info<< "StaticHashTable<T, Key, Hash>::erase(iterator&) : "
<< "cannot remove hashedEntry from hash table\n";
}
# endif
@ -278,7 +367,7 @@ bool StaticHashTable<T, Key, Hash>::erase(const iterator& it)
template<class T, class Key, class Hash>
bool StaticHashTable<T, Key, Hash>::erase(const Key& key)
bool Foam::StaticHashTable<T, Key, Hash>::erase(const Key& key)
{
iterator it = find(key);
@ -294,14 +383,38 @@ bool StaticHashTable<T, Key, Hash>::erase(const Key& key)
template<class T, class Key, class Hash>
void StaticHashTable<T, Key, Hash>::resize(const label newSize)
Foam::label Foam::StaticHashTable<T, Key, Hash>::erase
(
const StaticHashTable<T, Key, Hash>& rhs
)
{
label count = 0;
// Remove rhs elements from this table
// NOTE: could optimize depending on which hash is smaller
for (iterator iter = this->begin(); iter != this->end(); ++iter)
{
if (rhs.found(iter.key()) && erase(iter))
{
count++;
}
}
return count;
}
template<class T, class Key, class Hash>
void Foam::StaticHashTable<T, Key, Hash>::resize(const label sz)
{
label newSize = canonicalSize(sz);
if (newSize == keys_.size())
{
# ifdef FULLDEBUG
if (debug)
{
Pout<< "StaticHashTable<T, Key, Hash>::resize(const label) : "
Info<< "StaticHashTable<T, Key, Hash>::resize(const label) : "
<< "new table size == old table size\n";
}
# endif
@ -313,7 +426,7 @@ void StaticHashTable<T, Key, Hash>::resize(const label newSize)
{
FatalErrorIn
(
"StaticHashTable<T, Key, Hash>::StaticHashTable(const label size)"
"StaticHashTable<T, Key, Hash>::resize(const label)"
) << "Illegal size " << newSize << " for StaticHashTable."
<< " Minimum size is 1" << abort(FatalError);
}
@ -321,7 +434,7 @@ void StaticHashTable<T, Key, Hash>::resize(const label newSize)
StaticHashTable<T, Key, Hash> newTable(newSize);
for (iterator iter = begin(); iter != end(); ++iter)
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
newTable.insert(iter.key(), *iter);
}
@ -335,46 +448,62 @@ void StaticHashTable<T, Key, Hash>::resize(const label newSize)
template<class T, class Key, class Hash>
void StaticHashTable<T, Key, Hash>::clear()
void Foam::StaticHashTable<T, Key, Hash>::clear()
{
forAll(keys_, ii)
forAll(keys_, hashIdx)
{
keys_[ii].clear();
objects_[ii].clear();
keys_[hashIdx].clear();
objects_[hashIdx].clear();
}
nElmts_ = 0;
}
template<class T, class Key, class Hash>
void StaticHashTable<T, Key, Hash>::transfer(StaticHashTable<T, Key, Hash>& ht)
void Foam::StaticHashTable<T, Key, Hash>::clearStorage()
{
// Remove my existing elements
clear();
resize(1);
}
template<class T, class Key, class Hash>
void Foam::StaticHashTable<T, Key, Hash>::transfer
(
StaticHashTable<T, Key, Hash>& ht
)
{
// Remove existing elements
clear();
// Copy data from ht
keys_.transfer(ht.keys_);
objects_.transfer(ht.objects_);
nElmts_ = ht.nElmts_;
ht.nElmts_ = 0;
// Adapt end() iterators
endIter_.hashIndex_ = keys_.size();
endConstIter_.hashIndex_ = keys_.size();
// Clear ht
ht.nElmts_ = 0;
ht.endIter_.hashIndex_ = 0;
ht.endConstIter_.hashIndex_ = 0;
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
void StaticHashTable<T, Key, Hash>::operator=
void Foam::StaticHashTable<T, Key, Hash>::operator=
(
const StaticHashTable<T, Key, Hash>& ht
const StaticHashTable<T, Key, Hash>& rhs
)
{
// Check for assignment to self
if (this == &ht)
if (this == &rhs)
{
FatalErrorIn
(
@ -384,20 +513,70 @@ void StaticHashTable<T, Key, Hash>::operator=
<< abort(FatalError);
}
clear();
for (const_iterator iter = ht.begin(); iter != ht.end(); ++iter)
// keys could be empty from a previous transfer()
if (keys_.empty())
{
keys_.setSize(rhs.keys_.size());
objects_.setSize(keys_.size());
// Adapt end() iterators
endIter_.hashIndex_ = keys_.size();
endConstIter_.hashIndex_ = keys_.size();
}
else
{
clear();
// keys_.size() does not change so neither does end() iterator.
}
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
insert(iter.key(), *iter);
}
}
// keys_.size() does not change so neither does end() iterator.
template<class T, class Key, class Hash>
bool Foam::StaticHashTable<T, Key, Hash>::operator==
(
const StaticHashTable<T, Key, Hash>& rhs
) const
{
// Are all my elements in rhs?
for (const_iterator iter = cbegin(); iter != cend(); ++iter)
{
const_iterator fnd = rhs.find(iter.key());
if (fnd == rhs.cend() || fnd() != iter())
{
return false;
}
}
// Are all rhs elements in me?
for (const_iterator iter = rhs.cbegin(); iter != rhs.cend(); ++iter)
{
const_iterator fnd = find(iter.key());
if (fnd == cend() || fnd() != iter())
{
return false;
}
}
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
bool Foam::StaticHashTable<T, Key, Hash>::operator!=
(
const StaticHashTable<T, Key, Hash>& rhs
) const
{
return !(operator==(rhs));
}
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //

View file

@ -28,10 +28,10 @@ Class
Description
STL conforming hash table.
Note
Uses straight lists as underlying type.
Is slower to insert than the standard HashTable, but should be more
memory efficient and faster to access.
Explicitly does not have default size.
SourceFiles
StaticHashTableI.H
@ -44,7 +44,9 @@ SourceFiles
#define StaticHashTable_H
#include "label.H"
#include "uLabel.H"
#include "word.H"
#include "Xfer.H"
#include "className.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -54,9 +56,7 @@ namespace Foam
// Forward declaration of friend functions and operators
template<class T>
class List;
template<class T> class List;
template<class T, class Key, class Hash> class StaticHashTable;
template<class T, class Key, class Hash> Istream& operator>>
@ -73,14 +73,14 @@ template<class T, class Key, class Hash> Ostream& operator<<
/*---------------------------------------------------------------------------*\
Class StaticHashTableName Declaration
Class StaticHashTableName Declaration
\*---------------------------------------------------------------------------*/
TemplateName(StaticHashTable);
/*---------------------------------------------------------------------------*\
Class StaticHashTable Declaration
Class StaticHashTable Declaration
\*---------------------------------------------------------------------------*/
template<class T, class Key=word, class Hash=string::hash>
@ -99,6 +99,16 @@ class StaticHashTable
//- The current number of elements in table
label nElmts_;
//- Return a canonical (power-of-two) size
static label canonicalSize(const label);
//- Return the hash index of the Key within the current table size.
// No checks for zero-sized tables.
inline label hashKeyIndex(const Key&) const;
//- Assign a new hashed entry to a possibly already existing key
bool set(const Key&, const T& newElmt, bool protect);
public:
@ -138,14 +148,16 @@ public:
// Constructors
//- Construct given initial table size
StaticHashTable(const label size = 100);
StaticHashTable(const label size = 128);
//- Construct from Istream
StaticHashTable(Istream&, const label size = 100);
StaticHashTable(Istream&, const label size = 128);
//- Construct as copy
StaticHashTable(const StaticHashTable<T, Key, Hash>&);
//- Construct by transferring the parameter contents
StaticHashTable(const Xfer< StaticHashTable<T, Key, Hash> >&);
// Destructor
@ -159,54 +171,83 @@ public:
//- Return number of elements in table.
inline label size() const;
//- Return true if hashedEntry is found in table
//- Return true if the hash table is empty
inline bool empty() const;
//- Return true if hashed entry is found in table
bool found(const Key& key) const;
//- Find and return an iterator set at the hashedEntry
//- Find and return an iterator set at the hashed entry
// If not found iterator = end()
iterator find(const Key& key);
//- Find and return an const_iterator set at the hashedEntry
//- Find and return an const_iterator set at the hashed entry
// If not found iterator = end()
const_iterator find(const Key& key) const;
//- Return the table of contents
List<Key> toc() const;
//- Print information
Ostream& printInfo(Ostream&) const;
// Edit
//- Insert a new hashedEntry
//- Insert a new hashed entry
bool insert(const Key& key, const T& newElmt);
//- Erase an hashedEntry specified by given iterator
//- Assign a new hashed entry, overwriting existing entries
inline bool set(const Key&, const T& newElmt);
//- Erase an hashed entry specified by given iterator
bool erase(const iterator& it);
//- Erase an hashedEntry specified by given key if in table
//- Erase an hashed entry specified by given key if in table
bool erase(const Key& key);
//- Resize the hash table for efficiency
void resize(const label newSize);
//- Remove entries in the given hash table from this hash table
// Return the number of elements removed
label erase(const StaticHashTable<T, Key, Hash>&);
//- Clear all entries from table
void clear();
//- Clear the table entries and the table itself.
// Equivalent to clear() followed by resize(1)
void clearStorage();
//- Transfer the contents of the argument table into this table
// and annull the argument table.
void transfer(StaticHashTable<T, Key, Hash>&);
//- Transfer contents to the Xfer container
inline Xfer< StaticHashTable<T, Key, Hash> > xfer();
// Member Operators
//- Find and return an hashedEntry
inline T& operator[](const Key& key);
//- Find and return an hashed entry
inline T& operator[](const Key&);
//- Find and return an hashedEntry
inline const T& operator[](const Key& key) const;
//- Find and return an hashed entry
inline const T& operator[](const Key&) const;
//- Find and return an hashed entry, create it null if not present.
inline T& operator()(const Key&);
//- Assignment
void operator=(const StaticHashTable<T, Key, Hash>&);
//- Equality. Two hash tables are equal if all contents of first are
// also in second and vice versa.
bool operator==(const StaticHashTable<T, Key, Hash>&) const;
//- The opposite of the equality operation.
bool operator!=(const StaticHashTable<T, Key, Hash>&) const;
// STL type definitions
@ -242,24 +283,24 @@ public:
// Private data
//- Reference to the StaticHashTable this is an iterator for
TableRef curStaticHashTable_;
TableRef hashTable_;
//- Current hash index
label hashIndex_;
//- Index of current element at hashIndex
label elementIndex_;
label elemIndex_;
public:
// Constructors
//- Construct from hash table, element and hash index
//- Construct from hash table, hash index and element index
inline Iterator
(
TableRef curStaticHashTable,
TableRef,
label hashIndex_,
label elementIndex_
label elemIndex_
);
//- Construct from the non-const iterator
@ -268,13 +309,13 @@ public:
// Member operators
inline void operator=(const iterator& iter);
inline void operator=(const iterator&);
inline bool operator==(const iterator& iter) const;
inline bool operator==(const const_iterator& iter) const;
inline bool operator==(const iterator&) const;
inline bool operator==(const const_iterator&) const;
inline bool operator!=(const iterator& iter) const;
inline bool operator!=(const const_iterator& iter) const;
inline bool operator!=(const iterator&) const;
inline bool operator!=(const const_iterator&) const;
inline TRef operator*();
inline TRef operator()();
@ -282,23 +323,28 @@ public:
inline Iterator& operator++();
inline Iterator operator++(int);
inline const Key& key();
inline const Key& key() const;
};
//- iterator set to the begining of the StaticHashTable
//- iterator set to the beginning of the StaticHashTable
inline iterator begin();
//- iterator set to beyond the end of the StaticHashTable
inline const iterator& end();
//- const_iterator set to the begining of the StaticHashTable
//- const_iterator set to the beginning of the StaticHashTable
inline const_iterator cbegin() const;
//- const_iterator set to beyond the end of the StaticHashTable
inline const const_iterator& cend() const;
//- const_iterator set to the beginning of the StaticHashTable
inline const_iterator begin() const;
//- const_iterator set to beyond the end of the StaticHashTable
inline const const_iterator& end() const;
// IOstream Operator
friend Istream& operator>> <T, Key, Hash>

View file

@ -27,34 +27,76 @@ License
#include "error.H"
#include "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * Private Member Classes * * * * * * * * * * * * //
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline Foam::label
Foam::StaticHashTable<T, Key, Hash>::hashKeyIndex(const Key& key) const
{
// size is power of two - this is the modulus
return Hash()(key) & (keys_.size() - 1);
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline label StaticHashTable<T, Key, Hash>::size() const
inline Foam::label Foam::StaticHashTable<T, Key, Hash>::size() const
{
return nElmts_;
}
template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::empty() const
{
return !nElmts_;
}
template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::insert
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, true);
}
template<class T, class Key, class Hash>
inline bool Foam::StaticHashTable<T, Key, Hash>::set
(
const Key& key,
const T& newEntry
)
{
return set(key, newEntry, false);
}
template<class T, class Key, class Hash>
inline Foam::Xfer< Foam::StaticHashTable<T, Key, Hash> >
Foam::StaticHashTable<T, Key, Hash>::xfer()
{
return xferMove(*this);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
inline T& StaticHashTable<T, Key, Hash>::operator[](const Key& key)
inline T& Foam::StaticHashTable<T, Key, Hash>::operator[](const Key& key)
{
iterator iter = find(key);
if (iter == end())
{
FatalErrorIn("StaticHashTable<T, Key, Hash>::operator[](const Key&)")
<< key << " not found in table. Valid entries are "
<< key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
@ -62,17 +104,21 @@ inline T& StaticHashTable<T, Key, Hash>::operator[](const Key& key)
return *iter;
}
template<class T, class Key, class Hash>
inline const T& StaticHashTable<T, Key, Hash>::operator[](const Key& key) const
inline const T& Foam::StaticHashTable<T, Key, Hash>::operator[]
(
const Key& key
) const
{
const_iterator iter = find(key);
if (iter == end())
if (iter == cend())
{
FatalErrorIn
(
"StaticHashTable<T, Key, Hash>::operator[](const Key&) const"
) << key << " not found in table. Valid entries are "
) << key << " not found in table. Valid entries: "
<< toc()
<< exit(FatalError);
}
@ -81,74 +127,97 @@ inline const T& StaticHashTable<T, Key, Hash>::operator[](const Key& key) const
}
template<class T, class Key, class Hash>
inline T& Foam::StaticHashTable<T, Key, Hash>::operator()(const Key& key)
{
iterator iter = find(key);
if (iter == end())
{
insert(key, T());
return *find(key);
}
else
{
return *iter;
}
}
// * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
Iterator
inline Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::Iterator
(
TableRef curStaticHashTable,
TableRef hashTbl,
label hashIndex,
label elementIndex
label elemIndex
)
:
curStaticHashTable_(curStaticHashTable),
hashTable_(hashTbl),
hashIndex_(hashIndex),
elementIndex_(elementIndex)
elemIndex_(elemIndex)
{}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
Iterator(const iterator& iter)
inline Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::Iterator
(
const iterator& iter
)
:
curStaticHashTable_(iter.curStaticHashTable_),
hashTable_(iter.hashTable_),
hashIndex_(iter.hashIndex_),
elementIndex_(iter.elementIndex_)
elemIndex_(iter.elemIndex_)
{}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline void StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator=(const iterator& iter)
inline void
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator=
(
const iterator& iter
)
{
this->hashIndex_ = iter.hashIndex_;
this->elementIndex_ = iter.elementIndex_;
this->elemIndex_ = iter.elemIndex_;
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator==(const iterator& iter) const
inline bool
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator==
(
const iterator& iter
) const
{
return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
return hashIndex_ == iter.hashIndex_ && elemIndex_ == iter.elemIndex_;
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator==(const const_iterator& iter) const
inline bool
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator==
(
const const_iterator& iter
) const
{
return hashIndex_ == iter.hashIndex_ && elementIndex_ == iter.elementIndex_;
return hashIndex_ == iter.hashIndex_ && elemIndex_ == iter.elemIndex_;
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator!=(const iterator& iter) const
{
return !operator==(iter);
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline bool StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator!=(const const_iterator& iter) const
inline bool
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator!=
(
const iterator& iter
) const
{
return !operator==(iter);
}
@ -156,17 +225,29 @@ operator!=(const const_iterator& iter) const
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator*()
inline bool
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator!=
(
const const_iterator& iter
) const
{
return curStaticHashTable_.objects_[hashIndex_][elementIndex_];
return !operator==(iter);
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline TRef StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
operator()()
inline TRef
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator*()
{
return hashTable_.objects_[hashIndex_][elemIndex_];
}
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline TRef
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::operator()()
{
return operator*();
}
@ -175,40 +256,44 @@ operator()()
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline
typename StaticHashTable<T, Key, Hash>::template Iterator
typename Foam::StaticHashTable<T, Key, Hash>::template Iterator
<
TRef,
TableRef
>&
StaticHashTable<T, Key, Hash>::Iterator
Foam::StaticHashTable<T, Key, Hash>::Iterator
<
TRef,
TableRef
>::operator++()
{
const List<T>& localObjects = curStaticHashTable_.objects_[hashIndex_];
if (elementIndex_ == localObjects.size()-1)
// Check for special value from erase. (sets hashIndex to -1)
if (hashIndex_ >= 0)
{
elementIndex_ = 0;
// Try the next element on the local list
elemIndex_++;
// Find first non-zero entry
for
(
hashIndex_++;
hashIndex_ < curStaticHashTable_.objects_.size();
hashIndex_++
)
if (elemIndex_ < hashTable_.objects_[hashIndex_].size())
{
if (curStaticHashTable_.objects_[hashIndex_].size() > 0)
{
break;
}
return *this;
}
}
else
// Step to the next table entry
elemIndex_ = 0;
while
(
++hashIndex_ < hashTable_.objects_.size()
&& !hashTable_.objects_[hashIndex_].size()
)
{}
if (hashIndex_ >= hashTable_.objects_.size())
{
elementIndex_++;
// make end iterator
hashIndex_ = hashTable_.keys_.size();
}
return *this;
@ -218,12 +303,12 @@ StaticHashTable<T, Key, Hash>::Iterator
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline
typename StaticHashTable<T, Key, Hash>::template Iterator
typename Foam::StaticHashTable<T, Key, Hash>::template Iterator
<
TRef,
TableRef
>
StaticHashTable<T, Key, Hash>::Iterator
Foam::StaticHashTable<T, Key, Hash>::Iterator
<
TRef,
TableRef
@ -240,24 +325,23 @@ StaticHashTable<T, Key, Hash>::Iterator
template<class T, class Key, class Hash>
template<class TRef, class TableRef>
inline
const Key& StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::
key()
inline const Key&
Foam::StaticHashTable<T, Key, Hash>::Iterator<TRef, TableRef>::key() const
{
return curStaticHashTable_.keys_[hashIndex_][elementIndex_];
return hashTable_.keys_[hashIndex_][elemIndex_];
}
template<class T, class Key, class Hash>
inline typename StaticHashTable<T, Key, Hash>::iterator
StaticHashTable<T, Key, Hash>::begin()
inline typename Foam::StaticHashTable<T, Key, Hash>::iterator
Foam::StaticHashTable<T, Key, Hash>::begin()
{
// Find first non-empty entry
forAll(keys_, i)
forAll(keys_, hashIdx)
{
if (keys_[i].size() > 0)
if (keys_[hashIdx].size())
{
return iterator(*this, i, 0);
return iterator(*this, hashIdx, 0);
}
}
@ -273,23 +357,23 @@ StaticHashTable<T, Key, Hash>::begin()
template<class T, class Key, class Hash>
inline const typename StaticHashTable<T, Key, Hash>::iterator&
StaticHashTable<T, Key, Hash>::end()
inline const typename Foam::StaticHashTable<T, Key, Hash>::iterator&
Foam::StaticHashTable<T, Key, Hash>::end()
{
return StaticHashTable<T, Key, Hash>::endIter_;
}
template<class T, class Key, class Hash>
inline typename StaticHashTable<T, Key, Hash>::const_iterator
StaticHashTable<T, Key, Hash>::begin() const
inline typename Foam::StaticHashTable<T, Key, Hash>::const_iterator
Foam::StaticHashTable<T, Key, Hash>::cbegin() const
{
// Find first non-empty entry
forAll(keys_, i)
forAll(keys_, hashIdx)
{
if (keys_[i].size() > 0)
if (keys_[hashIdx].size())
{
return const_iterator(*this, i, 0);
return const_iterator(*this, hashIdx, 0);
}
}
@ -305,8 +389,24 @@ StaticHashTable<T, Key, Hash>::begin() const
template<class T, class Key, class Hash>
inline const typename StaticHashTable<T, Key, Hash>::const_iterator&
StaticHashTable<T, Key, Hash>::end() const
inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator&
Foam::StaticHashTable<T, Key, Hash>::cend() const
{
return StaticHashTable<T, Key, Hash>::endConstIter_;
}
template<class T, class Key, class Hash>
inline typename Foam::StaticHashTable<T, Key, Hash>::const_iterator
Foam::StaticHashTable<T, Key, Hash>::begin() const
{
return this->cbegin();
}
template<class T, class Key, class Hash>
inline const typename Foam::StaticHashTable<T, Key, Hash>::const_iterator&
Foam::StaticHashTable<T, Key, Hash>::end() const
{
return StaticHashTable<T, Key, Hash>::endConstIter_;
}
@ -314,6 +414,4 @@ StaticHashTable<T, Key, Hash>::end() const
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -28,16 +28,14 @@ License
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from Istream
template<class T, class Key, class Hash>
StaticHashTable<T, Key, Hash>::StaticHashTable(Istream& is, const label size)
Foam::StaticHashTable<T, Key, Hash>::StaticHashTable
(
Istream& is,
const label size
)
:
StaticHashTableName(),
keys_(size),
@ -59,23 +57,58 @@ StaticHashTable<T, Key, Hash>::StaticHashTable(Istream& is, const label size)
}
// * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Foam::Ostream&
Foam::StaticHashTable<T, Key, Hash>::printInfo(Ostream& os) const
{
label used = 0;
label maxChain = 0;
unsigned avgChain = 0;
// Find first non-empty entry
forAll(keys_, hashIdx)
{
const label count = keys_[hashIdx].size();
if (count)
{
++used;
avgChain += count;
if (maxChain < count)
{
maxChain = count;
}
}
}
os << "StaticHashTable<T,Key,Hash>"
<< " elements:" << size() << " slots:" << used << "/" << keys_.size()
<< " chaining(avg/max):" << (used ? float(avgChain/used) : 0)
<< "/" << maxChain << endl;
return os;
}
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T, class Key, class Hash>
Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
Foam::Istream& Foam::operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
{
is.fatalCheck("operator>>(Istream&, StaticHashTable<T, Key, Hash>&)");
// Anull list
L.clear();
is.fatalCheck("operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)");
is.fatalCheck("operator>>(Istream&, StaticHashTable<T, Key, Hash>&)");
token firstToken(is);
is.fatalCheck
(
"operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L) : "
"operator>>(Istream&, StaticHashTable<T, Key, Hash>&) : "
"reading first token"
);
@ -84,7 +117,7 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
label s = firstToken.labelToken();
// Read beginning of contents
char listDelimiter = is.readBeginList("StaticHashTable<T, Key, Hash>");
char delimiter = is.readBeginList("StaticHashTable<T, Key, Hash>");
if (s)
{
@ -93,7 +126,7 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
L.resize(2*s);
}
if (listDelimiter == token::BEGIN_LIST)
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
{
@ -112,7 +145,7 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)",
"operator>>(Istream&, StaticHashTable<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
@ -128,7 +161,7 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)",
"operator>>(Istream&, StaticHashTable<T, Key, Hash>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
@ -144,10 +177,13 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
)
{
is.putBack(lastToken);
Key key;
is >> key;
T element;
is >> element;
L.insert(key, element);
is.fatalCheck
@ -163,7 +199,7 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
{
FatalIOErrorIn
(
"operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)",
"operator>>(Istream&, StaticHashTable<T, Key, Hash>&)",
is
) << "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
@ -177,15 +213,15 @@ Istream& operator>>(Istream& is, StaticHashTable<T, Key, Hash>& L)
template<class T, class Key, class Hash>
Ostream& operator<<(Ostream& os, const StaticHashTable<T, Key, Hash>& L)
Foam::Ostream& Foam::operator<<
(
Ostream& os,
const StaticHashTable<T, Key, Hash>& L)
{
// Write size of StaticHashTable
os << nl << L.size();
// Write size and start delimiter
os << nl << L.size() << nl << token::BEGIN_LIST << nl;
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write StaticHashTable contents
// Write contents
for
(
typename StaticHashTable<T, Key, Hash>::const_iterator iter = L.begin();
@ -196,7 +232,7 @@ Ostream& operator<<(Ostream& os, const StaticHashTable<T, Key, Hash>& L)
os << iter.key() << token::SPACE << iter() << nl;
}
// Write end of contents
// Write end delimiter
os << token::END_LIST;
// Check state of IOstream
@ -206,8 +242,4 @@ Ostream& operator<<(Ostream& os, const StaticHashTable<T, Key, Hash>& L)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -0,0 +1,132 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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::Keyed
Description
A container with an integer key attached to any item.
The key can useful for sorting.
SourceFiles
KeyedI.H
\*---------------------------------------------------------------------------*/
#ifndef Keyed_H
#define Keyed_H
#include "List.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// Forward declaration of friend functions and operators
template<class T> class Keyed;
template<class T> Istream& operator>>(Istream&, Keyed<T>&);
template<class T> Ostream& operator<<(Ostream&, const Keyed<T>&);
/*---------------------------------------------------------------------------*\
Class Keyed Declaration
\*---------------------------------------------------------------------------*/
template<class T>
class Keyed
:
public T
{
// Private data
label key_;
public:
// Static Members
//- Add labels to a list of values
inline static List<Keyed<T> > createList
(
const List<T>&,
const label key=0
);
//- Add labels to a list of values
inline static List<Keyed<T> > createList
(
const List<T>&,
const List<label>& keys
);
// Constructors
//- Construct null
inline Keyed();
//- Construct as a copy of item, with a key
inline Keyed(const T& item, const label key=0);
//- Construct by transferring the item, with a key
inline Keyed(const Xfer<T>& item, const label key=0);
//- Construct from Istream
inline Keyed(Istream&);
// Member Functions
// Access
//- Return const access to the integer key
inline label key() const;
//- Return non-const access to the integer key
inline label& key();
// IOstream Operators
friend Istream& operator>> <T>(Istream&, Keyed<T>&);
friend Ostream& operator<< <T>(Ostream&, const Keyed<T>&);
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#include "KeyedI.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
// ************************************************************************* //

View file

@ -0,0 +1,152 @@
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright held by original author
\\/ 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 "IOstreams.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline Foam::Keyed<T>::Keyed()
:
key_(-1)
{}
template<class T>
inline Foam::Keyed<T>::Keyed(const T& item, const label key)
:
T(item),
key_(key)
{}
template<class T>
inline Foam::Keyed<T>::Keyed(const Xfer<T>& item, const label key)
:
T(item),
key_(key)
{}
template<class T>
inline Foam::Keyed<T>::Keyed(Istream& is)
{
is >> *this;
}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline Foam::label Foam::Keyed<T>::key() const
{
return key_;
}
template<class T>
inline Foam::label& Foam::Keyed<T>::key()
{
return key_;
}
template<class T>
inline Foam::List<Foam::Keyed<T> >
Foam::Keyed<T>::createList(const List<T>& lst, const label key)
{
List<Keyed<T> > newList(lst.size());
forAll (lst, elemI)
{
newList[elemI] = Keyed(lst[elemI], key);
}
return newList;
}
template<class T>
inline Foam::List<Foam::Keyed<T> >
Foam::Keyed<T>::createList(const List<T>& lst, const List<label>& keys)
{
if (lst.size() != keys.size())
{
FatalErrorIn
(
"Foam::Keyed<T>::createList(const List<T>&, const List<label>&)"
)
<< "size mismatch adding keys to a list:" << nl
<< "List has size " << lst.size()
<< " and keys has size " << keys.size() << nl
<< abort(FatalError);
}
List<Keyed<T> > newList(lst.size());
forAll (lst, elemI)
{
newList[elemI] = Keyed(lst[elemI], keys[elemI]);
}
return newList;
}
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class T>
inline Foam::Istream& Foam::operator>>(Istream& is, Keyed<T>& item)
{
// Read beginning of Keyed item/key pair
is.readBegin("Keyed<T>");
is >> static_cast<T&>(item);
is >> item.key_;
// Read end of Keyed item/key pair
is.readEnd("Keyed<T>");
// Check state of Ostream
is.check("Istream& operator>>(Istream&, Keyed&)");
return is;
}
template<class T>
inline Foam::Ostream& Foam::operator<<(Ostream& os, const Keyed<T>& item)
{
os << token::BEGIN_LIST
<< static_cast<const T&>(item)
<< token::SPACE << item.key_
<< token::END_LIST;
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// ************************************************************************* //

View file

@ -26,22 +26,17 @@ License
#include "ILList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
ILList<LListBase, T>::ILList(const ILList<LListBase, T>& slpl)
Foam::ILList<LListBase, T>::ILList(const ILList<LListBase, T>& lst)
:
UILList<LListBase, T>()
{
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -53,9 +48,9 @@ ILList<LListBase, T>::ILList(const ILList<LListBase, T>& slpl)
#ifndef __INTEL_COMPILER
template<class LListBase, class T>
template<class CloneArg>
ILList<LListBase, T>::ILList
Foam::ILList<LListBase, T>::ILList
(
const ILList<LListBase, T>& slpl,
const ILList<LListBase, T>& lst,
const CloneArg& cloneArg
)
:
@ -63,8 +58,8 @@ ILList<LListBase, T>::ILList
{
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -77,7 +72,7 @@ ILList<LListBase, T>::ILList
// * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
template<class LListBase, class T>
ILList<LListBase, T>::~ILList()
Foam::ILList<LListBase, T>::~ILList()
{
this->clear();
}
@ -85,9 +80,8 @@ ILList<LListBase, T>::~ILList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Return and remove head
template<class LListBase, class T>
bool ILList<LListBase, T>::eraseHead()
bool Foam::ILList<LListBase, T>::eraseHead()
{
T* tPtr;
if ((tPtr = this->removeHead()))
@ -101,9 +95,8 @@ bool ILList<LListBase, T>::eraseHead()
}
}
//- Return and remove element
template<class LListBase, class T>
bool ILList<LListBase, T>::erase(T* p)
bool Foam::ILList<LListBase, T>::erase(T* p)
{
T* tPtr;
if ((tPtr = remove(p)))
@ -119,7 +112,7 @@ bool ILList<LListBase, T>::erase(T* p)
template<class LListBase, class T>
void ILList<LListBase, T>::clear()
void Foam::ILList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
@ -131,17 +124,25 @@ void ILList<LListBase, T>::clear()
}
template<class LListBase, class T>
void Foam::ILList<LListBase, T>::transfer(ILList<LListBase, T>& lst)
{
clear();
LListBase::transfer(lst);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void ILList<LListBase, T>::operator=(const ILList<LListBase, T>& slpl)
void Foam::ILList<LListBase, T>::operator=(const ILList<LListBase, T>& lst)
{
this->clear();
for
(
typename UILList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -149,11 +150,6 @@ void ILList<LListBase, T>::operator=(const ILList<LListBase, T>& slpl)
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "ILListIO.C"

View file

@ -71,7 +71,7 @@ class ILList
//- Read from Istream using given Istream constructor class
template<class INew>
void read(Istream&, const INew& inewt);
void read(Istream&, const INew&);
public:
@ -96,7 +96,7 @@ public:
//- Copy constructor with additional argument for clone
template<class CloneArg>
ILList(const ILList<LListBase, T>& slpl, const CloneArg& cloneArg)
ILList(const ILList<LListBase, T>& lst, const CloneArg& cloneArg)
#ifdef __INTEL_COMPILER
:
UILList<LListBase, T>()
@ -104,8 +104,8 @@ public:
for
(
typename UILList<LListBase, T>::const_iterator iter =
slpl.begin();
iter != slpl.end();
lst.begin();
iter != lst.end();
++iter
)
{
@ -118,7 +118,7 @@ public:
//- Construct from Istream using given Istream constructor class
template<class INew>
ILList(Istream&, const INew& inewt);
ILList(Istream&, const INew&);
// Destructor
@ -139,6 +139,10 @@ public:
//- Clear the contents of the list
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
void transfer(ILList<LListBase, T>&);
// Member operators
@ -148,10 +152,7 @@ public:
// Istream operator
//- Read List from Istream, discarding contents of existing List.
friend Istream& operator>>
#ifndef __CINT__
<LListBase, T>
#endif
friend Istream& operator>> <LListBase, T>
(
Istream&,
ILList<LListBase, T>&

View file

@ -30,24 +30,19 @@ Description
#include "Istream.H"
#include "INew.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
template<class INew>
void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
void Foam::ILList<LListBase, T>::read(Istream& is, const INew& iNew)
{
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
token firstToken(is);
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : reading first token"
"operator>>(Istream&, ILList<LListBase, T>&) : reading first token"
);
if (firstToken.isLabel())
@ -55,31 +50,31 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
label s = firstToken.labelToken();
// Read beginning of contents
char listDelimiter = is.readBeginList("ILList<LListBase, T>");
char delimiter = is.readBeginList("ILList<LListBase, T>");
if (s)
{
if (listDelimiter == token::BEGIN_LIST)
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
{
append(inewt(is).ptr());
append(iNew(is).ptr());
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : "
"operator>>(Istream&, ILList<LListBase, T>&) : "
"reading entry"
);
}
}
else
{
T* tPtr = inewt(is).ptr();
T* tPtr = iNew(is).ptr();
append(tPtr);
is.fatalCheck
(
"operator>>(Istream& is, ILList<LListBase, T>& L) : "
"operator>>(Istream&, ILList<LListBase, T>&) : "
"reading entry"
);
@ -99,14 +94,14 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
{
FatalIOErrorIn
(
"operator>>(Istream& is, ILList<LListBase, T>& L)",
"operator>>(Istream&, ILList<LListBase, T>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
token lastToken(is);
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
while
(
@ -117,36 +112,34 @@ void ILList<LListBase, T>::read(Istream& is, const INew& inewt)
)
{
is.putBack(lastToken);
append(inewt(is).ptr());
append(iNew(is).ptr());
is >> lastToken;
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
}
}
else
{
FatalIOErrorIn("operator>>(Istream& is, ILList<LListBase, T>& L)", is)
FatalIOErrorIn("operator>>(Istream&, ILList<LListBase, T>&)", is)
<< "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
}
is.fatalCheck("operator>>(Istream& is, ILList<LListBase, T>& L)");
is.fatalCheck("operator>>(Istream&, ILList<LListBase, T>&)");
}
//- Construct from Istream using given Istream constructor class
template<class LListBase, class T>
template<class INew>
ILList<LListBase, T>::ILList(Istream& is, const INew& inewt)
Foam::ILList<LListBase, T>::ILList(Istream& is, const INew& iNew)
{
read(is, inewt);
read(is, iNew);
}
// Construct from Istream
template<class LListBase, class T>
ILList<LListBase, T>::ILList(Istream& is)
Foam::ILList<LListBase, T>::ILList(Istream& is)
{
read(is, INew<T>());
}
@ -155,7 +148,7 @@ ILList<LListBase, T>::ILList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Istream& operator>>(Istream& is, ILList<LListBase, T>& L)
Foam::Istream& Foam::operator>>(Istream& is, ILList<LListBase, T>& L)
{
L.clear();
L.read(is, INew<T>());
@ -166,6 +159,4 @@ Istream& operator>>(Istream& is, ILList<LListBase, T>& L)
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -27,22 +27,16 @@ Description
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "LList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
LList<LListBase, T>::LList(const LList<LListBase, T>& slpl)
Foam::LList<LListBase, T>::LList(const LList<LListBase, T>& lst)
:
LListBase()
{
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
}
@ -50,7 +44,7 @@ LList<LListBase, T>::LList(const LList<LListBase, T>& slpl)
template<class LListBase, class T>
LList<LListBase, T>::~LList()
Foam::LList<LListBase, T>::~LList()
{
this->clear();
}
@ -59,7 +53,7 @@ LList<LListBase, T>::~LList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class LListBase, class T>
void LList<LListBase, T>::clear()
void Foam::LList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
@ -71,24 +65,28 @@ void LList<LListBase, T>::clear()
}
template<class LListBase, class T>
void Foam::LList<LListBase, T>::transfer(LList<LListBase, T>& lst)
{
clear();
LListBase::transfer(lst);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void LList<LListBase, T>::operator=(const LList<LListBase, T>& slpl)
void Foam::LList<LListBase, T>::operator=(const LList<LListBase, T>& lst)
{
this->clear();
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "LListIO.C"

View file

@ -38,6 +38,7 @@ SourceFiles
#define LList_H
#include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -67,7 +68,7 @@ Ostream& operator<<
/*---------------------------------------------------------------------------*\
Class LList Declaration
Class LList Declaration
\*---------------------------------------------------------------------------*/
template<class LListBase, class T>
@ -200,6 +201,9 @@ public:
//- Delete contents of list
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
void transfer(LList<LListBase, T>&);
// Member operators
@ -323,19 +327,13 @@ public:
// IOstream operators
friend Istream& operator>>
#ifndef __CINT__
<LListBase, T>
#endif
friend Istream& operator>> <LListBase, T>
(
Istream&,
LList<LListBase, T>&
);
friend Ostream& operator<<
#ifndef __CINT__
<LListBase, T>
#endif
friend Ostream& operator<< <LListBase, T>
(
Ostream&,
const LList<LListBase, T>&

View file

@ -30,16 +30,10 @@ Description
#include "Istream.H"
#include "Ostream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
// Construct from Istream
template<class LListBase, class T>
LList<LListBase, T>::LList(Istream& is)
Foam::LList<LListBase, T>::LList(Istream& is)
{
operator>>(is, *this);
}
@ -48,18 +42,18 @@ LList<LListBase, T>::LList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Istream& operator>>(Istream& is, LList<LListBase, T>& L)
Foam::Istream& Foam::operator>>(Istream& is, LList<LListBase, T>& L)
{
// Anull list
L.clear();
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
token firstToken(is);
is.fatalCheck
(
" operator>>(Istream& is, LList<LListBase, T>& L) : reading first token"
" operator>>(Istream&, LList<LListBase, T>&) : reading first token"
);
if (firstToken.isLabel())
@ -67,11 +61,11 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
label s = firstToken.labelToken();
// Read beginning of contents
char listDelimiter = is.readBeginList("LList<LListBase, T>");
char delimiter = is.readBeginList("LList<LListBase, T>");
if (s)
{
if (listDelimiter == token::BEGIN_LIST)
if (delimiter == token::BEGIN_LIST)
{
for (register label i=0; i<s; i++)
{
@ -101,14 +95,14 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
{
FatalIOErrorIn
(
" operator>>(Istream& is, LList<LListBase, T>& L)",
" operator>>(Istream&, LList<LListBase, T>&)",
is
) << "incorrect first token, '(', found " << firstToken.info()
<< exit(FatalIOError);
}
token lastToken(is);
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
while
(
@ -124,19 +118,19 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
L.append(element);
is >> lastToken;
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase, T>&)");
}
}
else
{
FatalIOErrorIn(" operator>>(Istream& is, LList<LListBase, T>& L)", is)
FatalIOErrorIn(" operator>>(Istream&, LList<LListBase, T>&)", is)
<< "incorrect first token, expected <int> or '(', found "
<< firstToken.info()
<< exit(FatalIOError);
}
// Check state of IOstream
is.fatalCheck(" operator>>(Istream& is, LList<LListBase, T>& L)");
is.fatalCheck(" operator>>(Istream&, LList<LListBase,>&)");
return is;
}
@ -145,19 +139,19 @@ Istream& operator>>(Istream& is, LList<LListBase, T>& L)
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Ostream& operator<<(Ostream& os, const LList<LListBase, T>& ll)
Foam::Ostream& Foam::operator<<(Ostream& os, const LList<LListBase, T>& lst)
{
// Write size of LList
os << nl << ll.size();
// Write size
os << nl << lst.size();
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write LList contents
// Write contents
for
(
typename LList<LListBase, T>::const_iterator iter = ll.begin();
iter != ll.end();
typename LList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -168,14 +162,10 @@ Ostream& operator<<(Ostream& os, const LList<LListBase, T>& ll)
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const LList&)");
os.check("Ostream& operator<<(Ostream&, const LList<LListBase, T>&)");
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -26,19 +26,14 @@ License
#include "LPtrList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& slpl)
Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
:
LList<LListBase, T*>()
{
for(const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
}
@ -48,7 +43,7 @@ LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& slpl)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
template<class LListBase, class T>
LPtrList<LListBase, T>::~LPtrList()
Foam::LPtrList<LListBase, T>::~LPtrList()
{
clear();
}
@ -56,9 +51,8 @@ LPtrList<LListBase, T>::~LPtrList()
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
//- Return and remove head
template<class LListBase, class T>
bool LPtrList<LListBase, T>::eraseHead()
bool Foam::LPtrList<LListBase, T>::eraseHead()
{
T* tPtr;
if ((tPtr = this->removeHead()))
@ -74,7 +68,7 @@ bool LPtrList<LListBase, T>::eraseHead()
template<class LListBase, class T>
void LPtrList<LListBase, T>::clear()
void Foam::LPtrList<LListBase, T>::clear()
{
label oldSize = this->size();
for (label i=0; i<oldSize; i++)
@ -86,24 +80,28 @@ void LPtrList<LListBase, T>::clear()
}
template<class LListBase, class T>
void Foam::LPtrList<LListBase, T>::transfer(LPtrList<LListBase, T>& lst)
{
clear();
LList<LListBase, T*>::transfer(lst);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& slpl)
void Foam::LPtrList<LListBase, T>::operator=(const LPtrList<LListBase, T>& lst)
{
clear();
for(const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(iter().clone().ptr());
}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "LPtrListIO.C"

View file

@ -149,12 +149,16 @@ public:
// Edit
//- Remove the head element specified from the list and delete it
//- Remove the head element from the list and delete the pointer
bool eraseHead();
//- Remove the specified element from the list and delete it
//- Clear the contents of the list
void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
void transfer(LPtrList<LListBase, T>&);
// Member operators
@ -256,19 +260,13 @@ public:
// IOstream operators
friend Istream& operator>>
#ifndef __CINT__
<LListBase, T>
#endif
friend Istream& operator>> <LListBase, T>
(
Istream&,
LPtrList<LListBase, T>&
);
friend Ostream& operator<<
#ifndef __CINT__
<LListBase, T>
#endif
friend Ostream& operator<< <LListBase, T>
(
Ostream&,
const LPtrList<LListBase, T>&

View file

@ -29,16 +29,11 @@ License
#include "Ostream.H"
#include "INew.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * * //
template<class LListBase, class T>
template<class INew>
void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
void Foam::LPtrList<LListBase, T>::read(Istream& is, const INew& iNew)
{
is.fatalCheck
(
@ -58,15 +53,15 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
label s = firstToken.labelToken();
// Read beginning of contents
char listDelimiter = is.readBeginList("LPtrList<LListBase, T>");
char delimiter = is.readBeginList("LPtrList<LListBase, T>");
if (s)
{
if (listDelimiter == token::BEGIN_LIST)
if (delimiter == token::BEGIN_LIST)
{
for (label i=0; i<s; i++)
{
append(inewt(is).ptr());
append(iNew(is).ptr());
is.fatalCheck
(
@ -77,7 +72,7 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
}
else
{
T* tPtr = inewt(is).ptr();
T* tPtr = iNew(is).ptr();
append(tPtr);
is.fatalCheck
@ -120,7 +115,7 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
)
{
is.putBack(lastToken);
append(inewt(is).ptr());
append(iNew(is).ptr());
is >> lastToken;
is.fatalCheck
@ -148,14 +143,14 @@ void LPtrList<LListBase, T>::read(Istream& is, const INew& inewt)
template<class LListBase, class T>
template<class INew>
LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& inewt)
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is, const INew& iNew)
{
read(is, inewt);
read(is, iNew);
}
template<class LListBase, class T>
LPtrList<LListBase, T>::LPtrList(Istream& is)
Foam::LPtrList<LListBase, T>::LPtrList(Istream& is)
{
read(is, INew<T>());
}
@ -164,11 +159,10 @@ LPtrList<LListBase, T>::LPtrList(Istream& is)
// * * * * * * * * * * * * * * * Istream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Istream& operator>>(Istream& is, LPtrList<LListBase, T>& L)
Foam::Istream& Foam::operator>>(Istream& is, LPtrList<LListBase, T>& L)
{
// Anull list
L.clear();
L.read(is, INew<T>());
return is;
}
@ -177,19 +171,19 @@ Istream& operator>>(Istream& is, LPtrList<LListBase, T>& L)
// * * * * * * * * * * * * * * * Ostream Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
Ostream& operator<<(Ostream& os, const LPtrList<LListBase, T>& slpl)
Foam::Ostream& Foam::operator<<(Ostream& os, const LPtrList<LListBase, T>& lst)
{
// Write size of LPtrList
os << nl << slpl.size();
// Write size
os << nl << lst.size();
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write LPtrList contents
// Write contents
for
(
typename LPtrList<LListBase, T>::const_iterator iter = slpl.begin();
iter != slpl.end();
typename LPtrList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -200,14 +194,9 @@ Ostream& operator<<(Ostream& os, const LPtrList<LListBase, T>& slpl)
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const LPtrList&)");
os.check("Ostream& operator<<(Ostream&, const LPtrList<LListBase, T>&)");
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -28,17 +28,12 @@ Description
#include "UILList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class LListBase, class T>
UILList<LListBase, T>::UILList(const UILList<LListBase, T>& slpl)
Foam::UILList<LListBase, T>::UILList(const UILList<LListBase, T>& lst)
{
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
{
append(&iter());
}
@ -48,22 +43,24 @@ UILList<LListBase, T>::UILList(const UILList<LListBase, T>& slpl)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class LListBase, class T>
void UILList<LListBase, T>::operator=(const UILList<LListBase, T>& slpl)
void Foam::UILList<LListBase, T>::operator=(const UILList<LListBase, T>& rhs)
{
LListBase::clear();
for (const_iterator iter = slpl.begin(); iter != slpl.end(); ++iter)
for (const_iterator iter = rhs.begin(); iter != rhs.end(); ++iter)
{
append(&iter());
}
}
// Comparison for equality
template<class LListBase, class T>
bool UILList<LListBase, T>::operator==(const UILList<LListBase, T>& slpl) const
bool Foam::UILList<LListBase, T>::operator==
(
const UILList<LListBase, T>& rhs
) const
{
if (this->size() != slpl.size())
if (this->size() != rhs.size())
{
return false;
}
@ -71,7 +68,7 @@ bool UILList<LListBase, T>::operator==(const UILList<LListBase, T>& slpl) const
bool equal = true;
const_iterator iter1 = this->begin();
const_iterator iter2 = slpl.begin();
const_iterator iter2 = rhs.begin();
for (; iter1 != this->end(); ++iter1, ++iter2)
{
@ -84,16 +81,15 @@ bool UILList<LListBase, T>::operator==(const UILList<LListBase, T>& slpl) const
// Comparison for inequality
template<class LListBase, class T>
bool UILList<LListBase, T>::operator!=(const UILList<LListBase, T>& slpl) const
bool Foam::UILList<LListBase, T>::operator!=
(
const UILList<LListBase, T>& rhs
) const
{
return !operator==(slpl);
return !operator==(rhs);
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
#include "UILListIO.C"

View file

@ -38,6 +38,7 @@ SourceFiles
#define UILList_H
#include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -266,7 +267,7 @@ public:
// STL member operators
//- Equality operation on ULists of the same type.
// Returns true when the ULists are elementwise equal
// Returns true when the ULists are element-wise equal
// (using UList::value_type::operator==). Takes linear time.
bool operator==(const UILList<LListBase, T>&) const;
@ -276,10 +277,7 @@ public:
// Ostream operator
friend Ostream& operator<<
#ifndef __CINT__
<LListBase, T>
#endif
friend Ostream& operator<< <LListBase, T>
(
Ostream&,
const UILList<LListBase, T>&

View file

@ -30,27 +30,22 @@ Description
#include "Ostream.H"
#include "token.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Ostream Operator * * * * * * * * * * * * * //
template<class LListBase, class T>
Ostream& operator<<(Ostream& os, const UILList<LListBase, T>& ill)
Foam::Ostream& Foam::operator<<(Ostream& os, const UILList<LListBase, T>& lst)
{
// Write size of UILList
os << nl << ill.size();
// Write size
os << nl << lst.size();
// Write beginning of contents
os << nl << token::BEGIN_LIST << nl;
// Write UILList contents
// Write contents
for
(
typename UILList<LListBase, T>::const_iterator iter = ill.begin();
iter != ill.end();
typename UILList<LListBase, T>::const_iterator iter = lst.begin();
iter != lst.end();
++iter
)
{
@ -61,14 +56,9 @@ Ostream& operator<<(Ostream& os, const UILList<LListBase, T>& ill)
os << token::END_LIST;
// Check state of IOstream
os.check("Ostream& operator<<(Ostream&, const UILList&)");
os.check("Ostream& operator<<(Ostream&, const UILList<LListBase, T>&)");
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -30,28 +30,23 @@ License
#include "IOstreams.H"
#include "long.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
// * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
DLListBase::iterator DLListBase::endIter
Foam::DLListBase::iterator Foam::DLListBase::endIter_
(
const_cast<DLListBase&>(static_cast<const DLListBase&>(DLListBase()))
);
DLListBase::const_iterator DLListBase::endConstIter
Foam::DLListBase::const_iterator Foam::DLListBase::endConstIter_
(
static_cast<const DLListBase&>(DLListBase()),
reinterpret_cast<const link*>(NULL)
reinterpret_cast<const link*>(0)
);
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void DLListBase::insert(DLListBase::link* a)
void Foam::DLListBase::insert(DLListBase::link* a)
{
nElmts_++;
@ -71,7 +66,7 @@ void DLListBase::insert(DLListBase::link* a)
}
void DLListBase::append(DLListBase::link* a)
void Foam::DLListBase::append(DLListBase::link* a)
{
nElmts_++;
@ -91,7 +86,7 @@ void DLListBase::append(DLListBase::link* a)
}
bool DLListBase::swapUp(DLListBase::link* a)
bool Foam::DLListBase::swapUp(DLListBase::link* a)
{
if (first_ != a)
{
@ -132,7 +127,7 @@ bool DLListBase::swapUp(DLListBase::link* a)
}
bool DLListBase::swapDown(DLListBase::link* a)
bool Foam::DLListBase::swapDown(DLListBase::link* a)
{
if (last_ != a)
{
@ -173,7 +168,7 @@ bool DLListBase::swapDown(DLListBase::link* a)
}
DLListBase::link* DLListBase::removeHead()
Foam::DLListBase::link* Foam::DLListBase::removeHead()
{
nElmts_--;
@ -197,7 +192,7 @@ DLListBase::link* DLListBase::removeHead()
}
DLListBase::link* DLListBase::remove(DLListBase::link* l)
Foam::DLListBase::link* Foam::DLListBase::remove(DLListBase::link* l)
{
nElmts_--;
@ -229,7 +224,7 @@ DLListBase::link* DLListBase::remove(DLListBase::link* l)
}
DLListBase::link* DLListBase::replace
Foam::DLListBase::link* Foam::DLListBase::replace
(
DLListBase::link* oldLink,
DLListBase::link* newLink
@ -266,8 +261,4 @@ DLListBase::link* DLListBase::replace
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -38,6 +38,7 @@ SourceFiles
#include "bool.H"
#include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -122,6 +123,9 @@ public:
//- Return number of elements in list
inline label size() const;
//- Return true if the list is empty
inline bool empty() const;
//- Return first entry
inline link* first();
@ -167,10 +171,13 @@ public:
//- Clear the list
inline void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
inline void transfer(DLListBase&);
// STL iterator
//- An STL iterator
//- An STL-conforming iterator
class iterator
{
friend class DLListBase;
@ -187,16 +194,17 @@ public:
//- Copy of the link
link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with NULL element and link.
// Only used to create endIter
inline iterator(DLListBase&);
public:
//- Construct for a given DLListBase and link
inline iterator(DLListBase&, link*);
//- Construct for a given DLListBase
// setting element and link to NULL.
// Only used to create endIter
inline iterator(DLListBase&);
// Member operators
inline void operator=(const iterator&);
@ -211,16 +219,12 @@ public:
};
inline iterator begin();
//- iterator returned by end()
static iterator endIter;
inline const iterator& end();
// STL const_iterator
//- An STL const_iterator
//- An STL-conforming const_iterator
class const_iterator
{
// Private data
@ -252,12 +256,20 @@ public:
inline const_iterator operator++(int);
};
inline const_iterator cbegin() const;
inline const const_iterator& cend() const;
inline const_iterator begin() const;
inline const const_iterator& end() const;
private:
//- iterator returned by end()
static iterator endIter_;
//- const_iterator returned by end()
static const_iterator endConstIter;
static const_iterator endConstIter_;
inline const const_iterator& end() const;
};

View file

@ -26,21 +26,16 @@ License
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
inline DLListBase::link::link()
inline Foam::DLListBase::link::link()
:
prev_(0),
next_(0)
{}
inline DLListBase::DLListBase()
inline Foam::DLListBase::DLListBase()
:
first_(0),
last_(0),
@ -48,7 +43,7 @@ inline DLListBase::DLListBase()
{}
inline DLListBase::DLListBase(link* a)
inline Foam::DLListBase::DLListBase(link* a)
:
first_(a),
last_(a),
@ -61,32 +56,39 @@ inline DLListBase::DLListBase(link* a)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
inline DLListBase::~DLListBase()
inline Foam::DLListBase::~DLListBase()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline bool DLListBase::link::registered() const
inline bool Foam::DLListBase::link::registered() const
{
return prev_ != 0 && next_ != 0;
}
inline void DLListBase::link::deregister()
inline void Foam::DLListBase::link::deregister()
{
prev_ = 0;
next_ = 0;
}
inline label DLListBase::size() const
inline Foam::label Foam::DLListBase::size() const
{
return nElmts_;
}
inline DLListBase::link* DLListBase::first()
inline bool Foam::DLListBase::empty() const
{
return !nElmts_;
}
inline Foam::DLListBase::link*
Foam::DLListBase::first()
{
if (!nElmts_)
{
@ -98,7 +100,8 @@ inline DLListBase::link* DLListBase::first()
}
inline const DLListBase::link* DLListBase::first() const
inline const Foam::DLListBase::link*
Foam::DLListBase::first() const
{
if (!nElmts_)
{
@ -110,7 +113,8 @@ inline const DLListBase::link* DLListBase::first() const
}
inline DLListBase::link* DLListBase::last()
inline Foam::DLListBase::link*
Foam::DLListBase::last()
{
if (!nElmts_)
{
@ -122,7 +126,8 @@ inline DLListBase::link* DLListBase::last()
}
inline const DLListBase::link* DLListBase::last() const
inline const Foam::DLListBase::link*
Foam::DLListBase::last() const
{
if (!nElmts_)
{
@ -134,21 +139,36 @@ inline const DLListBase::link* DLListBase::last() const
}
inline void DLListBase::clear()
inline void Foam::DLListBase::clear()
{
nElmts_ = 0;
first_ = 0;
last_ = 0;
last_ = 0;
nElmts_ = 0;
}
inline DLListBase::link* DLListBase::remove(DLListBase::iterator& it)
inline void Foam::DLListBase::transfer(DLListBase& lst)
{
first_ = lst.first_;
last_ = lst.last_;
nElmts_ = lst.nElmts_;
lst.clear();
}
inline Foam::DLListBase::link*
Foam::DLListBase::remove
(
DLListBase::iterator& it
)
{
return remove(it.curElmt_);
}
inline DLListBase::link* DLListBase::replace
inline Foam::DLListBase::link*
Foam::DLListBase::replace
(
DLListBase::iterator& oldIter,
DLListBase::link* newLink
@ -160,7 +180,7 @@ inline DLListBase::link* DLListBase::replace
// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
inline DLListBase::iterator::iterator(DLListBase& s, link* elmt)
inline Foam::DLListBase::iterator::iterator(DLListBase& s, link* elmt)
:
curList_(s),
curElmt_(elmt),
@ -168,7 +188,7 @@ inline DLListBase::iterator::iterator(DLListBase& s, link* elmt)
{}
inline DLListBase::iterator::iterator(DLListBase& s)
inline Foam::DLListBase::iterator::iterator(DLListBase& s)
:
curList_(s),
curElmt_(NULL),
@ -176,32 +196,34 @@ inline DLListBase::iterator::iterator(DLListBase& s)
{}
inline void DLListBase::iterator::operator=(const iterator& iter)
inline void Foam::DLListBase::iterator::operator=(const iterator& iter)
{
curElmt_ = iter.curElmt_;
curLink_ = iter.curLink_;
}
inline bool DLListBase::iterator::operator==(const iterator& iter) const
inline bool Foam::DLListBase::iterator::operator==(const iterator& iter) const
{
return curElmt_ == iter.curElmt_;
}
inline bool DLListBase::iterator::operator!=(const iterator& iter) const
inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
{
return curElmt_ != iter.curElmt_;
}
inline DLListBase::link& DLListBase::iterator::operator*()
inline Foam::DLListBase::link&
Foam::DLListBase::iterator::operator*()
{
return *curElmt_;
}
inline DLListBase::iterator& DLListBase::iterator::operator++()
inline Foam::DLListBase::iterator&
Foam::DLListBase::iterator::operator++()
{
// Check if the curElmt_ is the last element (if it points to itself)
// or if the list is empty because the last element may have been removed
@ -219,7 +241,8 @@ inline DLListBase::iterator& DLListBase::iterator::operator++()
}
inline DLListBase::iterator DLListBase::iterator::operator++(int)
inline Foam::DLListBase::iterator
Foam::DLListBase::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
@ -227,7 +250,8 @@ inline DLListBase::iterator DLListBase::iterator::operator++(int)
}
inline DLListBase::iterator DLListBase::begin()
inline Foam::DLListBase::iterator
Foam::DLListBase::begin()
{
if (size())
{
@ -235,20 +259,20 @@ inline DLListBase::iterator DLListBase::begin()
}
else
{
return endIter;
return endIter_;
}
}
inline const DLListBase::iterator& DLListBase::end()
inline const Foam::DLListBase::iterator& Foam::DLListBase::end()
{
return endIter;
return endIter_;
}
// * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
inline DLListBase::const_iterator::const_iterator
inline Foam::DLListBase::const_iterator::const_iterator
(
const DLListBase& s,
const link* elmt
@ -259,20 +283,23 @@ inline DLListBase::const_iterator::const_iterator
{}
inline DLListBase::const_iterator::const_iterator(const iterator& iter)
inline Foam::DLListBase::const_iterator::const_iterator(const iterator& iter)
:
curList_(iter.curList_),
curElmt_(iter.curElmt_)
{}
inline void DLListBase::const_iterator::operator=(const const_iterator& iter)
inline void Foam::DLListBase::const_iterator::operator=
(
const const_iterator& iter
)
{
curElmt_ = iter.curElmt_;
}
inline bool DLListBase::const_iterator::operator==
inline bool Foam::DLListBase::const_iterator::operator==
(
const const_iterator& iter
) const
@ -281,7 +308,7 @@ inline bool DLListBase::const_iterator::operator==
}
inline bool DLListBase::const_iterator::operator!=
inline bool Foam::DLListBase::const_iterator::operator!=
(
const const_iterator& iter
) const
@ -290,13 +317,15 @@ inline bool DLListBase::const_iterator::operator!=
}
inline const DLListBase::link& DLListBase::const_iterator::operator*()
inline const Foam::DLListBase::link&
Foam::DLListBase::const_iterator::operator*()
{
return *curElmt_;
}
inline DLListBase::const_iterator& DLListBase::const_iterator::operator++()
inline Foam::DLListBase::const_iterator&
Foam::DLListBase::const_iterator::operator++()
{
if (curElmt_ == curList_.last_)
{
@ -311,7 +340,8 @@ inline DLListBase::const_iterator& DLListBase::const_iterator::operator++()
}
inline DLListBase::const_iterator DLListBase::const_iterator::operator++(int)
inline Foam::DLListBase::const_iterator
Foam::DLListBase::const_iterator::operator++(int)
{
const_iterator tmp = *this;
++*this;
@ -319,7 +349,8 @@ inline DLListBase::const_iterator DLListBase::const_iterator::operator++(int)
}
inline DLListBase::const_iterator DLListBase::begin() const
inline Foam::DLListBase::const_iterator
Foam::DLListBase::cbegin() const
{
if (size())
{
@ -327,19 +358,30 @@ inline DLListBase::const_iterator DLListBase::begin() const
}
else
{
return endConstIter;
return endConstIter_;
}
}
inline const DLListBase::const_iterator& DLListBase::end() const
inline const Foam::DLListBase::const_iterator&
Foam::DLListBase::cend() const
{
return endConstIter;
return endConstIter_;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::DLListBase::const_iterator
Foam::DLListBase::begin() const
{
return this->cbegin();
}
inline const Foam::DLListBase::const_iterator&
Foam::DLListBase::end() const
{
return endConstIter_;
}
} // End namespace Foam
// ************************************************************************* //

View file

@ -25,31 +25,25 @@ License
\*---------------------------------------------------------------------------*/
#include "error.H"
#include "SLListBase.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
SLListBase::iterator SLListBase::endIter
Foam::SLListBase::iterator Foam::SLListBase::endIter_
(
const_cast<SLListBase&>(static_cast<const SLListBase&>(SLListBase()))
);
SLListBase::const_iterator SLListBase::endConstIter
Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter_
(
static_cast<const SLListBase&>(SLListBase()),
reinterpret_cast<const link*>(NULL)
reinterpret_cast<const link*>(0)
);
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
void SLListBase::insert(SLListBase::link* a)
void Foam::SLListBase::insert(SLListBase::link* a)
{
nElmts_++;
@ -66,7 +60,7 @@ void SLListBase::insert(SLListBase::link* a)
}
void SLListBase::append(SLListBase::link* a)
void Foam::SLListBase::append(SLListBase::link* a)
{
nElmts_++;
@ -82,7 +76,7 @@ void SLListBase::append(SLListBase::link* a)
}
SLListBase::link* SLListBase::removeHead()
Foam::SLListBase::link* Foam::SLListBase::removeHead()
{
nElmts_--;
@ -108,7 +102,7 @@ SLListBase::link* SLListBase::removeHead()
}
SLListBase::link* SLListBase::remove(SLListBase::link* it)
Foam::SLListBase::link* Foam::SLListBase::remove(SLListBase::link* it)
{
SLListBase::iterator iter = begin();
SLListBase::link *prev = &(*iter);
@ -143,8 +137,4 @@ SLListBase::link* SLListBase::remove(SLListBase::link* it)
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -38,6 +38,7 @@ SourceFiles
#include "bool.H"
#include "label.H"
#include "uLabel.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -119,6 +120,9 @@ public:
//- Return number of elements in list
inline label size() const;
//- Return true if the list is empty
inline bool empty() const;
//- Return first entry
inline link* first();
@ -152,6 +156,9 @@ public:
//- Clear the list
inline void clear();
//- Transfer the contents of the argument into this List
// and annull the argument list.
inline void transfer(SLListBase&);
// STL iterator
@ -172,17 +179,17 @@ public:
//- Copy of the link
link curLink_;
// Private Member Functions
//- Construct for a given SLListBase with NULL element and link.
// Only used to create endIter
inline iterator(SLListBase&);
public:
//- Construct for a given SLListBase and link
inline iterator(SLListBase&, link*);
//- Construct for a given SLListBase
// setting element and link to NULL.
// Only used to create endIter
inline iterator(SLListBase&);
// Member operators
inline void operator=(const iterator&);
@ -197,10 +204,6 @@ public:
};
inline iterator begin();
//- iterator returned by end()
static iterator endIter;
inline const iterator& end();
@ -239,12 +242,20 @@ public:
inline const_iterator operator++(int);
};
inline const_iterator cbegin() const;
inline const const_iterator& cend() const;
inline const_iterator begin() const;
inline const const_iterator& end() const;
private:
//- iterator returned by end()
static iterator endIter_;
//- const_iterator returned by end()
static const_iterator endConstIter;
inline const const_iterator& end() const;
static const_iterator endConstIter_;
};

View file

@ -29,33 +29,28 @@ Description
#include "error.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
inline SLListBase::link::link()
inline Foam::SLListBase::link::link()
:
next_(0)
{}
inline SLListBase::link::link(link* p)
inline Foam::SLListBase::link::link(link* p)
:
next_(p)
{}
inline SLListBase::SLListBase()
inline Foam::SLListBase::SLListBase()
:
last_(0),
nElmts_(0)
{}
inline SLListBase::SLListBase(link* a)
inline Foam::SLListBase::SLListBase(link* a)
:
last_(a->next_ = a),
nElmts_(1)
@ -64,19 +59,26 @@ inline SLListBase::SLListBase(link* a)
// * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
inline SLListBase::~SLListBase()
inline Foam::SLListBase::~SLListBase()
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
inline label SLListBase::size() const
inline Foam::label Foam::SLListBase::size() const
{
return nElmts_;
}
inline SLListBase::link* SLListBase::first()
inline bool Foam::SLListBase::empty() const
{
return !nElmts_;
}
inline Foam::SLListBase::link*
Foam::SLListBase::first()
{
if (!nElmts_)
{
@ -88,7 +90,8 @@ inline SLListBase::link* SLListBase::first()
}
inline const SLListBase::link* SLListBase::first() const
inline const Foam::SLListBase::link*
Foam::SLListBase::first() const
{
if (!nElmts_)
{
@ -100,7 +103,8 @@ inline const SLListBase::link* SLListBase::first() const
}
inline SLListBase::link* SLListBase::last()
inline Foam::SLListBase::link*
Foam::SLListBase::last()
{
if (!nElmts_)
{
@ -112,7 +116,8 @@ inline SLListBase::link* SLListBase::last()
}
inline const SLListBase::link* SLListBase::last() const
inline const Foam::SLListBase::link*
Foam::SLListBase::last() const
{
if (!nElmts_)
{
@ -124,14 +129,26 @@ inline const SLListBase::link* SLListBase::last() const
}
inline void SLListBase::clear()
inline void Foam::SLListBase::clear()
{
nElmts_ = 0;
last_ = 0;
nElmts_ = 0;
}
inline SLListBase::link* SLListBase::remove(SLListBase::iterator& it)
inline void Foam::SLListBase::transfer(SLListBase& lst)
{
last_ = lst.last_;
nElmts_ = lst.nElmts_;
lst.clear();
}
inline Foam::SLListBase::link* Foam::SLListBase::remove
(
SLListBase::iterator& it
)
{
return remove(it.curElmt_);
}
@ -139,7 +156,7 @@ inline SLListBase::link* SLListBase::remove(SLListBase::iterator& it)
// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
inline SLListBase::iterator::iterator(SLListBase& s, link* elmt)
inline Foam::SLListBase::iterator::iterator(SLListBase& s, link* elmt)
:
curList_(s),
curElmt_(elmt),
@ -147,7 +164,7 @@ inline SLListBase::iterator::iterator(SLListBase& s, link* elmt)
{}
inline SLListBase::iterator::iterator(SLListBase& s)
inline Foam::SLListBase::iterator::iterator(SLListBase& s)
:
curList_(s),
curElmt_(NULL),
@ -155,32 +172,32 @@ inline SLListBase::iterator::iterator(SLListBase& s)
{}
inline void SLListBase::iterator::operator=(const iterator& iter)
inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
{
curElmt_ = iter.curElmt_;
curLink_ = iter.curLink_;
}
inline bool SLListBase::iterator::operator==(const iterator& iter) const
inline bool Foam::SLListBase::iterator::operator==(const iterator& iter) const
{
return curElmt_ == iter.curElmt_;
}
inline bool SLListBase::iterator::operator!=(const iterator& iter) const
inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
{
return curElmt_ != iter.curElmt_;
}
inline SLListBase::link& SLListBase::iterator::operator*()
inline Foam::SLListBase::link& Foam::SLListBase::iterator::operator*()
{
return *curElmt_;
}
inline SLListBase::iterator& SLListBase::iterator::operator++()
inline Foam::SLListBase::iterator& Foam::SLListBase::iterator::operator++()
{
if (curElmt_ == curList_.last_ || curList_.last_ == 0)
{
@ -196,7 +213,8 @@ inline SLListBase::iterator& SLListBase::iterator::operator++()
}
inline SLListBase::iterator SLListBase::iterator::operator++(int)
inline Foam::SLListBase::iterator
Foam::SLListBase::iterator::operator++(int)
{
iterator tmp = *this;
++*this;
@ -204,7 +222,8 @@ inline SLListBase::iterator SLListBase::iterator::operator++(int)
}
inline SLListBase::iterator SLListBase::begin()
inline Foam::SLListBase::iterator
Foam::SLListBase::begin()
{
if (size())
{
@ -212,20 +231,21 @@ inline SLListBase::iterator SLListBase::begin()
}
else
{
return endIter;
return endIter_;
}
}
inline const SLListBase::iterator& SLListBase::end()
inline const Foam::SLListBase::iterator&
Foam::SLListBase::end()
{
return endIter;
return endIter_;
}
// * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
inline SLListBase::const_iterator::const_iterator
inline Foam::SLListBase::const_iterator::const_iterator
(
const SLListBase& s,
const link* elmt
@ -236,20 +256,23 @@ inline SLListBase::const_iterator::const_iterator
{}
inline SLListBase::const_iterator::const_iterator(const iterator& iter)
inline Foam::SLListBase::const_iterator::const_iterator(const iterator& iter)
:
curList_(iter.curList_),
curElmt_(iter.curElmt_)
{}
inline void SLListBase::const_iterator::operator=(const const_iterator& iter)
inline void Foam::SLListBase::const_iterator::operator=
(
const const_iterator& iter
)
{
curElmt_ = iter.curElmt_;
}
inline bool SLListBase::const_iterator::operator==
inline bool Foam::SLListBase::const_iterator::operator==
(
const const_iterator& iter
) const
@ -258,7 +281,7 @@ inline bool SLListBase::const_iterator::operator==
}
inline bool SLListBase::const_iterator::operator!=
inline bool Foam::SLListBase::const_iterator::operator!=
(
const const_iterator& iter
) const
@ -267,13 +290,15 @@ inline bool SLListBase::const_iterator::operator!=
}
inline const SLListBase::link& SLListBase::const_iterator::operator*()
inline const Foam::SLListBase::link&
Foam::SLListBase::const_iterator::operator*()
{
return *curElmt_;
}
inline SLListBase::const_iterator& SLListBase::const_iterator::operator++()
inline Foam::SLListBase::const_iterator&
Foam::SLListBase::const_iterator::operator++()
{
if (curElmt_ == curList_.last_)
{
@ -288,7 +313,8 @@ inline SLListBase::const_iterator& SLListBase::const_iterator::operator++()
}
inline SLListBase::const_iterator SLListBase::const_iterator::operator++(int)
inline Foam::SLListBase::const_iterator
Foam::SLListBase::const_iterator::operator++(int)
{
const_iterator tmp = *this;
++*this;
@ -296,7 +322,8 @@ inline SLListBase::const_iterator SLListBase::const_iterator::operator++(int)
}
inline SLListBase::const_iterator SLListBase::begin() const
inline Foam::SLListBase::const_iterator
Foam::SLListBase::cbegin() const
{
if (size())
{
@ -304,19 +331,30 @@ inline SLListBase::const_iterator SLListBase::begin() const
}
else
{
return endConstIter;
return endConstIter_;
}
}
inline const SLListBase::const_iterator& SLListBase::end() const
inline const Foam::SLListBase::const_iterator&
Foam::SLListBase::cend() const
{
return endConstIter;
return endConstIter_;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
inline Foam::SLListBase::const_iterator
Foam::SLListBase::begin() const
{
return this->cbegin();
}
inline const Foam::SLListBase::const_iterator&
Foam::SLListBase::end() const
{
return endConstIter_;
}
} // End namespace Foam
// ************************************************************************* //

View file

@ -92,15 +92,6 @@ public:
}
// Check
//- Is the stack empty
bool empty() const
{
return this->size() == 0;
}
// Edit
//- Push an element onto the stack

View file

@ -92,15 +92,6 @@ public:
}
// Check
//- Is the stack empty
bool empty() const
{
return this->size() == 0;
}
// Edit
//- Push an element onto the stack

View file

@ -26,8 +26,7 @@ Class
Foam::BiIndirectList
Description
Indexes into left list (negative index) or right list (zero or positive
index).
Indexes into negList (negative index) or posList (zero or positive index).
SourceFiles
BiIndirectListI.H
@ -67,7 +66,7 @@ public:
(
const UList<T>& posList,
const UList<T>& negList,
const List<label>&
const UList<label>&
);
@ -76,14 +75,16 @@ public:
// Access
inline label size() const;
inline bool empty() const;
inline const UList<T>& posList() const;
inline const UList<T>& negList() const;
inline const List<label>& addressing() const;
inline List<label>& addressing();
//- Calculate index given whether index is into posList or negList
inline static label posIndex(const label i);
inline static label negIndex(const label i);
inline static label posIndex(const label);
inline static label negIndex(const label);
// Member Operators

View file

@ -31,7 +31,7 @@ inline Foam::BiIndirectList<T>::BiIndirectList
(
const UList<T>& posList,
const UList<T>& negList,
const List<label>& addr
const UList<label>& addr
)
:
posList_(const_cast<UList<T>&>(posList)),
@ -49,6 +49,13 @@ inline Foam::label Foam::BiIndirectList<T>::size() const
}
template<class T>
inline bool Foam::BiIndirectList<T>::empty() const
{
return addressing_.empty();
}
template<class T>
inline const Foam::UList<T>& Foam::BiIndirectList<T>::posList() const
{

View file

@ -26,15 +26,10 @@ License
#include "CompactListList.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
CompactListList<T>::CompactListList(const List<List<T> >& ll)
Foam::CompactListList<T>::CompactListList(const List<List<T> >& ll)
:
offsets_(ll.size())
{
@ -61,7 +56,10 @@ CompactListList<T>::CompactListList(const List<List<T> >& ll)
template<class T>
CompactListList<T>::CompactListList(const UList<label>& rowSizes)
Foam::CompactListList<T>::CompactListList
(
const UList<label>& rowSizes
)
:
offsets_(rowSizes.size())
{
@ -77,7 +75,11 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes)
template<class T>
CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
Foam::CompactListList<T>::CompactListList
(
const UList<label>& rowSizes,
const T& t
)
:
offsets_(rowSizes.size())
{
@ -93,25 +95,31 @@ CompactListList<T>::CompactListList(const UList<label>& rowSizes, const T& t)
template<class T>
CompactListList<T>::CompactListList(CompactListList<T>& cll, bool reUse)
Foam::CompactListList<T>::CompactListList
(
const Xfer<CompactListList<T> >& lst
)
{
transfer(lst());
}
template<class T>
Foam::CompactListList<T>::CompactListList
(
CompactListList<T>& lst,
bool reUse
)
:
offsets_(cll.offsets_, reUse),
m_(cll.m_, reUse)
offsets_(lst.offsets_, reUse),
m_(lst.m_, reUse)
{}
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
const CompactListList<T>& CompactListList<T>::null()
{
CompactListList<T>* nullPtr = reinterpret_cast<CompactListList<T>*>(NULL);
return *nullPtr;
}
template<class T>
void CompactListList<T>::setSize(const label nRows)
void Foam::CompactListList<T>::setSize(const label nRows)
{
if (nRows == 0)
{
@ -134,14 +142,19 @@ void CompactListList<T>::setSize(const label nRows)
template<class T>
void CompactListList<T>::setSize(const label nRows, const label nData)
void Foam::CompactListList<T>::setSize
(
const label nRows,
const label nData
)
{
offsets_.setSize(nRows);
m_.setSize(nData);
}
template<class T>
void CompactListList<T>::setSize
void Foam::CompactListList<T>::setSize
(
const label nRows,
const label nData,
@ -152,22 +165,9 @@ void CompactListList<T>::setSize
m_.setSize(nData, t);
}
template<class T>
labelList CompactListList<T>::sizes() const
{
labelList rowSizes(offsets_.size());
label prevOffset = 0;
forAll(offsets_, i)
{
rowSizes[i] = offsets_[i]-prevOffset;
prevOffset = offsets_[i];
}
return rowSizes;
}
template<class T>
void CompactListList<T>::setSize(const UList<label>& rowSizes)
void Foam::CompactListList<T>::setSize(const UList<label>& rowSizes)
{
offsets_.setSize(rowSizes.size());
@ -181,8 +181,24 @@ void CompactListList<T>::setSize(const UList<label>& rowSizes)
m_.setSize(sumSize);
}
template<class T>
void CompactListList<T>::clear()
Foam::labelList Foam::CompactListList<T>::sizes() const
{
labelList rowSizes(offsets_.size());
label prevOffset = 0;
forAll(offsets_, i)
{
rowSizes[i] = offsets_[i]-prevOffset;
prevOffset = offsets_[i];
}
return rowSizes;
}
template<class T>
void Foam::CompactListList<T>::clear()
{
offsets_.clear();
m_.clear();
@ -190,7 +206,7 @@ void CompactListList<T>::clear()
template<class T>
void CompactListList<T>::transfer(CompactListList<T>& a)
void Foam::CompactListList<T>::transfer(CompactListList<T>& a)
{
offsets_.transfer(a.offsets_);
m_.transfer(a.m_);
@ -200,34 +216,29 @@ void CompactListList<T>::transfer(CompactListList<T>& a)
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
List<List<T> > CompactListList<T>::operator()() const
Foam::List<Foam::List<T> > Foam::CompactListList<T>::operator()() const
{
List<List<T> > llt(offsets_.size());
List<List<T> > ll(offsets_.size());
label offsetPrev = 0;
forAll(offsets_, i)
{
List<T>& llti = llt[i];
List<T>& lst = ll[i];
llti.setSize(offsets_[i] - offsetPrev);
lst.setSize(offsets_[i] - offsetPrev);
forAll(llti, j)
forAll(lst, j)
{
llti[j] = m_[offsetPrev + j];
lst[j] = m_[offsetPrev + j];
}
offsetPrev = offsets_[i];
}
return llt;
return ll;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * IOStream operators * * * * * * * * * * * //
#include "CompactListListIO.C"

View file

@ -81,6 +81,11 @@ class CompactListList
public:
// Static Member Functions
//- Return a null CompactListList
inline static const CompactListList<T>& null();
// Constructors
//- Null constructor.
@ -103,6 +108,9 @@ public:
//- Construct given list of row-sizes
CompactListList(const UList<label>& rowSizes, const T&);
//- Construct by transferring the parameter contents
CompactListList(const Xfer<CompactListList<T> >&);
//- Construct as copy or re-use as specified.
CompactListList(CompactListList<T>&, bool reUse);
@ -113,16 +121,16 @@ public:
inline autoPtr<CompactListList<T> > clone() const;
// Member functions
//- Return a null CompactListList
static const CompactListList<T>& null();
// Member Functions
// Access
//- Return the primary size, i.e. the number of rows
inline label size() const;
//- Return true if the number of rows is zero
inline bool empty() const;
//- Return the offset table
inline const List<label>& offsets() const;
@ -148,19 +156,34 @@ public:
//- Reset sizes of CompactListList and value for new elements.
void setSize(const label nRows, const label nData, const T&);
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Reset size of CompactListList.
void setSize(const UList<label>& rowSizes);
//- Reset size of CompactListList.
// This form only allows contraction of the CompactListList.
inline void resize(const label nRows);
//- Reset size of CompactListList.
inline void resize(const label nRows, const label nData);
//- Reset sizes of CompactListList and value for new elements.
inline void resize(const label nRows, const label nData, const T&);
//- Reset size of CompactListList.
inline void resize(const UList<label>& rowSizes);
//- Clear the CompactListList, i.e. set sizes to zero.
void clear();
//- Return sizes (to be used e.g. for construction)
labelList sizes() const;
//- Transfer the contents of the argument CompactListList
// into this CompactListList and annull the argument list.
void transfer(CompactListList<T>&);
//- Transfer the contents to the Xfer container
inline Xfer<CompactListList<T> > xfer();
// Other

View file

@ -24,20 +24,20 @@ License
\*---------------------------------------------------------------------------*/
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
template<class T>
inline CompactListList<T>::CompactListList()
inline Foam::CompactListList<T>::CompactListList()
{}
template<class T>
inline CompactListList<T>::CompactListList(const label nRows, const label nData)
inline Foam::CompactListList<T>::CompactListList
(
const label nRows,
const label nData
)
:
offsets_(nRows, 0),
m_(nData)
@ -45,7 +45,7 @@ inline CompactListList<T>::CompactListList(const label nRows, const label nData)
template<class T>
inline CompactListList<T>::CompactListList
inline Foam::CompactListList<T>::CompactListList
(
const label nRows,
const label nData,
@ -58,7 +58,8 @@ inline CompactListList<T>::CompactListList
template<class T>
inline autoPtr<CompactListList<T> > CompactListList<T>::clone() const
inline Foam::autoPtr<Foam::CompactListList<T> >
Foam::CompactListList<T>::clone() const
{
return autoPtr<CompactListList<T> >(new CompactListList<T>(*this));
}
@ -67,38 +68,60 @@ inline autoPtr<CompactListList<T> > CompactListList<T>::clone() const
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class T>
inline label CompactListList<T>::size() const
inline const Foam::CompactListList<T>& Foam::CompactListList<T>::null()
{
return *reinterpret_cast< CompactListList<T>* >(0);
}
template<class T>
inline Foam::label Foam::CompactListList<T>::size() const
{
return offsets_.size();
}
template<class T>
inline const List<label>& CompactListList<T>::offsets() const
inline bool Foam::CompactListList<T>::empty() const
{
return offsets_.empty();
}
template<class T>
inline const Foam::List<Foam::label>& Foam::CompactListList<T>::offsets() const
{
return offsets_;
}
template<class T>
inline List<label>& CompactListList<T>::offsets()
inline Foam::List<Foam::label>& Foam::CompactListList<T>::offsets()
{
return offsets_;
}
template<class T>
inline const List<T>& CompactListList<T>::m() const
{
return m_;
}
template<class T>
inline List<T>& CompactListList<T>::m()
inline const Foam::List<T>& Foam::CompactListList<T>::m() const
{
return m_;
}
template<class T>
inline label CompactListList<T>::index(const label i, const label j) const
inline Foam::List<T>& Foam::CompactListList<T>::m()
{
return m_;
}
template<class T>
inline Foam::label Foam::CompactListList<T>::index
(
const label i,
const label j
) const
{
if (i == 0)
{
@ -110,14 +133,15 @@ inline label CompactListList<T>::index(const label i, const label j) const
}
}
template<class T>
inline label CompactListList<T>::whichRow(const label i) const
inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
{
if (i < 0 || i >= m_.size())
{
FatalErrorIn
(
"CompactListList<T>::whichRow(const label i) const"
"CompactListList<T>::whichRow(const label) const"
) << "Index " << i << " outside 0.." << m_.size()
<< abort(FatalError);
}
@ -133,30 +157,69 @@ inline label CompactListList<T>::whichRow(const label i) const
return -1;
}
template<class T>
inline label CompactListList<T>::whichColumn(const label row, const label i)
const
inline Foam::label Foam::CompactListList<T>::whichColumn
(
const label row,
const label i
) const
{
return i - index(row, 0);
}
template<class T>
inline Foam::Xfer<Foam::CompactListList<T> > Foam::CompactListList<T>::xfer()
{
return xferMove(*this);
}
template<class T>
inline void Foam::CompactListList<T>::resize(const label nRows)
{
this->setSize(nRows);
}
template<class T>
inline void Foam::CompactListList<T>::resize
(
const label nRows,
const label nData
)
{
this->setSize(nRows, nData);
}
template<class T>
inline void Foam::CompactListList<T>::resize
(
const label nRows,
const label nData,
const T& t
)
{
this->setSize(nRows, nData, t);
}
template<class T>
inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
{
this->setSize(rowSizes);
}
// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
template<class T>
inline UList<T> CompactListList<T>::operator[](const label i)
{
if (i == 0)
{
return UList<T>(m_.begin(), offsets_[i]);
}
else
{
return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
}
}
template<class T>
inline const UList<T> CompactListList<T>::operator[](const label i) const
inline Foam::UList<T> Foam::CompactListList<T>::operator[]
(
const label i
)
{
if (i == 0)
{
@ -170,13 +233,35 @@ inline const UList<T> CompactListList<T>::operator[](const label i) const
template<class T>
inline T& CompactListList<T>::operator()(const label i, const label j)
inline const Foam::UList<T> Foam::CompactListList<T>::operator[]
(
const label i
) const
{
if (i == 0)
{
return UList<T>(m_.begin(), offsets_[i]);
}
else
{
return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
}
}
template<class T>
inline T& Foam::CompactListList<T>::operator()
(
const label i,
const label j
)
{
return m_[index(i, j)];
}
template<class T>
inline const T& CompactListList<T>::operator()
inline const T& Foam::CompactListList<T>::operator()
(
const label i,
const label j
@ -187,14 +272,10 @@ inline const T& CompactListList<T>::operator()
template<class T>
inline void CompactListList<T>::operator=(const T& t)
inline void Foam::CompactListList<T>::operator=(const T& t)
{
m_ = t;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -27,15 +27,10 @@ License
#include "CompactListList.H"
#include "Istream.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
template<class T>
CompactListList<T>::CompactListList(Istream& is)
Foam::CompactListList<T>::CompactListList(Istream& is)
{
operator>>(is, *this);
}
@ -44,23 +39,19 @@ CompactListList<T>::CompactListList(Istream& is)
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
template<class T>
Istream& operator>>(Istream& is, CompactListList<T>& cll)
Foam::Istream& Foam::operator>>(Istream& is, CompactListList<T>& lst)
{
is >> cll.offsets_ >> cll.m_;
is >> lst.offsets_ >> lst.m_;
return is;
}
template<class T>
Ostream& operator<<(Ostream& os, const CompactListList<T>& cll)
Foam::Ostream& Foam::operator<<(Ostream& os, const CompactListList<T>& lst)
{
os << cll.offsets_ << cll.m_;
os << lst.offsets_ << lst.m_;
return os;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// ************************************************************************* //

View file

@ -28,26 +28,23 @@ License
// * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
// Construct from Istream
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>::DynamicList(Istream& is)
:
List<T>(is),
nextFree_(List<T>::size())
capacity_(List<T>::size())
{}
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::Ostream& Foam::operator<<
(
Foam::Ostream& os,
const Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& DL
Ostream& os,
const DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
)
{
const_cast<DynamicList<T, SizeInc, SizeMult, SizeDiv>&>(DL)
.setSize(DL.nextFree_);
os << static_cast<const List<T>&>(DL);
os << static_cast<const List<T>&>(lst);
return os;
}
@ -55,12 +52,12 @@ Foam::Ostream& Foam::operator<<
template<class T, unsigned SizeInc, unsigned SizeMult, unsigned SizeDiv>
Foam::Istream& Foam::operator>>
(
Foam::Istream& is,
Foam::DynamicList<T, SizeInc, SizeMult, SizeDiv>& DL
Istream& is,
DynamicList<T, SizeInc, SizeMult, SizeDiv>& lst
)
{
is >> static_cast<List<T>&>(DL);
DL.nextFree_ = DL.List<T>::size();
is >> static_cast<List<T>&>(lst);
lst.capacity_ = lst.List<T>::size();
return is;
}

Some files were not shown because too many files have changed in this diff Show more