]> SALOME platform Git repositories - modules/kernel.git/blob - src/MEDWrapper/Factory/MED_Factory.cxx
Salome HOME
PR: merge from tag mergeto_trunk_18Jan05
[modules/kernel.git] / src / MEDWrapper / Factory / MED_Factory.cxx
1 //  
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 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : 
27 //  $Header$
28
29 #include "MED_Factory.hxx"
30 #include "MED_Utilities.hxx"
31 #include "MED_V2_2_Wrapper.hxx"
32 #include "MED_V2_1_Wrapper.hxx"
33
34 #include <stdio.h>
35
36 extern "C"{
37 #include <med.h>
38 }
39
40 #ifdef _DEBUG_
41 static int MYDEBUG = 0;
42 #else
43 static int MYDEBUG = 0;
44 #endif
45
46 namespace MED{
47   
48   EVersion GetVersionId(const std::string& theFileName)
49   {
50     EVersion aVersion = eVUnknown;
51     char* aFileName = const_cast<char*>(theFileName.c_str());
52     med_idt aFid = MEDouvrir(aFileName,MED_LECTURE);
53     MSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aFid = "<<aFid<<endl);
54     if(aFid >= 0){
55       med_int aMajor, aMinor, aRelease;
56       med_err aRet = MEDversionLire(aFid,&aMajor,&aMinor,&aRelease);
57       INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aRet = "<<aRet<<endl);
58       if(aRet >= 0){
59         if(aMajor >= 2 && aMinor >= 2)
60           aVersion = eV2_2;
61         else
62           aVersion = eV2_1;
63       }
64     }
65     INITMSG(MYDEBUG,"GetVersionId - theFileName = '"<<theFileName<<"'; aVersion = "<<aVersion<<endl);
66     return aVersion;
67   }
68
69   PWrapper CrWrapper(const std::string& theFileName)
70   {
71     PWrapper aWrapper;
72     EVersion aVersion = GetVersionId(theFileName);
73     switch(aVersion){
74     case eV2_2:
75       aWrapper.reset(new MED::V2_2::TVWrapper(theFileName));
76       break;
77     case eV2_1:
78     default:
79       aWrapper.reset(new MED::V2_1::TVWrapper(theFileName));
80     }
81     return aWrapper;
82   }
83
84   PWrapper CrWrapper(const std::string& theFileName, EVersion theId)
85   {
86     EVersion aVersion = GetVersionId(theFileName);
87
88     if(aVersion != theId)
89       remove(theFileName.c_str());
90     
91     PWrapper aWrapper;
92     switch(theId){
93     case eV2_2:
94       aWrapper.reset(new MED::V2_2::TVWrapper(theFileName));
95       break;
96     case eV2_1:
97       aWrapper.reset(new MED::V2_1::TVWrapper(theFileName));
98       break;
99     }
100     return aWrapper;
101   }
102
103 }