UList: Rationalize assignment (shallow-copy vs deep-copy)

//- Disallow default shallow-copy assignment
    //
    //  Assignment of UList<T> may need to be either shallow (copy pointer)
    //  or deep (copy elements) depending on context or the particular type
    //  of list derived from UList and it is confusing and prone to error
    //  for the default assignment to be either.  The solution is to
    //  disallow default assignment and provide separate 'shallowCopy' and
    //  'deepCopy' member functions.
    void operator=(const UList<T>&) = delete;

    //- Copy the pointer held by the given UList.
    inline void shallowCopy(const UList<T>&);

    //- Copy elements of the given UList.
    void deepCopy(const UList<T>&);
This commit is contained in:
Henry Weller
2016-04-03 10:26:05 +01:00
parent 06f7682413
commit ac71f86574
31 changed files with 122 additions and 100 deletions

View File

@ -56,8 +56,8 @@ int main(int argc, char *argv[])
rowSizes[1] = row1.size();
cll1.resize(rowSizes);
cll1[0].assign(row0); //note: operator= will not work since UList
cll1[1].assign(row1);
cll1[0].deepCopy(row0);
cll1[1].deepCopy(row1);
Info<< "cll1:" << cll1 << endl;
forAll(cll1.m(), i)

View File

@ -2,7 +2,7 @@
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration |
\\ / A nd | Copyright (C) 2011-2015 OpenFOAM Foundation
\\ / A nd | Copyright (C) 2011-2016 OpenFOAM Foundation
\\/ M anipulation |
-------------------------------------------------------------------------------
License
@ -64,10 +64,8 @@ int main(int argc, char *argv[])
// Create field with my local data
pointField coords(globalPointSlavesMap.constructSize());
SubList<point>(coords, coupledPatch.nPoints()).assign
(
coupledPatch.localPoints()
);
SubList<point>(coords, coupledPatch.nPoints()) =
coupledPatch.localPoints();
// Exchange data. Apply positional transforms.
globalPointSlavesMap.distribute
@ -185,8 +183,7 @@ int main(int argc, char *argv[])
label nBnd = mesh.nFaces()-mesh.nInternalFaces();
pointField fc(globalPointBoundaryFacesMap.constructSize());
SubList<point>(fc, nBnd).assign
(
SubList<point>(fc, nBnd) =
primitivePatch
(
SubList<face>
@ -196,8 +193,7 @@ int main(int argc, char *argv[])
mesh.nInternalFaces()
),
mesh.points()
).faceCentres()
);
).faceCentres();
// Exchange data
globalPointBoundaryFacesMap.distribute