fixed writing out entries in advective bc
[OpenFOAM-1.6-ext.git] / src / OpenFOAM / db / dlLibraryTable / dlLibraryTable.C
blobdafff7d2a35093b0e4ccdb45ba6d8b47b3746663
1 /*---------------------------------------------------------------------------*\
2   =========                 |
3   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
4    \\    /   O peration     |
5     \\  /    A nd           | Copyright held by original author
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 the
13     Free Software Foundation; either version 2 of the License, or (at your
14     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, write to the Free Software Foundation,
23     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 \*---------------------------------------------------------------------------*/
27 #include "dlLibraryTable.H"
29 #include <dlfcn.h>
31 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
33 Foam::dlLibraryTable Foam::dlLibraryTable::loadedLibraries;
36 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
38 Foam::dlLibraryTable::dlLibraryTable()
40     HashTable<fileName, void*, Hash<void*> >()
44 Foam::dlLibraryTable::readDlLibrary::readDlLibrary
46     const dictionary& dict,
47     const word& libsEntry
50     open(dict, libsEntry);
54 // * * * * * * * * * * * * * * * * Destructor  * * * * * * * * * * * * * * * //
56 Foam::dlLibraryTable::~dlLibraryTable()
58     forAllIter(dlLibraryTable, *this, iter)
59     {
60         dlclose(iter.key());
61     }
65 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
67 bool Foam::dlLibraryTable::open(const fileName& functionLibName)
69     if (functionLibName.size())
70     {
71         void* functionLibPtr =
72             dlopen(functionLibName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
74 #ifdef darwin
75         if(!functionLibPtr && functionLibName.ext()=="so") {
76             fileName lName=functionLibName.lessExt()+".dylib";
77             functionLibPtr =
78                 dlopen(lName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
79         }
80 #endif
81         if (!functionLibPtr)
82         {
83             WarningIn
84             (
85                 "dlLibraryTable::open(const fileName& functionLibName)"
86             )   << "could not load " << dlerror()
87                 << endl;
89             return false;
90         }
91         else
92         {
93             if (!loadedLibraries.found(functionLibPtr))
94             {
95                 loadedLibraries.insert(functionLibPtr, functionLibName);
96                 return true;
97             }
98             else
99             {
100                 return false;
101             }
102         }
103     }
104     else
105     {
106         return false;
107     }
111 bool Foam::dlLibraryTable::open
113     const dictionary& dict,
114     const word& libsEntry
117     if (dict.found(libsEntry))
118     {
119         fileNameList libNames(dict.lookup(libsEntry));
121         bool allOpened = (libNames.size() > 0);
123         forAll(libNames, i)
124         {
125             allOpened = dlLibraryTable::open(libNames[i]) && allOpened;
126         }
128         return allOpened;
129     }
130     else
131     {
132         return false;
133     }
137 // ************************************************************************* //