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)
25 m_name.assign(attribute.getName());
26 m_type = attribute.getValueType();
28 if (!attribute.getValueType())
29 attribute.getRange(m_min, m_max);
38 m_allowedValues = attribute.getAllowedValues();
39 if (0 != m_allowedValues.size())
41 m_hasAllowedValue = true;
43 m_nextAllowedValueIndex = 0;
44 m_prevAllowedValueIndex = m_allowedValues.size();
47 AttributeGenerator::~AttributeGenerator()
52 m_nextAllowedValueIndex = 0;
53 m_prevAllowedValueIndex = 0;
57 bool AttributeGenerator::hasNext()
59 if (m_hasRange && m_rangeIndex <= m_max && !m_type)
64 if (m_hasAllowedValue && m_nextAllowedValueIndex < m_allowedValues.size())
72 AttributeSP AttributeGenerator::next()
74 AttributeSP attr = std::make_shared<SimulatorResourceModel::Attribute>(m_name);
79 if (m_hasRange && !m_type)
81 attr->setName(m_name);
82 attr->setValue(m_rangeIndex++);
86 if (m_hasAllowedValue)
92 attr->setValue(m_allowedValues[m_nextAllowedValueIndex++]);
98 attr->setValue(m_allowedValues[m_nextAllowedValueIndex++]);
107 AttributeSP AttributeGenerator::previous()
109 AttributeSP attr = std::make_shared<SimulatorResourceModel::Attribute>(m_name);
114 if (m_hasRange && !m_type)
116 attr->setValue(m_rangeIndex - 1);
120 if (m_hasAllowedValue)
126 attr->setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);
132 attr->setValue(m_allowedValues[m_prevAllowedValueIndex - 1]);