1 // Copyright (C) 2013-2016 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_StringStep.hxx"
25 StringStep::StringStep(const int& step, const int& stamp, const int& nbElements, const int& nbComponents)
27 m_nbElements = nbElements;
28 m_nbComponents = nbComponents;
32 m_values.reserve(m_nbElements);
33 for (int i = 0; i < m_nbElements; ++i)
35 std::vector<std::string> row;
36 row.reserve(m_nbComponents);
37 for (int j = 0; j < m_nbComponents; ++j)
39 m_values.push_back(row);
43 std::vector<std::string> StringStep::getValues()
45 std::vector<std::string> result;
46 result.reserve(m_nbElements * m_nbComponents);
48 std::vector< std::vector<std::string> >::iterator it;
49 for (it = m_values.begin(); it != m_values.end(); ++it)
51 std::vector<std::string> eltValues = *it;
52 result.insert(result.end(), eltValues.begin(), eltValues.end());
58 std::vector<std::string> StringStep::getElement(const int& element)
61 checkElementIndex(element);
63 std::vector<std::string> result(m_values[element]);
67 std::vector<std::string> StringStep::getComponent(const int& component)
70 checkComponentIndex(component);
72 std::vector<std::string> result;
73 result.reserve(m_nbElements);
75 std::vector< std::vector<std::string> >::iterator it;
76 for (it = m_values.begin(); it != m_values.end(); ++it)
78 std::vector<std::string> eltValues = *it;
79 result.push_back(eltValues[component]);
85 const std::string StringStep::getValue(const int& element, const int& component)
88 checkElementIndex(element);
89 checkComponentIndex(component);
91 return m_values[element][component];
94 const std::string StringStep::getStringValue(const int& element, const int& component)
97 return getValue(element, component);
100 void StringStep::setValues(const std::vector<std::string>& values)
101 throw (XAO_Exception)
103 checkNbValues(values.size());
105 for (int i = 0; i < m_nbElements; ++i)
107 for (int j = 0; j < m_nbComponents; ++j)
109 m_values[i][j] = values[i * m_nbComponents + j];
114 void StringStep::setElement(const int& element, const std::vector<std::string>& elements)
115 throw (XAO_Exception)
117 checkElementIndex(element);
118 checkNbComponents(elements.size());
120 for (int i = 0; i < m_nbComponents; ++i)
121 m_values[element][i] = elements[i];
124 void StringStep::setComponent(const int& component, const std::vector<std::string>& components)
125 throw (XAO_Exception)
127 checkElementIndex(component);
128 checkNbElements(components.size());
130 for (int i = 0; i < m_nbElements; ++i)
131 m_values[i][component] = components[i];
134 void StringStep::setValue(const int& element, const int& component, const std::string& value)
135 throw (XAO_Exception)
137 checkElementIndex(element);
138 checkComponentIndex(component);
140 m_values[element][component] = value;
143 void StringStep::setStringValue(const int& element, const int& component, const std::string& value)
144 throw (XAO_Exception)
146 setValue(element, component, value);