Browse Source

Add Double module (broken)

Patrick-Christopher Mattulat 2 weeks ago
parent
commit
631af9adcf

+ 8 - 2
cmake/Build.cmake

@@ -7,9 +7,12 @@ function(build_boxing_module build_static_flag build_shared_flag module_name mod
         set_target_properties("${${module_name}}" PROPERTIES DEBUG_POSTFIX "-d")
 
         target_compile_features("${${module_name}}" PUBLIC cxx_std_20)
+        target_compile_options("${${module_name}}" PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-include-angled-in-module-purview>)
 
         target_sources("${${module_name}}" PUBLIC FILE_SET boxing_modules TYPE CXX_MODULES FILES
-                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Boolean.cppm)
+                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Boolean.cppm
+                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Double.cppm
+        )
     endif ()
 
     if (${build_shared_flag})
@@ -19,9 +22,12 @@ function(build_boxing_module build_static_flag build_shared_flag module_name mod
         set_target_properties("${${module_name}}" PROPERTIES DEBUG_POSTFIX "-d")
 
         target_compile_features("${${module_name}}" PUBLIC cxx_std_20)
+        target_compile_options("${${module_name}}" PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-include-angled-in-module-purview>)
 
         target_sources("${${module_name}}" PUBLIC FILE_SET boxing_modules TYPE CXX_MODULES FILES
-                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Boolean.cppm)
+                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Boolean.cppm
+                ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Double.cppm
+        )
     endif ()
 endfunction()
 

+ 0 - 1
cmake/SourceFiles.cmake

