Salome HOME
Fix bug SMESH5528 (The compilation fails on the file SMESHDriver.cxx using gcc2.95.4).
[modules/smesh.git] / src / Driver / SMESHDriver.cxx
1 //  SMESH Driver : implementation of driver for reading and writing     
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21
22 #include "SMESHDriver.h"
23
24 #include <dlfcn.h>
25 #include <utilities.h>
26
27 Document_Reader* SMESHDriver::GetDocumentReader(string Extension)
28 {
29         // if there is not document reader in the driver create a default
30         // one with the mesh reader.
31         Document_Reader * docReader=
32                 (Document_Reader*)getMeshDocumentDriver(Extension);
33
34         if(docReader==NULL)
35         {
36                 Mesh_Reader * reader=GetMeshReader(Extension);
37                 if(reader==NULL)
38                 {
39                 MESSAGE("No driver known for this extension");
40                         return NULL;
41                 }
42                 return new Document_Reader(reader);
43         }
44         else return docReader;
45 }
46
47 Document_Writer* SMESHDriver::GetDocumentWriter(string Extension)
48 {
49         Mesh_Writer * writer=GetMeshWriter(Extension);
50         if(writer==NULL)
51         {
52         MESSAGE("No driver known for this extension");
53                 return NULL;
54         }
55         return new Document_Writer(writer);
56 }
57
58 Mesh_Reader* SMESHDriver::GetMeshReader(string extension)
59 {
60         void * driver = getMeshDriver(extension, string("Reader"));
61         return (Mesh_Reader*)driver;
62 }
63
64 Mesh_Writer* SMESHDriver::GetMeshWriter(string extension)
65 {
66         void * driver = getMeshDriver(extension, string("Writer"));
67         return (Mesh_Writer*)driver;
68 }
69
70 void * SMESHDriver::getMeshDriver(string extension, string type)
71 {
72         string libName = string("libMeshDriver")+extension+string(".so");
73         void * handle = dlopen(libName.c_str(), RTLD_LAZY);
74         if(!handle)
75         {
76                 cerr << dlerror() << endl;
77                 return NULL;
78         }
79         else
80         {
81                 void * (*factory)();
82                 string symbol = string("SMESH_create")+extension+string("Mesh")+type;
83                 factory = (void * (*)()) dlsym(handle, symbol.c_str());
84                 if(factory==NULL)
85                 {
86                         cerr << dlerror() << endl;
87                         return NULL;
88                 }
89                 else return factory();
90         }
91 }
92
93 void * SMESHDriver::getMeshDocumentDriver(string extension)
94 {
95         string libName = string("libMeshDriver")+extension+string(".so");
96         void * handle = dlopen(libName.c_str(), RTLD_LAZY);
97         if(!handle)
98         {
99                 cerr << dlerror() << endl;
100                 return NULL;
101         }
102         else
103         {
104                 void * (*factory)();
105                 string symbol = string("SMESH_create")+extension+string("DocumentReader");
106                 factory = (void * (*)()) dlsym(handle, symbol.c_str());
107                 if(factory==NULL)
108                 {
109                         cerr << dlerror() << endl;
110                         return NULL;
111                 }
112                 else return factory();
113         }
114 }