diff --git a/MString.cpp b/MString.cpp index d645ccd..7e03bac 100644 --- a/MString.cpp +++ b/MString.cpp @@ -2,6 +2,7 @@ #include "Log.h" #include "uuid/uuid.h" #include +#include #include #include @@ -80,6 +81,13 @@ namespace coreutils { this->length = fread(this->data, 1000000, 1000000, file); cursor = this->data; } + + MString::MString(double value) { + std::string data = std::to_string(value); + setSize(data.length()); + memcpy(this->data, (char *)data.c_str(), data.length()); + cursor = this->data; + } MString::~MString() { if (data) @@ -120,6 +128,14 @@ namespace coreutils { *data = value; return *this; } + + MString &MString::operator=(double value) { + std::string data = std::to_string(value); + setSize(data.length()); + memcpy(this->data, (char *)data.c_str(), data.length()); + cursor = this->data; + return *this; + } MString &MString::operator<<(const char *value) { int temp = length; diff --git a/MString.h b/MString.h index 70b8cdb..e44fa55 100644 --- a/MString.h +++ b/MString.h @@ -81,6 +81,12 @@ namespace coreutils { /// MString(std::FILE *file); + + /// + /// + /// + + MString(double value); /// /// @@ -117,6 +123,12 @@ namespace coreutils { MString &operator=(char data); + /// + /// Assignment operator for saving a double value.. + /// + + MString &operator=(double value); + /// /// /// diff --git a/testing/mstring_test b/testing/mstring_test index aca8e24..83b1d3e 100755 Binary files a/testing/mstring_test and b/testing/mstring_test differ diff --git a/testing/mstring_test.cpp b/testing/mstring_test.cpp index a258592..7f1590d 100644 --- a/testing/mstring_test.cpp +++ b/testing/mstring_test.cpp @@ -81,6 +81,14 @@ int main(int argc, char **argv) { // coreutils::MString test24 = std::endl; // std::cout << "mstring << endl: " << test24 << std::endl; + + coreutils::MString test25 = 3.14159; + std::cout << "float: " << test25 << std::endl; + + coreutils::MString test26; + double test27 = 4.0f; + test26 = test27; + std::cout << "float: " << test26 << std::endl; return 0; } diff --git a/testing/zstring_test b/testing/zstring_test index b9466d4..ed824d1 100755 Binary files a/testing/zstring_test and b/testing/zstring_test differ