1/*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_CALC_DIMENSION_H
17#define FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_CALC_DIMENSION_H
18
19#include "base/geometry/dimension.h"
20
21namespace OHOS::Ace {
22class CalcDimension : public Dimension {
23public:
24    CalcDimension() = default;
25    ~CalcDimension() = default;
26
27    explicit CalcDimension(const std::string& value, DimensionUnit unit = DimensionUnit::CALC)
28    {
29        calcvalue_ = value;
30        SetUnit(DimensionUnit::CALC);
31    };
32
33    CalcDimension(double value, DimensionUnit unit = DimensionUnit::PX) : Dimension(value, unit) {};
34    CalcDimension(const Dimension& dimension) : Dimension(dimension) {};
35
36    const std::string& CalcValue() const
37    {
38        return calcvalue_;
39    }
40
41    void SetCalcValue(const std::string& value)
42    {
43        calcvalue_ = value;
44    }
45
46    CalcDimension& operator=(const Dimension& newDimension)
47    {
48        Dimension& dimension = *this;
49        dimension = newDimension;
50        return *this;
51    }
52
53    CalcDimension& operator=(const CalcDimension& newDimension)
54    {
55        SetCalcValue(newDimension.CalcValue());
56        SetValue(newDimension.Value());
57        SetUnit(newDimension.Unit());
58        return *this;
59    }
60
61    std::string ToString() const
62    {
63        return calcvalue_.empty() ? Dimension::ToString() : calcvalue_ + "calc";
64    }
65
66private:
67    std::string calcvalue_ = "";
68};
69} // namespace OHOS::Ace
70
71#endif // FOUNDATION_ACE_FRAMEWORKS_BASE_GEOMETRY_CALC_DIMENSION_H
72