1 /******************************************************************
3 * Copyright 2015 Samsung Electronics All Rights Reserved.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 ******************************************************************/
21 #include "attribute_generator.h"
23 AttributeGenerator::AttributeGenerator(SimulatorResourceModel::Attribute &attribute)
24 : m_name(attribute.getName()),
28 m_nextAllowedValueIndex(0),
29 m_prevAllowedValueIndex(0),
31 m_hasAllowedValue(false)
33 if (attribute.getValueType() ==
34 SimulatorResourceModel::Attribute::ValueType::INTEGER)
36 attribute.getRange(m_min, m_max);
37 if (INT_MIN != m_min && INT_MAX != m_max)
45 m_allowedValues = attribute.getAllowedValues();
46 if (0 != m_allowedValues.size())
48 m_hasAllowedValue = true;
50 m_prevAllowedValueIndex = m_allowedValues.size();
54 bool AttributeGenerator::hasNext()
56 if (m_hasRange && m_rangeIndex <= m_max)
61 if (m_hasAllowedValue && m_nextAllowedValueIndex < m_allowedValues.size())
69 bool AttributeGenerator::next(SimulatorResourceModel::Attribute &attribute)
71 attribute.setName(m_name);
75 attribute.setValue(m_rangeIndex++);
78 else if (m_hasAllowedValue)
80 attribute.setValue(m_allowedValues[m_nextAllowedValueIndex++]);
87 bool AttributeGenerator::previous(SimulatorResourceModel::Attribute &attribute)
89 attribute.setName(m_name);
93 attribute.setValue(m_rangeIndex - 1);
96 else if (m_hasAllowedValue)
98 attribute.setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);