Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
openfoam
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
350
Issues
350
List
Boards
Labels
Service Desk
Milestones
Merge Requests
8
Merge Requests
8
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Development
openfoam
Commits
e56e195a
Commit
e56e195a
authored
Jul 30, 2020
by
Mark Olesen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: support objectRegistry store of refPtr (as per tmp)
parent
487002d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
45 deletions
+92
-45
src/OpenFOAM/db/regIOobject/regIOobject.H
src/OpenFOAM/db/regIOobject/regIOobject.H
+35
-29
src/OpenFOAM/db/regIOobject/regIOobjectI.H
src/OpenFOAM/db/regIOobject/regIOobjectI.H
+57
-16
No files found.
src/OpenFOAM/db/regIOobject/regIOobject.H
View file @
e56e195a
...
@@ -42,6 +42,8 @@ SourceFiles
...
@@ -42,6 +42,8 @@ SourceFiles
#define regIOobject_H
#define regIOobject_H
#include "IOobject.H"
#include "IOobject.H"
#include "refPtr.H"
#include "tmp.H"
#include "typeInfo.H"
#include "typeInfo.H"
#include "stdFoam.H"
#include "stdFoam.H"
#include "OSspecific.H"
#include "OSspecific.H"
...
@@ -52,6 +54,8 @@ SourceFiles
...
@@ -52,6 +54,8 @@ SourceFiles
namespace
Foam
namespace
Foam
{
{
// Forward Declarations
namespace
functionEntries
namespace
functionEntries
{
{
class
codeStream
;
class
codeStream
;
...
@@ -59,7 +63,6 @@ namespace functionEntries
...
@@ -59,7 +63,6 @@ namespace functionEntries
namespace
fileOperations
namespace
fileOperations
{
{
class
uncollatedFileOperation
;
class
uncollatedFileOperation
;
class
masterUncollatedFileOperation
;
}
}
/*---------------------------------------------------------------------------*\
/*---------------------------------------------------------------------------*\
...
@@ -118,11 +121,9 @@ private:
...
@@ -118,11 +121,9 @@ private:
public:
public:
//- Declare friendship with classes that need access to
//- Friendship with classes needing access to masterOnlyReading
//- masterOnlyReading
friend
class
functionEntries
::
codeStream
;
friend
class
functionEntries
::
codeStream
;
friend
class
fileOperations
::
uncollatedFileOperation
;
friend
class
fileOperations
::
uncollatedFileOperation
;
friend
class
fileOperations
::
masterUncollatedFileOperation
;
// Static data
// Static data
...
@@ -184,41 +185,46 @@ public:
...
@@ -184,41 +185,46 @@ public:
// \return true if now ownedByRegistry
// \return true if now ownedByRegistry
inline
bool
store
();
inline
bool
store
();
//- Register object pointer with its registry
//- Transfer pointer ownership to its registry.
//- and transfer ownership to the registry.
// \return reference to the stored object
// \return reference to the object.
template
<
class
Type
>
template
<
class
Type
>
inline
static
Type
&
store
(
Type
*
p
);
inline
static
Type
&
store
(
Type
*
p
);
//- Register object pointer with its registry
//- Transfer pointer ownership to its registry.
//- and transfer ownership to the registry.
// Resets (clears) the parameter.
// Clears the autoPtr parameter.
// \return reference to the stored object
// \return reference to the object.
template
<
class
Type
>
template
<
class
Type
>
inline
static
Type
&
store
(
autoPtr
<
Type
>&
a
ptr
);
inline
static
Type
&
store
(
autoPtr
<
Type
>&
ptr
);
//- Register object pointer with its registry
//- Transfer pointer ownership to its registry.
//- and transfer ownership to the registry.
// Resets (clears) the parameter.
// Clears the autoPtr parameter.
// \return reference to the stored object
// \return reference to the object.
template
<
class
Type
>
inline
static
Type
&
store
(
autoPtr
<
Type
>&&
ptr
);
//- Transfer pointer ownership to its registry.
// Changes parameter from PTR to CREF (do not rely on this).
// \return reference to the stored object
template
<
class
Type
>
inline
static
Type
&
store
(
refPtr
<
Type
>&
ptr
);
//- Transfer pointer ownership to its registry.
// Changes parameter from PTR to CREF (do not rely on this).
// \return reference to the stored object
template
<
class
Type
>
template
<
class
Type
>
inline
static
Type
&
store
(
autoPtr
<
Type
>&&
a
ptr
);
inline
static
Type
&
store
(
refPtr
<
Type
>&&
ptr
);
//- Register temporary pointer with its registry
//- Transfer pointer ownership to its registry.
//- and transfer ownership of pointer to the registry.
// Changes parameter from PTR to CREF (do not rely on this).
// After the call, tmp parameter changes from PTR to CREF.
// \return reference to the stored object
//
// \return reference to the object.
template
<
class
Type
>
template
<
class
Type
>
inline
static
Type
&
store
(
tmp
<
Type
>&
t
ptr
);
inline
static
Type
&
store
(
tmp
<
Type
>&
ptr
);
//- Register temporary pointer with its registry
//- Transfer pointer ownership to its registry.
//- and transfer ownership of pointer to the registry.
// Changes parameter from PTR to CREF (do not rely on this).
// After the call, the tmp parameter content is \em unspecified.
// \return reference to the stored object
//
// \return reference to the object.
template
<
class
Type
>
template
<
class
Type
>
inline
static
Type
&
store
(
tmp
<
Type
>&&
t
ptr
);
inline
static
Type
&
store
(
tmp
<
Type
>&&
ptr
);
//- Release ownership of this object from its registry
//- Release ownership of this object from its registry
// \param unregister optionally set as non-registered
// \param unregister optionally set as non-registered
...
...
src/OpenFOAM/db/regIOobject/regIOobjectI.H
View file @
e56e195a
...
@@ -75,47 +75,47 @@ inline Type& Foam::regIOobject::store(Type* p)
...
@@ -75,47 +75,47 @@ inline Type& Foam::regIOobject::store(Type* p)
template
<
class
Type
>
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
autoPtr
<
Type
>&
a
ptr
)
inline
Type
&
Foam
::
regIOobject
::
store
(
autoPtr
<
Type
>&
ptr
)
{
{
// Pass management to objectRegistry
// Pass management to objectRegistry
return
store
(
a
ptr
.
release
());
return
store
(
ptr
.
release
());
}
}
template
<
class
Type
>
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
autoPtr
<
Type
>&&
a
ptr
)
inline
Type
&
Foam
::
regIOobject
::
store
(
autoPtr
<
Type
>&&
ptr
)
{
{
// Pass management to objectRegistry
// Pass management to objectRegistry
return
store
(
a
ptr
.
release
());
return
store
(
ptr
.
release
());
}
}
template
<
class
Type
>
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
tmp
<
Type
>&
t
ptr
)
inline
Type
&
Foam
::
regIOobject
::
store
(
refPtr
<
Type
>&
ptr
)
{
{
Type
*
p
=
nullptr
;
Type
*
p
=
nullptr
;
if
(
tptr
.
isTmp
())
if
(
ptr
.
is_pointer
())
{
{
//
P
ass management to objectRegistry
//
Acquire ownership, p
ass management to objectRegistry
p
=
t
ptr
.
ptr
();
p
=
ptr
.
ptr
();
store
(
p
);
store
(
p
);
//
Adjust tmp<> access to use
the stored reference
//
Change parameter to access
the stored reference
t
ptr
.
cref
(
*
p
);
ptr
.
cref
(
*
p
);
}
}
else
else
{
{
// Taking ownership of
a const-ref
does not make much sense.
// Taking ownership of
reference
does not make much sense.
// - Storing the object won't actually do so, it will be removed
// - Storing the object won't actually do so, it will be removed
// when the original object goes out of scope.
// when the original object goes out of scope.
// - Storing a clone may not be what we want.
// - Storing a clone may not be what we want.
p
=
t
ptr
.
get
();
p
=
ptr
.
get
();
WarningInFunction
WarningInFunction
<<
"Refuse to store
tmp to const-ref
: "
<<
p
->
name
()
<<
"Refuse to store
reference
: "
<<
p
->
name
()
<<
". Likely indicates a coding error
\n
"
;
<<
". Likely indicates a coding error
\n
"
;
}
}
...
@@ -124,10 +124,51 @@ inline Type& Foam::regIOobject::store(tmp<Type>& tptr)
...
@@ -124,10 +124,51 @@ inline Type& Foam::regIOobject::store(tmp<Type>& tptr)
template
<
class
Type
>
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
tmp
<
Type
>&&
t
ptr
)
inline
Type
&
Foam
::
regIOobject
::
store
(
refPtr
<
Type
>&&
ptr
)
{
{
// Treat like a normal reference
// Forward as named reference, which also does a move
return
store
(
tptr
);
return
store
(
ptr
);
}
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
tmp
<
Type
>&
ptr
)
{
Type
*
p
=
nullptr
;
if
(
ptr
.
is_pointer
())
{
// Acquire ownership, pass management to objectRegistry
p
=
ptr
.
ptr
();
store
(
p
);
// Change parameter to access the stored reference
ptr
.
cref
(
*
p
);
}
else
{
// Taking ownership of reference does not make much sense.
// - Storing the object won't actually do so, it will be removed
// when the original object goes out of scope.
// - Storing a clone may not be what we want.
p
=
ptr
.
get
();
WarningInFunction
<<
"Refuse to store reference: "
<<
p
->
name
()
<<
". Likely indicates a coding error
\n
"
;
}
return
*
p
;
}
template
<
class
Type
>
inline
Type
&
Foam
::
regIOobject
::
store
(
tmp
<
Type
>&&
ptr
)
{
// Forward as named reference, which also does a move
return
store
(
ptr
);
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment