1 /******************************************************************
3 * Copyright 2016 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_value_generator.h"
23 std::unique_ptr<AttributeValueGen> AttributeValueGenFactory::create(
24 const std::shared_ptr<AttributeProperty> &property)
29 if (property->isInteger())
31 std::shared_ptr<IntegerProperty> intProperty = property->asInteger();
32 if (intProperty->hasRange())
36 intProperty->getRange(min, max);
37 return std::unique_ptr<AttributeValueGen>(
38 new RangeValueGen<int>(min, max));
40 else if (intProperty->hasValues())
42 std::vector<int> values;
43 intProperty->getValues(values);
44 return std::unique_ptr<AttributeValueGen>(
45 new ValuesSetGen<int>(values));
48 else if (property->isDouble())
50 std::shared_ptr<DoubleProperty> doubleProperty = property->asDouble();
51 if (doubleProperty->hasRange())
55 doubleProperty->getRange(min, max);
56 return std::unique_ptr<AttributeValueGen>(
57 new RangeValueGen<double>(min, max));
59 else if (doubleProperty->hasValues())
61 std::vector<double> values;
62 doubleProperty->getValues(values);
63 return std::unique_ptr<AttributeValueGen>(
64 new ValuesSetGen<double>(values));
67 else if (property->isBoolean())
69 return std::unique_ptr<AttributeValueGen>(new ValuesSetGen<bool>({true, false}));
71 else if (property->isString())
73 std::shared_ptr<StringProperty> stringProperty = property->asString();
74 if (stringProperty->hasValues())
76 std::vector<std::string> values;
77 stringProperty->getValues(values);
78 return std::unique_ptr<AttributeValueGen>(
79 new ValuesSetGen<std::string>(values));