Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/paravis.git] / src / Plugins / MedReader / IO / vtkMedSelection.cxx
1 // Copyright (C) 2010-2011  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.
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 "vtkMedSelection.h"
21
22 #include "vtkObjectFactory.h"
23 #include "vtkStringArray.h"
24
25 #include <map>
26 #include <string>
27 #include <vector>
28 using namespace std;
29
30 class vtkMedSelectionInternals
31 {
32 public :
33   map< string, bool > Status;
34   vector< string > Keys;
35 };
36
37 // vtkCxxRevisionMacro(vtkMedSelection, "$Revision$")
38 vtkStandardNewMacro(vtkMedSelection)
39
40 vtkMedSelection::vtkMedSelection()
41 {
42   this->Internals = new vtkMedSelectionInternals();
43 }
44
45 vtkMedSelection::~vtkMedSelection()
46 {
47   delete this->Internals;
48 }
49
50 void  vtkMedSelection::Initialize()
51 {
52   this->Internals->Status.clear();
53   this->Internals->Keys.clear();
54 }
55
56 void  vtkMedSelection::AddKey(const char* key)
57 {
58   if(this->Internals->Status.find(key) != this->Internals->Status.end())
59     {
60     return ;
61     }
62   this->Internals->Keys.push_back(key);
63   this->Internals->Status[key] = 1;
64 }
65
66 void  vtkMedSelection::SetKeyStatus(const char* key, int status)
67 {
68   if(this->Internals->Status.find(key) == this->Internals->Status.end())
69     {
70     this->AddKey(key);
71     }
72   this->Internals->Status[key] = status;
73 }
74
75 int vtkMedSelection::GetKeyStatus(const char* key)
76 {
77   if(this->Internals->Status.find(key) == this->Internals->Status.end())
78     {
79     return 0;
80     }
81   return this->Internals->Status[key];
82 }
83
84 const char* vtkMedSelection::GetKey(int index)
85 {
86   if(index < 0  || index >= this->Internals->Keys.size())
87     {
88     return NULL;
89     }
90   return this->Internals->Keys[index].c_str();
91 }
92
93 int vtkMedSelection::GetNumberOfKey()
94 {
95   return this->Internals->Keys.size();
96 }
97
98 int vtkMedSelection::KeyExists(const char *key)
99 {
100   return this->Internals->Status.find(key)
101       != this->Internals->Status.end();
102 }
103
104 void  vtkMedSelection::RemoveKeyByIndex(int index)
105 {
106   if(index < 0  || index >= this->Internals->Keys.size())
107     {
108     return;
109     }
110   string name = this->Internals->Keys[index];
111   this->Internals->Status.erase(name);
112   this->Internals->Keys.erase(this->Internals->Keys.begin() + index);
113 }
114
115 void vtkMedSelection::PrintSelf(ostream& os, vtkIndent indent)
116 {
117   this->Superclass::PrintSelf(os, indent);
118 }