1 // Copyright (C) 2013-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 // Author : Frederic Pons (OpenCascade)
21 #include "XAO_IntegerStep.hxx"
22 #include "XAO_XaoUtils.hxx"
26 IntegerStep::IntegerStep(int step, int stamp, int nbElements, int nbComponents)
28 m_nbElements = nbElements;
29 m_nbComponents = nbComponents;
33 m_values.reserve(m_nbElements);
34 for (int i = 0; i < m_nbElements; ++i)
37 row.reserve(m_nbComponents);
38 for (int j = 0; j < m_nbComponents; ++j)
40 m_values.push_back(row);
44 std::vector<int> IntegerStep::getValues()
46 std::vector<int> result;
47 result.reserve(m_nbElements * m_nbComponents);
49 std::vector< std::vector<int> >::iterator it;
50 for (it = m_values.begin(); it != m_values.end(); ++it)
52 std::vector<int> eltValues = *it;
53 result.insert(result.end(), eltValues.begin(), eltValues.end());
59 std::vector<int> IntegerStep::getElement(int element)
62 checkElementIndex(element);
64 std::vector<int> result(m_values[element]);
68 std::vector<int> IntegerStep::getComponent(int component)
71 checkComponentIndex(component);
73 std::vector<int> result;
74 result.reserve(m_nbElements);
76 std::vector< std::vector<int> >::iterator it;
77 for (it = m_values.begin(); it != m_values.end(); ++it)
79 std::vector<int> eltValues = *it;
80 result.push_back(eltValues[component]);
86 int IntegerStep::getValue(int element, int component)
89 checkElementIndex(element);
90 checkComponentIndex(component);
92 return m_values[element][component];
95 const std::string IntegerStep::getStringValue(int element, int component)
98 return XaoUtils::intToString(getValue(element, component));
101 void IntegerStep::setValues(const std::vector<int>& values)
104 checkNbValues(values.size());
106 for (int i = 0; i < m_nbElements; ++i)
108 for (int j = 0; j < m_nbComponents; ++j)
110 m_values[i][j] = values[i * m_nbComponents + j];
115 void IntegerStep::setElement(int element, const std::vector<int>& elements)
118 checkElementIndex(element);
119 checkNbComponents(elements.size());
121 for (int i = 0; i < m_nbComponents; ++i)
122 m_values[element][i] = elements[i];
125 void IntegerStep::setComponent(int component, const std::vector<int>& components)
128 checkElementIndex(component);
129 checkNbElements(components.size());
131 for (int i = 0; i < m_nbElements; ++i)
132 m_values[i][component] = components[i];
135 void IntegerStep::setValue(int element, int component, int value)
138 checkElementIndex(element);
139 checkComponentIndex(component);
141 m_values[element][component] = value;
144 void IntegerStep::setStringValue(int element, int component, const std::string& value)
147 setValue(element, component, XaoUtils::stringToInt(value));