Salome HOME
f93f85db449e60aee2dc7d612e3cd87b34683075
[modules/geom.git] / src / XAO / XAO_StringStep.cxx
1 // Copyright (C) 2013-2023  CEA/DEN, EDF R&D, OPEN CASCADE
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 // Author : Frederic Pons (OpenCascade)
20
21 #include "XAO_StringStep.hxx"
22
23 using namespace XAO;
24
25 StringStep::StringStep(int step, int stamp, int nbElements, int nbComponents)
26 {
27     m_nbElements = nbElements;
28     m_nbComponents = nbComponents;
29     m_step = step;
30     m_stamp = stamp;
31
32     m_values.reserve(m_nbElements);
33     for (int i = 0; i < m_nbElements; ++i)
34     {
35         std::vector<std::string> row;
36         row.reserve(m_nbComponents);
37         for (int j = 0; j < m_nbComponents; ++j)
38             row.push_back("");
39         m_values.push_back(row);
40     }
41 }
42
43 std::vector<std::string> StringStep::getValues()
44 {
45     std::vector<std::string> result;
46     result.reserve(m_nbElements * m_nbComponents);
47
48     std::vector< std::vector<std::string>  >::iterator it;
49     for (it = m_values.begin(); it != m_values.end(); ++it)
50     {
51         std::vector<std::string> eltValues = *it;
52         result.insert(result.end(), eltValues.begin(), eltValues.end());
53     }
54
55     return result;
56 }
57
58 std::vector<std::string> StringStep::getElement(int element)
59
60 {
61     checkElementIndex(element);
62
63     std::vector<std::string> result(m_values[element]);
64     return result;
65 }
66
67 std::vector<std::string> StringStep::getComponent(int component)
68
69 {
70     checkComponentIndex(component);
71
72     std::vector<std::string> result;
73     result.reserve(m_nbElements);
74
75     std::vector< std::vector<std::string>  >::iterator it;
76     for (it = m_values.begin(); it != m_values.end(); ++it)
77     {
78         std::vector<std::string> eltValues = *it;
79         result.push_back(eltValues[component]);
80     }
81
82     return result;
83 }
84
85 const std::string StringStep::getValue(int element, int component)
86
87 {
88     checkElementIndex(element);
89     checkComponentIndex(component);
90
91     return m_values[element][component];
92 }
93
94 const std::string StringStep::getStringValue(int element, int component)
95
96 {
97     return getValue(element, component);
98 }
99
100 void StringStep::setValues(const std::vector<std::string>& values)
101
102 {
103     checkNbValues(values.size());
104
105     for (int i = 0; i < m_nbElements; ++i)
106     {
107         for (int j = 0; j < m_nbComponents; ++j)
108         {
109             m_values[i][j] = values[i * m_nbComponents + j];
110         }
111     }
112 }
113
114 void StringStep::setElement(int element, const std::vector<std::string>& elements)
115
116 {
117     checkElementIndex(element);
118     checkNbComponents(elements.size());
119
120     for (int i = 0; i < m_nbComponents; ++i)
121         m_values[element][i] = elements[i];
122 }
123
124 void StringStep::setComponent(int component, const std::vector<std::string>& components)
125
126 {
127     checkElementIndex(component);
128     checkNbElements(components.size());
129
130     for (int i = 0; i < m_nbElements; ++i)
131         m_values[i][component] = components[i];
132 }
133
134 void StringStep::setValue(int element, int component, const std::string& value)
135
136 {
137     checkElementIndex(element);
138     checkComponentIndex(component);
139
140     m_values[element][component] = value;
141 }
142
143 void StringStep::setStringValue(int element, int component, const std::string& value)
144
145 {
146     setValue(element, component, value);
147 }