Merge branch 'master' of ssh://git.code.sf.net/p/foam-extend/foam-extend-3.2
[foam-extend-3.2.git] / src / foam / db / postfixedSubRegistry / postfixedSubRegistry.C
blob18af82075b2d5d4b3a4ae75895e9f7be70311ff3
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | foam-extend: Open Source CFD
4    \\    /   O peration     | Version:     3.2
5     \\  /    A nd           | Web:         http://www.foam-extend.org
6      \\/     M anipulation  | For copyright notice see file Copyright
7 -------------------------------------------------------------------------------
8 License
9     This file is part of foam-extend.
11     foam-extend is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by the
13     Free Software Foundation, either version 3 of the License, or (at your
14     option) any later version.
16     foam-extend is distributed in the hope that it will be useful, but
17     WITHOUT ANY WARRANTY; without even the implied warranty of
18     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19     General Public License for more details.
21     You should have received a copy of the GNU General Public License
22     along with foam-extend.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "postfixedSubRegistry.H"
27 #include "Pstream.H"
29 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
31 namespace Foam
33     defineTypeNameAndDebug(postfixedSubRegistry, 0);
37 // * * * * * * * * * * * * * * * * Constructors *  * * * * * * * * * * * * * //
39 Foam::postfixedSubRegistry::postfixedSubRegistry
41     const IOobject& io,
42     const label nIoObjects
45     objectRegistry(io, io.db().dbDir(), nIoObjects)
47     writeOpt() = IOobject::NO_WRITE;
51 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
53 Foam::postfixedSubRegistry::~postfixedSubRegistry()
55     objectRegistry::clear();
59 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
61 Foam::fileName Foam::postfixedSubRegistry::mangleFileName(const fileName& fName) const
63     return fileName(fName+name());
67 bool Foam::postfixedSubRegistry::checkIn(regIOobject& io) const
69     if (postfixedSubRegistry::debug)
70     {
71         Pout<< "postfixedSubRegistry::checkIn(regIOobject&) : "
72             << name() << " : checking in " << io.name()
73             << endl;
74     }
76     word demangledName = io.name();
77     demangledName = demangledName(io.name().size() - name().size());
79     // Check into Mesh-Registry under full name
80     const_cast<objectRegistry&>(parent()).insert(io.name(), &io);
82     // Check into Mesh-Registry under short name
83     return const_cast<postfixedSubRegistry&>(*this).insert(demangledName, &io);;
87 bool Foam::postfixedSubRegistry::checkOut(regIOobject& io) const
89     word demangledName = io.name();
90     demangledName = demangledName(io.name().size() - name().size());
91     iterator iter = const_cast<postfixedSubRegistry&>(*this).find(demangledName);
92     iterator iterPar = const_cast<objectRegistry&>(parent()).find(io.name());
94     if (iter != end() && iterPar != end())
95     {
96         if (postfixedSubRegistry::debug)
97         {
98             Pout<< "postfixedSubRegistry::checkOut(regIOobject&) : "
99                 << name() << " : checking out " << io.name()
100                 << endl;
101         }
103         if (iter() != &io || iterPar() != &io)
104         {
105             if (postfixedSubRegistry::debug)
106             {
107                 WarningIn("postfixedSubRegistry::checkOut(regIOobject&)")
108                     << name() << " : attempt to checkOut copy of " << io.name()
109                     << endl;
110             }
112             return false;
113         }
114         else
115         {
116             bool hasErased =
117                 const_cast<postfixedSubRegistry&>(*this).erase(iter)
118                 && const_cast<objectRegistry&>(parent()).erase(iterPar);
120             if (io.ownedByRegistry())
121             {
122                 delete iter();
123             }
125             return hasErased;
126         }
127     }
128     else
129     {
130         if (postfixedSubRegistry::debug)
131         {
132             Pout<< "postfixedSubRegistry::checkOut(regIOobject&) : "
133                 << name() << " : could not find " << io.name()
134                 << " in registry " << name()
135                 << endl;
136         }
138         return false;
139     }
143 // ************************************************************************* //