Skip to content

Commit 6054d11

Browse files
authored
Remove UFixedBase and SFixedBase (#46)
* Delete SFixedBase.h * Delete UFixedBase.h
1 parent ff3308f commit 6054d11

File tree

7 files changed

+249
-209
lines changed

7 files changed

+249
-209
lines changed

src/FixedPoints/FixedPoints.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
#include "Details.h"
1616

17-
#include "UFixedBase.h"
18-
#include "SFixedBase.h"
19-
2017
#include "UFixed.h"
2118
#include "SFixed.h"
2219

src/FixedPoints/SFixed.h

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#pragma once
1616

1717
#include "Details.h"
18-
#include "SFixedBase.h"
1918

2019
FIXED_POINTS_BEGIN_NAMESPACE
2120

@@ -24,7 +23,7 @@ FIXED_POINTS_BEGIN_NAMESPACE
2423
//
2524

2625
template< unsigned Integer, unsigned Fraction >
27-
class SFixed : FIXED_POINTS_DETAILS::SFixedBase< Integer, Fraction >
26+
class SFixed
2827
{
2928
public:
3029
static_assert(((Integer + 1) + Fraction) <= FIXED_POINTS_DETAILS::BitSize<intmax_t>::Value, "Platform does not have a native type large enough for SFixed.");
@@ -55,16 +54,41 @@ class SFixed : FIXED_POINTS_DETAILS::SFixedBase< Integer, Fraction >
5554

5655
constexpr const static MaskType MidpointMask = FIXED_POINTS_DETAILS::MsbMask<FractionSize>::Value;
5756
constexpr const static MaskType LesserMidpointMask = MidpointMask - 1;
58-
59-
private:
60-
using Base = FIXED_POINTS_DETAILS::SFixedBase<Integer, Fraction>;
61-
using RawType = typename Base::RawType;
6257

63-
public:
64-
using Base::Base;
58+
protected:
59+
class RawType
60+
{
61+
private:
62+
const InternalType value;
63+
64+
public:
65+
constexpr inline explicit RawType(const InternalType & value) : value(value) {}
66+
constexpr inline explicit operator InternalType(void) const { return this->value; }
67+
};
6568

69+
protected:
70+
InternalType value;
71+
72+
protected:
73+
constexpr SFixed(const RawType & value);
74+
75+
public:
6676
constexpr SFixed(void);
6777
constexpr SFixed(const IntegerType & integer, const FractionType & fraction);
78+
constexpr SFixed(const char & value);
79+
constexpr SFixed(const unsigned char & value);
80+
constexpr SFixed(const signed char & value);
81+
constexpr SFixed(const unsigned short int & value);
82+
constexpr SFixed(const signed short int & value);
83+
constexpr SFixed(const unsigned int & value);
84+
constexpr SFixed(const signed int & value);
85+
constexpr SFixed(const unsigned long int & value);
86+
constexpr SFixed(const signed long int & value);
87+
constexpr SFixed(const unsigned long long int & value);
88+
constexpr SFixed(const signed long long int & value);
89+
constexpr SFixed(const double & value);
90+
constexpr SFixed(const float & value);
91+
constexpr SFixed(const long double & value);
6892

6993
constexpr InternalType getInternal(void) const;
7094
constexpr IntegerType getInteger(void) const;

src/FixedPoints/SFixedBase.h

Lines changed: 0 additions & 93 deletions
This file was deleted.

src/FixedPoints/SFixedMemberFunctions.h

Lines changed: 92 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,105 @@ FIXED_POINTS_BEGIN_NAMESPACE
1818
// Constructors
1919
//
2020

21+
template< unsigned Integer, unsigned Fraction >
22+
constexpr SFixed<Integer, Fraction>::SFixed(const RawType & value)
23+
: value(static_cast<InternalType>(value))
24+
{
25+
}
26+
2127
template< unsigned Integer, unsigned Fraction >
2228
constexpr SFixed<Integer, Fraction>::SFixed(void)
23-
: Base()
29+
: value(0)
2430
{
2531
}
2632

2733
template< unsigned Integer, unsigned Fraction >
2834
constexpr SFixed<Integer, Fraction>::SFixed(const IntegerType & integer, const FractionType & fraction)
29-
: Base(RawType((static_cast<InternalType>(integer) << FractionSize) | fraction))
35+
: value((static_cast<InternalType>(integer) << FractionSize) | fraction)
36+
{
37+
}
38+
39+
template< unsigned Integer, unsigned Fraction >
40+
constexpr SFixed<Integer, Fraction>::SFixed(const char & value)
41+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<char, InternalType> >(value) << FractionSize))
42+
{
43+
}
44+
45+
template< unsigned Integer, unsigned Fraction >
46+
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned char & value)
47+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned char, InternalType> >(value) << FractionSize))
48+
{
49+
}
50+
51+
template< unsigned Integer, unsigned Fraction >
52+
constexpr SFixed<Integer, Fraction>::SFixed(const signed char & value)
53+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed char, InternalType> >(value) << FractionSize))
54+
{
55+
}
56+
57+
template< unsigned Integer, unsigned Fraction >
58+
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned short int & value)
59+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned short int, InternalType> >(value) << FractionSize))
60+
{
61+
}
62+
63+
template< unsigned Integer, unsigned Fraction >
64+
constexpr SFixed<Integer, Fraction>::SFixed(const signed short int & value)
65+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed short int, InternalType> >(value) << FractionSize))
66+
{
67+
}
68+
69+
template< unsigned Integer, unsigned Fraction >
70+
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned int & value)
71+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned int, InternalType> >(value) << FractionSize))
72+
{
73+
}
74+
75+
template< unsigned Integer, unsigned Fraction >
76+
constexpr SFixed<Integer, Fraction>::SFixed(const signed int & value)
77+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed int, InternalType> >(value) << FractionSize))
78+
{
79+
}
80+
81+
template< unsigned Integer, unsigned Fraction >
82+
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned long int & value)
83+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long int, InternalType> >(value) << FractionSize))
84+
{
85+
}
86+
87+
template< unsigned Integer, unsigned Fraction >
88+
constexpr SFixed<Integer, Fraction>::SFixed(const signed long int & value)
89+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long int, InternalType> >(value) << FractionSize))
90+
{
91+
}
92+
93+
template< unsigned Integer, unsigned Fraction >
94+
constexpr SFixed<Integer, Fraction>::SFixed(const unsigned long long int & value)
95+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<unsigned long long int, InternalType> >(value) << FractionSize))
96+
{
97+
}
98+
99+
template< unsigned Integer, unsigned Fraction >
100+
constexpr SFixed<Integer, Fraction>::SFixed(const signed long long int & value)
101+
: value(static_cast<InternalType>(static_cast< FIXED_POINTS_DETAILS::LargerType<signed long long int, InternalType> >(value) << FractionSize))
102+
{
103+
}
104+
105+
template< unsigned Integer, unsigned Fraction >
106+
constexpr SFixed<Integer, Fraction>::SFixed(const double & value)
107+
: value(static_cast<InternalType>(value * static_cast<double>(Scale)))
108+
{
109+
}
110+
111+
template< unsigned Integer, unsigned Fraction >
112+
constexpr SFixed<Integer, Fraction>::SFixed(const float & value)
113+
: value(static_cast<InternalType>(value * static_cast<float>(Scale)))
114+
{
115+
}
116+
117+
template< unsigned Integer, unsigned Fraction >
118+
constexpr SFixed<Integer, Fraction>::SFixed(const long double & value)
119+
: value(static_cast<InternalType>(value * static_cast<long double>(Scale)))
30120
{
31121
}
32122

