Salome HOME
6f05fae660c5c4df0872a2babbc6c2adedc1d2a3
[tools/medcoupling.git] / src / RENUMBER / RenumberingFactory.cxx
1 // Copyright (C) 2007-2019  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "RenumberingFactory.hxx"
21 #include "RENUMBER_Renumbering.hxx"
22 #ifdef MED_ENABLE_METIS
23 #include "RENUMBER_METISRenumbering.hxx"
24 #endif
25 #ifdef ENABLE_BOOST
26 #include "RENUMBER_BOOSTRenumbering.hxx"
27 #endif
28
29 #include <iostream>
30 #include <algorithm>
31
32 namespace MED_RENUMBER
33 {
34   bool CompareRenumMeth(const std::string& s1, const char *s2)
35   {
36     std::string ss1(s1),ss2(s2);
37     std::transform(ss1.begin(), ss1.end(), ss1.begin(), ::tolower);
38     std::transform(ss2.begin(), ss2.end(), ss2.begin(), ::tolower);
39     return ss1==ss2;
40   }
41   
42   Renumbering* RenumberingFactory(const std::string &s)
43   {
44 #ifdef MED_ENABLE_METIS
45 #ifdef ENABLE_BOOST
46     if ( CompareRenumMeth(s,METIS_ALG) )
47       {
48         return new METISRenumbering;
49       }
50     else if( CompareRenumMeth(s,BOOST_ALG) )
51       {
52         return new BOOSTRenumbering;
53       }
54     else 
55       {
56         std::cerr << "The method has to be METIS or BOOST" << std::endl;
57         return 0;
58       }
59 #endif
60 #ifndef ENABLE_BOOST
61     if ( CompareRenumMeth(s,METIS_ALG) )
62       {
63         return new METISRenumbering;
64       }
65     else
66       {
67         std::cerr << "The method has to be METIS!" << std::endl;
68         return 0;
69       }
70 #endif
71 #endif
72 #ifndef MED_ENABLE_METIS
73 #ifdef ENABLE_BOOST
74     if ( CompareRenumMeth(s,BOOST_ALG) )
75       {
76         return new BOOSTRenumbering;
77       }
78     else
79       {
80         std::cerr << "The method has to be BOOST!" << std::endl;
81         return 0;
82       }
83 #endif
84 #ifndef ENABLE_BOOST
85     std::cerr << "Error, no method compiled" << std::endl;
86     return 0;
87 #endif
88 #endif
89   }
90
91   std::vector<std::string> AllRenumberMethods()
92   {
93     std::vector<std::string> ret;
94     ret.push_back(std::string(BOOST_ALG));
95     ret.push_back(std::string(METIS_ALG));
96     return ret;
97   }
98   
99   std::vector<std::string> RenumberAvailableMethods()
100   {
101     std::vector<std::string> ret;
102 #ifdef ENABLE_BOOST
103     ret.push_back(std::string(BOOST_ALG));
104 #endif
105 #ifdef MED_ENABLE_METIS
106     ret.push_back(std::string(METIS_ALG));
107 #endif
108     return ret;
109   }
110 }