Skip to content

Commit 850c5b7

Browse files
first commit
1 parent 436163b commit 850c5b7

File tree

6 files changed

+78
-12
lines changed

6 files changed

+78
-12
lines changed

nautilus-api/include/Interface/DataTypes/Val.hpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33
#ifndef NAUTILUS_LIB_VAL_HPP
44
#define NAUTILUS_LIB_VAL_HPP
55

6+
#include <iostream>
67
#include <memory>
8+
#include <common/CastUtils.hpp>
79
#include <common/config.hpp>
810

911
#ifdef USE_SOURCE_LOCATION_TRACKING
10-
#include <common/SourceLocation.hpp>
12+
#include <common/source_location.hpp>
1113
#endif
1214

13-
#include <iostream>
1415

1516
namespace nautilus {
1617

1718
class base_value {
1819
};
1920

21+
22+
2023
template<class T>
2124
concept is_base_type = std::is_base_of<base_value, T>::value;
2225

@@ -42,6 +45,9 @@ namespace nautilus {
4245

4346
namespace details {
4447

48+
template<typename LHS>
49+
LHS getRawValue(val<LHS> &val);
50+
4551
#define COMMON_RETURN_TYPE \
4652
val<typename std::common_type<LHS, RHS>::type>
4753

@@ -111,16 +117,15 @@ namespace nautilus {
111117

112118

113119
#ifdef USE_SOURCE_LOCATION_TRACKING
120+
114121
inline val<ValueType>(ValueType value, const std::source_location loc = std::source_location::current())
115122
: value(value), loc(loc) {};
116123

117124
inline val<ValueType>(const val<ValueType> &other,
118125
const std::source_location loc = std::source_location::current())
119126
: value(other.value), loc(loc) {};
120127
#else
121-
122128
inline val<ValueType>(ValueType value) : value(value) {};
123-
124129
inline val<ValueType>(const val<ValueType> &other) : value(other.value) {};
125130
#endif
126131

@@ -180,6 +185,8 @@ namespace nautilus {
180185
private:
181186
friend class val_ptr<ValueType *>;
182187

188+
friend ValueType details::getRawValue<ValueType>(val<ValueType> &left);
189+
183190
template<is_fundamental LHS, is_fundamental RHS>
184191
friend COMMON_RETURN_TYPE mul(val<LHS> &left, val<RHS> &right);
185192

@@ -451,6 +458,11 @@ namespace nautilus {
451458
return ~lValue.value;
452459
}
453460

461+
template<typename LHS>
462+
LHS inline getRawValue(val<LHS> &val) {
463+
return val.value;
464+
}
465+
454466
}
455467

456468
template<typename LHS, typename RHS>
@@ -753,8 +765,6 @@ namespace nautilus {
753765
left = left >> right;
754766
return left;
755767
}
756-
757-
758768
}
759769

760770
#endif //NAUTILUS_LIB_VAL_HPP

nautilus-api/test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
add_executable(nautilus-api-tests
1515
Interface/BooleanTypeTest.cpp
1616
Interface/IntegerValTypeTest.cpp
17+
Interface/FloatValTypeTest.cpp
1718
Interface/IntegerTypeTest.cpp
1819
Interface/FloatTypeTest.cpp)
1920

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
2+
#include <catch2/catch_all.hpp>
3+
#include <Interface/DataTypes/Val.hpp>
4+
#include <iostream>
5+
6+
namespace nautilus {
7+
8+
TEMPLATE_TEST_CASE("Float Val Operation Test", "[value][template]", float, double) {
9+
SECTION("comparison operators") {
10+
SECTION("==") {
11+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
12+
REQUIRE(f1 == static_cast<TestType>(42.1));
13+
}SECTION("!=") {
14+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
15+
REQUIRE(f1 != static_cast<TestType>(1));
16+
}SECTION(">") {
17+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
18+
REQUIRE(f1 > static_cast<TestType>(1));
19+
}SECTION("<") {
20+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
21+
REQUIRE(f1 < static_cast<TestType>(100));
22+
}SECTION(">=") {
23+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
24+
REQUIRE(f1 >= static_cast<TestType>(42.1));
25+
REQUIRE(f1 >= static_cast<TestType>(1));
26+
}SECTION("<=") {
27+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
28+
REQUIRE(f1 <= static_cast<TestType>(100));
29+
REQUIRE(f1 <= static_cast<TestType>(42.2));
30+
}
31+
}SECTION("arithmetic operators") {
32+
SECTION("+") {
33+
auto f1 = val<TestType>(static_cast<TestType>(42.1));
34+
auto f2 = val<TestType>(static_cast<TestType>(42.1));
35+
auto res = f1 + f2;
36+
REQUIRE(res == static_cast<TestType>(84.2));
37+
}SECTION("-") {
38+
auto f1 = val<TestType>(static_cast<TestType>(42.5));
39+
auto f2 = val<TestType>(static_cast<TestType>(42.2));
40+
auto res = f1 - f2;
41+
auto x = details::getRawValue(res);
42+
REQUIRE(x == Catch::Approx(0.3));
43+
}SECTION("*") {
44+
auto f1 = val<TestType>(static_cast<TestType>(5.5));
45+
auto f2 = val<TestType>(static_cast<TestType>(5.5));
46+
auto res = f1 * f2;
47+
auto x = details::getRawValue(res);
48+
REQUIRE(x == Catch::Approx(30.25));
49+
}SECTION("/") {
50+
auto f1 = val<TestType>(static_cast<TestType>(21.1));
51+
auto f2 = val<TestType>(static_cast<TestType>(7));
52+
auto res = f1 / f2;
53+
auto x = details::getRawValue(res);
54+
REQUIRE(x == Catch::Approx(3.0142857143));
55+
}
56+
}
57+
}
58+
}

nautilus-api/test/Interface/IntegerValTypeTest.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11

22
#include <catch2/catch_all.hpp>
3-
#include <Interface/DataTypes/Integer/Int.hpp>
43
#include <Interface/DataTypes/Val.hpp>
54
#include <iostream>
65

76
namespace nautilus {
87

9-
TEMPLATE_TEST_CASE("Integer Operation Test", "[value][template]", int8_t, int16_t, int32_t, int64_t, uint8_t,
8+
TEMPLATE_TEST_CASE("Integer Val Operation Test", "[value][template]", int8_t, int16_t, int32_t, int64_t, uint8_t,
109
uint16_t, uint32_t,
1110
uint64_t) {
1211
SECTION("comparison operators") {

nautilus-common/include/common/SourceLocation.hpp renamed to nautilus-common/include/common/source_location.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
See the License for the specific language governing permissions and
1212
limitations under the License.
1313
*/
14-
#ifndef NES_COMMON_INCLUDE_UTIL_SOURCELOCATION_HPP_
15-
#define NES_COMMON_INCLUDE_UTIL_SOURCELOCATION_HPP_
14+
#pragma once
1615

1716
#include <cstring>
1817
// The following provides a polyfill for the source location standard. On not supported platforms it will return a empty result.
@@ -57,4 +56,3 @@ struct source_location {
5756
};
5857
}// namespace std
5958
#endif
60-
#endif// NES_COMMON_INCLUDE_UTIL_SOURCELOCATION_HPP_

nautilus-common/include/exceptions/RuntimeException.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#ifndef NES_COMMON_INCLUDE_EXCEPTIONS_RUNTIMEEXCEPTION_HPP_
1616
#define NES_COMMON_INCLUDE_EXCEPTIONS_RUNTIMEEXCEPTION_HPP_
1717

18-
#include <common/SourceLocation.hpp>
18+
#include <common/source_location.hpp>
1919
#include <exception>
2020
#include <stdexcept>
2121
#include <string>

0 commit comments

Comments
 (0)