1 // Copyright (C) 2013-2015 CEA/DEN, EDF R&D, OPEN CASCADE
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(const int& step, const int& stamp, const int& nbElements, const 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(const int& element)
62 checkElementIndex(element);
64 std::vector<int> result(m_values[element]);
68 std::vector<int> IntegerStep::getComponent(const 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 const int IntegerStep::getValue(const int& element, const int& component)
89 checkElementIndex(element);
90 checkComponentIndex(component);
92 return m_values[element][component];
95 const std::string IntegerStep::getStringValue(const int& element, const int& component)
98 return XaoUtils::intToString(getValue(element, component));
101 void IntegerStep::setValues(const std::vector<int>& values)
102 throw (XAO_Exception)
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(const int& element, const std::vector<int>& elements)
116 throw (XAO_Exception)
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(const int& component, const std::vector<int>& components)
126 throw (XAO_Exception)
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(const int& element, const int& component, const int& value)
136 throw (XAO_Exception)
138 checkElementIndex(element);
139 checkComponentIndex(component);
141 m_values[element][component] = value;
144 void IntegerStep::setStringValue(const int& element, const int& component, const std::string& value)
145 throw (XAO_Exception)
147 setValue(element, component, XaoUtils::stringToInt(value));