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(const SimulatorResourceAttribute &attribute)
25 m_name = attribute.getName();
26 if (attribute.getProperty())
28 m_valueGen = AttributeValueGenFactory::create(attribute.getProperty());
32 AttributeGenerator::AttributeGenerator(const std::string &name,
33 const std::shared_ptr<AttributeProperty> &property)
38 m_valueGen = AttributeValueGenFactory::create(property);
42 bool AttributeGenerator::hasNext()
45 return m_valueGen->hasNext();
49 bool AttributeGenerator::next(SimulatorResourceAttribute &attribute)
56 attribute.setName(m_name);
57 attribute.setValue(m_valueGen->next());
64 SimulatorResourceAttribute AttributeGenerator::current()
68 return SimulatorResourceAttribute(m_name, m_valueGen->value());
71 return SimulatorResourceAttribute(m_name);
74 void AttributeGenerator::reset()
80 AttributeCombinationGen::AttributeCombinationGen(
81 const std::vector<SimulatorResourceAttribute> &attributes)
83 for (auto &attr : attributes)
85 AttributeGenerator attrGen(attr);
86 m_attrGenList.push_back(attr);
87 m_resModel.add(attr.getName(), attr.getValue());
93 bool AttributeCombinationGen::next(SimulatorResourceModel &resModel)
95 if (!m_attrGenList.size())
100 std::lock_guard<std::mutex> lock(m_lock);
102 // This block will execute for only first time
105 for (size_t index = 0; index < m_attrGenList.size(); index++)
107 // Add the attribute on resource model
108 updateAttributeInModel(index);
111 m_index = m_attrGenList.size() - 1;
112 resModel = m_resModel;
116 // Get the next attribute from statck top element
117 if (m_attrGenList[m_index].hasNext())
119 updateAttributeInModel(m_index);
120 resModel = m_resModel;
124 for (int index = m_index; index >= 0; index--)
126 if (!m_attrGenList[index].hasNext())
131 m_attrGenList[index].reset();
132 updateAttributeInModel(index);
136 updateAttributeInModel(index);
141 resModel = m_resModel;
147 void AttributeCombinationGen::updateAttributeInModel(int index)
149 SimulatorResourceAttribute attribute;
150 if (m_attrGenList[index].next(attribute))
151 m_resModel.update(attribute.getName(), attribute.getValue());