LibrePCB Developers Documentation
boundedunsignedratio.h
Go to the documentation of this file.
1/*
2 * LibrePCB - Professional EDA for everyone!
3 * Copyright (C) 2013 LibrePCB Developers, see AUTHORS.md for contributors.
4 * https://librepcb.org/
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef LIBREPCB_CORE_BOUNDEDUNSIGNEDRATIO_H
21#define LIBREPCB_CORE_BOUNDEDUNSIGNEDRATIO_H
22
23/*******************************************************************************
24 * Includes
25 ******************************************************************************/
26#include "length.h"
27#include "ratio.h"
28
29#include <QtCore>
30
31/*******************************************************************************
32 * Namespace / Forward Declarations
33 ******************************************************************************/
34namespace librepcb {
35
36class SExpression;
37
38/*******************************************************************************
39 * Class BoundedUnsignedRatio
40 ******************************************************************************/
41
47 Q_DECLARE_TR_FUNCTIONS(BoundedUnsignedRatio)
48
49public:
50 // Constructors / Destructor
52 BoundedUnsignedRatio(const BoundedUnsignedRatio& other) noexcept;
53 BoundedUnsignedRatio(const UnsignedRatio& ratio, const UnsignedLength& min,
54 const UnsignedLength& max);
55 explicit BoundedUnsignedRatio(const SExpression& node);
56 ~BoundedUnsignedRatio() noexcept;
57
58 // Getters
59 const UnsignedRatio& getRatio() const noexcept { return mRatio; }
60 const UnsignedLength& getMinValue() const noexcept { return mMinValue; }
61 const UnsignedLength& getMaxValue() const noexcept { return mMaxValue; }
62 UnsignedLength calcValue(const Length& input) const noexcept;
63
64 // General Methods
65 void serialize(SExpression& root) const;
66
67 // Operator Overloadings
69 bool operator==(const BoundedUnsignedRatio& rhs) const noexcept;
70 bool operator!=(const BoundedUnsignedRatio& rhs) const noexcept {
71 return !(*this == rhs);
72 }
73
74private: // Methods
75 void throwIfInvalid() const;
76
77private: // Data
81};
82
83/*******************************************************************************
84 * End of File
85 ******************************************************************************/
86
87} // namespace librepcb
88
89#endif
The BoundedUnsignedRatio class represents a ratio limited to a range specified by min/max values.
Definition: boundedunsignedratio.h:46
void throwIfInvalid() const
Definition: boundedunsignedratio.cpp:104
bool operator!=(const BoundedUnsignedRatio &rhs) const noexcept
Definition: boundedunsignedratio.h:70
UnsignedLength mMinValue
Definition: boundedunsignedratio.h:79
const UnsignedRatio & getRatio() const noexcept
Definition: boundedunsignedratio.h:59
BoundedUnsignedRatio & operator=(const BoundedUnsignedRatio &rhs) noexcept
Definition: boundedunsignedratio.cpp:86
bool operator==(const BoundedUnsignedRatio &rhs) const noexcept
Definition: boundedunsignedratio.cpp:94
UnsignedLength calcValue(const Length &input) const noexcept
Definition: boundedunsignedratio.cpp:66
void serialize(SExpression &root) const
Definition: boundedunsignedratio.cpp:76
const UnsignedLength & getMinValue() const noexcept
Definition: boundedunsignedratio.h:60
UnsignedRatio mRatio
Definition: boundedunsignedratio.h:78
~BoundedUnsignedRatio() noexcept
Definition: boundedunsignedratio.cpp:59
const UnsignedLength & getMaxValue() const noexcept
Definition: boundedunsignedratio.h:61
UnsignedLength mMaxValue
Definition: boundedunsignedratio.h:80
The Length class is used to represent a length (for example 12.75 millimeters)
Definition: length.h:83
The SExpression class.
Definition: sexpression.h:69
Definition: occmodel.cpp:77
type_safe::constrained_type< Length, UnsignedLengthConstraint, UnsignedLengthVerifier > UnsignedLength
Definition: length.h:696
type_safe::constrained_type< Ratio, UnsignedRatioConstraint, UnsignedRatioVerifier > UnsignedRatio
Definition: ratio.h:330