@@ -1,6 +1,5 @@
 function(collect_boxing_module_source_files placeholder)
     set(SOURCE_FILES_BOXING
-            ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Double.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Float.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Integer.cpp
             ${CMAKE_CURRENT_SOURCE_DIR}/source/ls-std/boxing/Long.cpp

+ 0 - 1
include/ls-std/ls-std-boxing.hpp

@@ -15,7 +15,6 @@
  * @doc: boxing.description('This package provides functionalities for wrapping primitive datatypes (boolean, double, float, int, long, string). Wrapping those types would enable a developer to provide string representations, or parsing from strings to convert them back into their primitive forms. Additionally, these boxing types come with a great selection of operators and convenient functions.')
  * */
 
-#include <ls-std/boxing/Double.hpp>
 #include <ls-std/boxing/Float.hpp>
 #include <ls-std/boxing/Integer.hpp>
 #include <ls-std/boxing/Long.hpp>

+ 7 - 4
source/ls-std/boxing/Boolean.cppm

@@ -1,14 +1,14 @@
+export module ls.std.boxing.boolean;
+
 /*
  * Author:          Patrick-Christopher Mattulat
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-09
- * Changed:         2025-12-24
+ * Changed:         2025-12-25
  *
  * */
 
-module;
-
 #include <algorithm>
 #include <ls-std/core/Class.hpp>
 #include <ls-std/core/interface/IBoxing.hpp>
@@ -16,7 +16,10 @@ module;
 #include <ls-std/os/dynamic-goal.hpp>
 #include <string>
 
-export module ls.std.boxing.boolean;
+/*
+ * @doc: class(name: 'Boolean', package: 'boxing')
+ * @doc: boxing.Boolean.description('This class represents the primitive datatype bool and provides functionalities for boolean expressions and string representation.')
+ * */
 
 using ls::std::core::Class;
 using ls::std::core::IllegalArgumentException;

+ 0 - 242
source/ls-std/boxing/Double.cpp

@@ -1,242 +0,0 @@
-/*
- * Author:          Patrick-Christopher Mattulat
- * Company:         Lynar Studios
- * E-Mail:          webmaster@lynarstudios.com
- * Created:         2020-08-14
- * Changed:         2025-12-21
- *
- * */
-
-#include <cmath>
-#include <ls-std/boxing/Double.hpp>
-#include <ls-std/core/exception/IllegalArgumentException.hpp>
-
-using ls::std::boxing::Double;
-using ls::std::core::Class;
-using ls::std::core::IllegalArgumentException;
-using std::fabs;
-using std::stod;
-using std::string;
-using std::to_string;
-
-Double::Double() : Class(_fetchClassName())
-{
-  this->_assignEpsilon(0.00000001);
-}
-
-Double::Double(const double _value) : Class(_fetchClassName()), value(_value)
-{
-  this->_assignEpsilon(0.00000001);
-}
-
-Double::~Double() noexcept = default;
-
-Double &Double::operator=(const double _value)
-{
-  this->value = _value;
-  return *this;
-}
-
-double Double::operator-() const
-{
-  return -this->value;
-}
-
-double Double::operator+(const Double &_double) const
-{
-  return this->value + _double.getValue();
-}
-
-double Double::operator+(const double _value) const
-{
-  return this->value + _value;
-}
-
-double Double::operator*(const Double &_double) const
-{
-  return this->value * _double.getValue();
-}
-
-double Double::operator*(const double _value) const
-{
-  return this->value * _value;
-}
-
-double Double::operator-(const Double &_double) const
-{
-  return this->value - _double.getValue();
-}
-
-double Double::operator-(const double _value) const
-{
-  return this->value - _value;
-}
-
-double Double::operator/(const Double &_double) const
-{
-  return this->value / _double.getValue();
-}
-
-double Double::operator/(const double _value) const
-{
-  return this->value / _value;
-}
-
-Double &Double::operator+=(const Double &_double)
-{
-  this->value += _double.getValue();
-  return *this;
-}
-
-Double &Double::operator+=(const double _value)
-{
-  this->value += _value;
-  return *this;
-}
-
-Double &Double::operator-=(const Double &_double)
-{
-  this->value -= _double.getValue();
-  return *this;
-}
-
-Double &Double::operator-=(const double _value)
-{
-  this->value -= _value;
-  return *this;
-}
-
-Double &Double::operator*=(const Double &_double)
-{
-  this->value *= _double.getValue();
-  return *this;
-}
-
-Double &Double::operator*=(const double _value)
-{
-  this->value *= _value;
-  return *this;
-}
-
-Double &Double::operator/=(const Double &_double)
-{
-  this->value /= _double.getValue();
-  return *this;
-}
-
-Double &Double::operator/=(const double _value)
-{
-  this->value /= _value;
-  return *this;
-}
-
-bool Double::operator==(const Double &_double) const
-{
-  return fabs(this->value - _double.getValue()) < this->epsilon;
-}
-
-bool Double::operator==(const double _value) const
-{
-  return fabs(this->value - _value) < this->epsilon;
-}
-
-bool Double::operator!=(const Double &_double) const
-{
-  return fabs(this->value - _double.getValue()) >= this->epsilon;
-}
-
-bool Double::operator!=(const double _value) const
-{
-  return fabs(this->value - _value) >= this->epsilon;
-}
-
-bool Double::operator>(const Double &_double) const
-{
-  return this->value > _double.getValue();
-}
-
-bool Double::operator>(const double _value) const
-{
-  return this->value > _value;
-}
-
-bool Double::operator>=(const Double &_double) const
-{
-  return this->value >= _double.getValue();
-}
-
-bool Double::operator>=(const double _value) const
-{
-  return this->value >= _value;
-}
-
-bool Double::operator<(const Double &_double) const
-{
-  return this->value < _double.getValue();
-}
-
-bool Double::operator<(const double _value) const
-{
-  return this->value < _value;
-}
-
-bool Double::operator<=(const Double &_double) const
-{
-  return this->value <= _double.getValue();
-}
-
-bool Double::operator<=(const double _value) const
-{
-  return this->value <= _value;
-}
-
-void Double::operator++()
-{
-  this->value += 1.0;
-}
-
-void Double::operator--()
-{
-  this->value -= 1.0;
-}
-
-void Double::parse(const string &_parseText)
-{
-  this->value = stod(_parseText);
-}
-
-string Double::toString()
-{
-  return to_string(this->value);
-}
-
-double Double::getEpsilon() const
-{
-  return this->epsilon;
-}
-
-double Double::getValue() const
-{
-  return this->value;
-}
-
-void Double::setEpsilon(const double _epsilon)
-{
-  this->_assignEpsilon(_epsilon);
-}
-
-void Double::_assignEpsilon(const double _epsilon)
-{
-  if (_epsilon <= 0.0)
-  {
-    throw IllegalArgumentException{"_epsilon is less than or equal zero"};
-  }
-
-  this->epsilon = _epsilon;
-}
-
-string Double::_fetchClassName()
-{
-  static const string className = "Double";
-  return className;
-}

+ 264 - 0
source/ls-std/boxing/Double.cppm

@@ -0,0 +1,264 @@
+export module ls.std.boxing.double;
+
+/*
+ * Author:          Patrick-Christopher Mattulat
+ * Company:         Lynar Studios
+ * E-Mail:          webmaster@lynarstudios.com
+ * Created:         2020-08-14
+ * Changed:         2025-12-25
+ *
+ * */
+
+#include <cmath>
+#include <ls-std/core/Class.hpp>
+#include <ls-std/core/interface/IBoxing.hpp>
+#include <ls-std/core/exception/IllegalArgumentException.hpp>
+#include <ls-std/os/dynamic-goal.hpp>
+
+/*
+ * @doc: class(name: 'Double', package: 'boxing')
+ * @doc: boxing.Double.description('This class represents the primitive datatype double and provides functionalities for arithmetic operations, accuracy and string representation.')
+ * */
+
+using ls::std::core::Class;
+using ls::std::core::IllegalArgumentException;
+using ls::std::core::interface_type::IBoxing;
+using std::fabs;
+using std::stod;
+using std::string;
+using std::to_string;
+
+export namespace ls::std::boxing
+{
+  class LS_STD_DYNAMIC_GOAL Double : public Class, public IBoxing
+  {
+    public:
+
+      Double() : Class(_fetchClassName())
+      {
+        this->_assignEpsilon(0.00000001);
+      }
+
+      explicit Double(const double _value) : Class(_fetchClassName()), value(_value)
+      {
+        this->_assignEpsilon(0.00000001);
+      }
+
+      ~Double() noexcept override = default;
+
+      Double &operator=(const double _value)
+      {
+        this->value = _value;
+        return *this;
+      }
+
+      double operator-() const
+      {
+        return -this->value;
+      }
+
+      double operator+(const Double &_double) const
+      {
+        return this->value + _double.getValue();
+      }
+
+      double operator+(const double _value) const
+      {
+        return this->value + _value;
+      }
+
+      double operator*(const Double &_double) const
+      {
+        return this->value * _double.getValue();
+      }
+
+      double operator*(const double _value) const
+      {
+        return this->value * _value;
+      }
+
+      double operator-(const Double &_double) const
+      {
+        return this->value - _double.getValue();
+      }
+
+      double operator-(const double _value) const
+      {
+        return this->value - _value;
+      }
+
+      double operator/(const Double &_double) const
+      {
+        return this->value / _double.getValue();
+      }
+
+      double operator/(const double _value) const
+      {
+        return this->value / _value;
+      }
+
+      Double &operator+=(const Double &_double)
+      {
+        this->value += _double.getValue();
+        return *this;
+      }
+
+      Double &operator+=(const double _value)
+      {
+        this->value += _value;
+        return *this;
+      }
+
+      Double &operator-=(const Double &_double)
+      {
+        this->value -= _double.getValue();
+        return *this;
+      }
+
+      Double &operator-=(const double _value)
+      {
+        this->value -= _value;
+        return *this;
+      }
+
+      Double &operator*=(const Double &_double)
+      {
+        this->value *= _double.getValue();
+        return *this;
+      }
+
+      Double &operator*=(const double _value)
+      {
+        this->value *= _value;
+        return *this;
+      }
+
+      Double &operator/=(const Double &_double)
+      {
+        this->value /= _double.getValue();
+        return *this;
+      }
+
+      Double &operator/=(const double _value)
+      {
+        this->value /= _value;
+        return *this;
+      }
+
+      bool operator==(const Double &_double) const
+      {
+        return fabs(this->value - _double.getValue()) < this->epsilon;
+      }
+
+      bool operator==(const double _value) const
+      {
+        return fabs(this->value - _value) < this->epsilon;
+      }
+
+      bool operator!=(const Double &_double) const
+      {
+        return fabs(this->value - _double.getValue()) >= this->epsilon;
+      }
+
+      bool operator!=(const double _value) const
+      {
+        return fabs(this->value - _value) >= this->epsilon;
+      }
+
+      bool operator>(const Double &_double) const
+      {
+        return this->value > _double.getValue();
+      }
+
+      bool operator>(const double _value) const
+      {
+        return this->value > _value;
+      }
+
+      bool operator>=(const Double &_double) const
+      {
+        return this->value >= _double.getValue();
+      }
+
+      bool operator>=(const double _value) const
+      {
+        return this->value >= _value;
+      }
+
+      bool operator<(const Double &_double) const
+      {
+        return this->value < _double.getValue();
+      }
+
+      bool operator<(const double _value) const
+      {
+        return this->value < _value;
+      }
+
+      bool operator<=(const Double &_double) const
+      {
+        return this->value <= _double.getValue();
+      }
+
+      bool operator<=(const double _value) const
+      {
+        return this->value <= _value;
+      }
+
+      void operator++()
+      {
+        this->value += 1.0;
+      }
+
+      void operator--()
+      {
+        this->value -= 1.0;
+      }
+
+      void parse(const string &_parseText) override
+      {
+        this->value = stod(_parseText);
+      }
+
+      [[nodiscard]] string toString() override
+      {
+        return to_string(this->value);
+      }
+
+      [[nodiscard]] double getEpsilon() const
+      {
+        return this->epsilon;
+      }
+
+      [[nodiscard]] double getValue() const
+      {
+        return this->value;
+      }
+
+      void setEpsilon(const double _epsilon)
+      {
+        this->_assignEpsilon(_epsilon);
+      }
+
+    private:
+
+      double epsilon{};
+      double value{};
+
+      void _assignEpsilon(const double _epsilon)
+      {
+        if (_epsilon <= 0.0)
+        {
+          throw IllegalArgumentException{"_epsilon is less than or equal zero"};
+        }
+
+        this->epsilon = _epsilon;
+      }
+
+      [[nodiscard]] static string _fetchClassName()
+      {
+        static const string className = "Double";
+        return className;
+      }
+  };
+}

+ 3 - 2
test/cases/boxing/DoubleTest.cpp

@@ -3,14 +3,15 @@
  * Company:         Lynar Studios
  * E-Mail:          webmaster@lynarstudios.com
  * Created:         2020-08-14
- * Changed:         2025-12-21
+ * Changed:         2025-12-25
  *
  * */
 
 #include <gtest/gtest.h>
-#include <ls-std/ls-std-boxing.hpp>
 #include <ls-std/ls-std-core.hpp>
 
+import ls.std.boxing.double;
+
 using ls::std::boxing::Double;
 using ls::std::core::IllegalArgumentException;
 using std::string;