BUG: UListIO: byteSize overflowing on really big faceLists
[OpenFOAM-2.0.x.git] / src / OpenFOAM / db / dynamicLibrary / dlLibraryTable / dlLibraryTable.C
blob48bc178ac6a3749157d7bc35c925ba02ffaa45fa
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright (C) 2011 OpenFOAM Foundation
6      \\/     M anipulation  |
7 -------------------------------------------------------------------------------
8 License
9     This file is part of OpenFOAM.
11     OpenFOAM is free software: you can redistribute it and/or modify it
12     under the terms of the GNU General Public License as published by
13     the Free Software Foundation, either version 3 of the License, or
14     (at your option) any later version.
16     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
19     for more details.
21     You should have received a copy of the GNU General Public License
22     along with OpenFOAM.  If not, see <http://www.gnu.org/licenses/>.
24 \*---------------------------------------------------------------------------*/
26 #include "dlLibraryTable.H"
27 #include "OSspecific.H"
28 #include "long.H"
30 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
32 defineTypeNameAndDebug(Foam::dlLibraryTable, 0);
35 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
37 Foam::dlLibraryTable::dlLibraryTable()
41 Foam::dlLibraryTable::dlLibraryTable
43     const dictionary& dict,
44     const word& libsEntry
47     open(dict, libsEntry);
51 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
53 Foam::dlLibraryTable::~dlLibraryTable()
55     forAllReverse(libPtrs_, i)
56     {
57         if (libPtrs_[i])
58         {
59             if (debug)
60             {
61                 Info<< "dlLibraryTable::~dlLibraryTable() : closing "
62                     << libNames_[i]
63                     << " with handle " << long(libPtrs_[i]) << endl;
64             }
65             dlClose(libPtrs_[i]);
66         }
67     }
71 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
73 bool Foam::dlLibraryTable::open
75     const fileName& functionLibName,
76     const bool verbose
79     if (functionLibName.size())
80     {
81         void* functionLibPtr = dlOpen(functionLibName, verbose);
83         if (debug)
84         {
85             Info<< "dlLibraryTable::open : opened " << functionLibName
86                 << " resulting in handle " << long(functionLibPtr) << endl;
87         }
89         if (!functionLibPtr)
90         {
91             if (verbose)
92             {
93                 WarningIn
94                 (
95                     "dlLibraryTable::open(const fileName&, const bool)"
96                 )   << "could not load " << functionLibName
97                     << endl;
98             }
100             return false;
101         }
102         else
103         {
104             libPtrs_.append(functionLibPtr);
105             libNames_.append(functionLibName);
106             return true;
107         }
108     }
109     else
110     {
111         return false;
112     }
116 bool Foam::dlLibraryTable::close
118     const fileName& functionLibName,
119     const bool verbose
122     label index = -1;
123     forAllReverse(libNames_, i)
124     {
125         if (libNames_[i] == functionLibName)
126         {
127             index = i;
128             break;
129         }
130     }
132     if (index != -1)
133     {
134         if (debug)
135         {
136             Info<< "dlLibraryTable::close : closing " << functionLibName
137                 << " with handle " << long(libPtrs_[index]) << endl;
138         }
140         bool ok = dlClose(libPtrs_[index]);
142         libPtrs_[index] = NULL;
143         libNames_[index] = fileName::null;
145         if (!ok)
146         {
147             if (verbose)
148             {
149                 WarningIn
150                 (
151                     "dlLibraryTable::close(const fileName&)"
152                 )   << "could not close " << functionLibName
153                     << endl;
154             }
156             return false;
157         }
159         return true;
160     }
161     return false;
165 void* Foam::dlLibraryTable::findLibrary(const fileName& functionLibName)
167     label index = -1;
168     forAllReverse(libNames_, i)
169     {
170         if (libNames_[i] == functionLibName)
171         {
172             index = i;
173             break;
174         }
175     }
177     if (index != -1)
178     {
179         return libPtrs_[index];
180     }
181     return NULL;
185 bool Foam::dlLibraryTable::open
187     const dictionary& dict,
188     const word& libsEntry
191     if (dict.found(libsEntry))
192     {
193         fileNameList libNames(dict.lookup(libsEntry));
195         bool allOpened = !libNames.empty();
197         forAll(libNames, i)
198         {
199             allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
200         }
202         return allOpened;
203     }
204     else
205     {
206         return false;
207     }
211 // ************************************************************************* //