src/FixedPoints/UFixed.h

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#pragma once
1616

1717
#include "Details.h"
18-
#include "UFixedBase.h"
1918

2019
FIXED_POINTS_BEGIN_NAMESPACE
2120

@@ -24,7 +23,7 @@ FIXED_POINTS_BEGIN_NAMESPACE
2423
//
2524

2625
template< unsigned Integer, unsigned Fraction >
27-
class UFixed : FIXED_POINTS_DETAILS::UFixedBase< Integer, Fraction >
26+
class UFixed
2827
{
2928
public:
3029
static_assert((Integer + Fraction) <= FIXED_POINTS_DETAILS::BitSize<uintmax_t>::Value, "Platform does not have a native type large enough for UFixed.");
@@ -56,16 +55,42 @@ class UFixed : FIXED_POINTS_DETAILS::UFixedBase< Integer, Fraction >
5655
constexpr const static MaskType MidpointMask = FIXED_POINTS_DETAILS::MsbMask<FractionSize>::Value;
5756
constexpr const static MaskType LesserMidpointMask = MidpointMask - 1;
5857

59-
private:
60-
using Base = FIXED_POINTS_DETAILS::UFixedBase<Integer, Fraction>;
61-
using RawType = typename Base::RawType;
58+
protected:
59+
class RawType
60+
{
61+
private:
62+
const InternalType value;
6263

63-
public:
64-
using Base::Base;
64+
public:
65+
constexpr inline explicit RawType(const InternalType & value) : value(value) {}
66+
constexpr inline explicit operator InternalType(void) const { return this->value; }
67+
};
68+
69+
protected:
70+
InternalType value;
6571

72+
protected:
73+
constexpr UFixed(const RawType & value);
74+
75+
public:
6676
constexpr UFixed(void);
6777
constexpr UFixed(const IntegerType & integer, const FractionType & fraction);
68-
78+
constexpr UFixed(const char & value);
79+
constexpr UFixed(const unsigned char & value);
80+
constexpr UFixed(const signed char & value);
81+
constexpr UFixed(const unsigned short int & value);
82+
constexpr UFixed(const signed short int & value);
83+
constexpr UFixed(const unsigned int & value);
84+
constexpr UFixed(const signed int & value);
85+
constexpr UFixed(const unsigned long int & value);
86+
constexpr UFixed(const signed long int & value);
87+
constexpr UFixed(const unsigned long long int & value);
88+
constexpr UFixed(const signed long long int & value);
89+
constexpr UFixed(const double & value);
90+
constexpr UFixed(const float & value);
91+
constexpr UFixed(const long double & value);
92+
93+
public:
6994
constexpr InternalType getInternal(void) const;
7095
constexpr IntegerType getInteger(void) const;
7196
constexpr FractionType getFraction(void) const;

0 commit comments

Comments
 (0)