Commit 3d608bf0 authored by Mark Olesen's avatar Mark Olesen
Browse files

ENH: remove reliance on the Xfer class (issue #639)

This class is largely a pre-C++11 holdover. It is now possible to
simply use move construct/assignment directly.

In a few rare cases (eg, polyMesh::resetPrimitives) it has been
replaced by an autoPtr.
parent 57291e86
Info<< "Constructing single cell mesh" << nl << endl;
labelList owner(6, label(0));
labelList neighbour(0);
pointField points(8);
points[0] = vector(0, 0, 0);
points[1] = vector(1, 0, 0);
......@@ -24,10 +21,10 @@ fvMesh mesh
runTime,
IOobject::READ_IF_PRESENT
),
xferMove<pointField>(points),
faces.xfer(),
owner.xfer(),
neighbour.xfer()
std::move(points),
std::move(faces),
labelList(6, Zero), // owner
labelList() // neighbour
);
List<polyPatch*> patches(1);
......
......@@ -180,7 +180,7 @@ int main(int argc, char *argv[])
{
std::cout<< "iter: " << typeid(*iter).name() << '\n';
Info<< "elem = " << *(*iter) << endl;
// Info<< "elem = " << *(*iter) << endl;
}
std::cout<< "iter type: "
......
......@@ -194,13 +194,13 @@ int main(int argc, char *argv[])
printInfo("dlC", dlC, true);
List<label> lstB(dlC.xfer());
List<label> lstB(std::move(dlC));
Info<< "Transferred to normal list via the xfer() method" << endl;
Info<< "Move construct to normal list" << endl;
printInfo("lstB", lstB, true);
printInfo("dlC", dlC, true);
DynamicList<label> dlD(lstB.xfer());
DynamicList<label> dlD(std::move(lstB));
Info<< "Transfer construct from normal list" << endl;
printInfo("lstB", lstB, true);
......@@ -279,7 +279,7 @@ int main(int argc, char *argv[])
Info<< "list in: " << flatOutput(list1) << nl
<< "list out: " << flatOutput(list2) << endl;
input2 = std::move(identity(15));
input2 = identity(15); // don't need std::move() on temporary object
list2 = std::move(input2);
Info<< "list in: " << flatOutput(input2) << nl
<< "list out: " << flatOutput(list2) << endl;
......
......@@ -102,7 +102,14 @@ int main(int argc, char *argv[])
Info<< "transfer contents to a List" << endl;
IListStream ibuf(obuf.xfer());
IListStream ibuf;
// Reclaim data storage from OListStream -> IListStream
{
List<char> data;
obuf.swap(data);
ibuf.swap(data);
}
Info<< nl;
Info<< nl << "input string:";
......
......@@ -95,7 +95,7 @@ int main(int argc, char *argv[])
inplaceReverseList(addresses);
idl1.resetAddressing(addresses.xfer());
idl1.resetAddressing(std::move(addresses));
printInfo(idl1);
......
......@@ -190,8 +190,8 @@ int main(int argc, char *argv[])
list2.setSize(10, vector(1, 2, 3));
Info<< "list2: " << list2 << endl;
List<vector> list3(list2.xfer());
Info<< "Transferred via the xfer() method" << endl;
List<vector> list3(std::move(list2));
Info<< "Move construct" << endl;
Info<< "list2: " << list2 << nl
<< "list3: " << list3 << endl;
......
......@@ -129,7 +129,13 @@ int main(int argc, char *argv[])
Info<< "transfer contents to a List or IListStream" << nl;
IListStream ibuf(obuf.xfer());
IListStream ibuf;
// Reclaim data storage from OListStream -> IListStream
{
List<char> data;
obuf.swap(data);
ibuf.swap(data);
}
Info<<"original:";
printInfo(obuf);
......@@ -141,6 +147,7 @@ int main(int argc, char *argv[])
// Create from other storage types
List<char> written;
Info<< nl;
{
Info<<"create std::move(List)" << endl;
......@@ -163,35 +170,9 @@ int main(int argc, char *argv[])
toString(Info, list) << endl;
printInfo(buf1);
}
Info<< nl;
List<char> written;
{
Info<<"create List.xfer()" << endl;
List<char> list(16, 'B');
Info<<"input:";
toString(Info, list) << endl;
OListStream buf1(list.xfer());
for (label i = 0; i < 26; ++i)
{
buf1 << char('A' + i);
}
for (label i = 0; i < 26; ++i)
{
buf1 << char('a' +i);
}
Info<<"orig:";
toString(Info, list) << endl;
printInfo(buf1);
// Move back to written
written = buf1.xfer();
buf1.swap(written);
printInfo(buf1);
}
......
......@@ -147,8 +147,8 @@ int main(int argc, char *argv[])
Info<<"list1: " << list1 << endl;
PtrList<Scalar> list3(list1.xfer());
Info<< "Transferred via the xfer() method" << endl;
PtrList<Scalar> list3(std::move(list1));
Info<<"Move constructed" << endl;
Info<<"list1: " << list1 << nl
<<"list2: " << list2 << nl
......
......@@ -71,7 +71,7 @@ int main(int argc, char *argv[])
<< "keys: " << dict1.keys() << nl
<< "patterns: " << dict1.keys(true) << endl;
dictionary dict2(dict1.xfer());
dictionary dict2(std::move(dict1));
Info<< "dict1.toc(): " << dict1.name() << " " << dict1.toc() << nl
<< "dict2.toc(): " << dict2.name() << " " << dict2.toc()
......
......@@ -51,19 +51,20 @@ int main(int argc, char *argv[])
const scalar instanceValue(0.005);
IOobject io
IOmapDistributePolyMesh map
(
"procAddressing",
instance,
fvMesh::meshSubDir,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
IOobject
(
"procAddressing",
instance,
fvMesh::meshSubDir,
mesh,
IOobject::MUST_READ,
IOobject::NO_WRITE,
false
)
);
IOmapDistributePolyMesh map(io);
{
// Load the instance mesh
runTime.setTime(instanceValue, 0);
......@@ -112,7 +113,6 @@ int main(int argc, char *argv[])
}
}
{
const mapDistribute& cellMap = map.cellMap();
pointField cc(mesh.cellCentres());
......
......@@ -91,7 +91,7 @@ int main(int argc, char *argv[])
runTime,
Foam::IOobject::NO_READ
),
Xfer<pointField>(points),
std::move(points),
shapes,
boundaryFaces,
boundaryPatchNames,
......
......@@ -111,7 +111,7 @@ void testMapDistribute()
}
// Construct distribute map (destructively)
mapDistribute map(constructSize, sendMap.xfer(), recvMap.xfer());
mapDistribute map(constructSize, std::move(sendMap), std::move(recvMap));
// Distribute complexData
map.distribute(complexData);
......
......@@ -246,15 +246,16 @@ int main(int argc, char *argv[])
writeFaceFaces(localPoints, localFaces, faceFaces);
}
// Test construction from Xfer
// Move construct
{
faceList patchFaces = patch;
pointField allPoints = patch.points();
PrimitivePatch<face, List, pointField, point> storedPatch
(
patchFaces.xfer(),
allPoints.xfer()
patchFaces,
allPoints,
true
);
}
......
......@@ -413,9 +413,9 @@ int main(int argc, char *argv[])
surf.writeStats(Info);
Info<< endl;
ModifiableMeshedSurface<face> tsurf(surf.xfer());
// ModifiableMeshedSurface<face> tsurf;
// tsurf.reset(surf.xfer());
ModifiableMeshedSurface<face> tsurf(std::move(surf));
// ModifiableMeshedSurface<face> xtsurf;
// xtsurf.transfer(surf);
Info<< "in-progress" << nl;
surf.writeStats(Info);
......@@ -515,7 +515,7 @@ int main(int argc, char *argv[])
IOobject::NO_WRITE,
false
),
surf.xfer()
std::move(surf)
);
Info<< "writing surfMesh as well: " << surfOut.objectPath() << endl;
......@@ -546,7 +546,6 @@ int main(int argc, char *argv[])
surfOut.setInstance(runTime.timeName());
Info<< "writing surfMesh again well: " << surfOut.objectPath()
<< endl;
surfOut.write();
......
......@@ -214,9 +214,9 @@ int main(int argc, char *argv[])
runTime.timeName(),
runTime
),
xferCopy(mesh.points()), // could we safely re-use the data?
xferCopy(mesh.faces()),
xferCopy(mesh.cells())
pointField(mesh.points()), // Could we safely re-use the data?
faceList(mesh.faces()),
cellList(mesh.cells())
);
// Add the boundary patches
......
......@@ -446,27 +446,23 @@ int main(int argc, char *argv[])
const word defaultFacesName = "defaultFaces";
word defaultFacesType = emptyPolyPatch::typeName;
// Create dummy mesh just to find out what are internal/external
// faces
autoPtr<polyMesh> dummyMesh
// Create dummy mesh just to find out what are internal/external faces
auto dummyMesh = autoPtr<polyMesh>::New
(
new polyMesh
IOobject
(
IOobject
(
"dummyMesh",
runTime.constant(),
runTime
),
xferCopy(points),
cellShapes,
faceListList(0),
wordList(0),
wordList(0),
defaultFacesName,
defaultFacesType,
wordList(0)
)
"dummyMesh",
runTime.constant(),
runTime
),
pointField(points), // copy
cellShapes,
faceListList(),
wordList(),
wordList(),
defaultFacesName,
defaultFacesType,
wordList()
);
......@@ -605,7 +601,7 @@ int main(int argc, char *argv[])
runTime.constant(),
runTime
),
xferMove(points),
std::move(points),
cellShapes,
patchFaces,
patchNames,
......@@ -615,7 +611,7 @@ int main(int argc, char *argv[])
);
if (cellTypes.size() > 0 || patchNames.size() > 0)
if (cellTypes.size() || patchNames.size())
{
DynamicList<pointZone*> pz;
DynamicList<faceZone*> fz;
......
......@@ -739,7 +739,7 @@ int main(int argc, char *argv[])
runTime.constant(),
runTime
),
xferMove(points),
std::move(points),
cellShapes,
boundary,
patchNames,
......
......@@ -945,10 +945,7 @@ int main(int argc, char *argv[])
runTime.constant(),
runTime
),
xferCopy(pointField()),
xferCopy(faceList()),
xferCopy(labelList()),
xferCopy(labelList())
Zero
);
......
......@@ -1175,7 +1175,7 @@ int main(int argc, char *argv[])
runTime.constant(),
runTime
),
xferMove(points),
std::move(points),
cellShapes,
patches,
patchNames,
......
......@@ -853,7 +853,7 @@ int main(int argc, char *argv[])
runTime.constant(),
runTime
),
xferMove(points),
std::move(points),
cells,
boundary,
patchNames,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment