Fixed assignment of double to MString.
This commit is contained in:
parent
1cfdc23a57
commit
363a6aa496
16
MString.cpp
16
MString.cpp
@ -2,6 +2,7 @@
|
|||||||
#include "Log.h"
|
#include "Log.h"
|
||||||
#include "uuid/uuid.h"
|
#include "uuid/uuid.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <string>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -81,6 +82,13 @@ namespace coreutils {
|
|||||||
cursor = this->data;
|
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() {
|
MString::~MString() {
|
||||||
if (data)
|
if (data)
|
||||||
free(data);
|
free(data);
|
||||||
@ -121,6 +129,14 @@ namespace coreutils {
|
|||||||
return *this;
|
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) {
|
MString &MString::operator<<(const char *value) {
|
||||||
int temp = length;
|
int temp = length;
|
||||||
int len = strlen(value);
|
int len = strlen(value);
|
||||||
|
12
MString.h
12
MString.h
@ -86,6 +86,12 @@ namespace coreutils {
|
|||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
|
||||||
|
MString(double value);
|
||||||
|
|
||||||
|
///
|
||||||
|
///
|
||||||
|
///
|
||||||
|
|
||||||
virtual ~MString();
|
virtual ~MString();
|
||||||
|
|
||||||
// ~MString();
|
// ~MString();
|
||||||
@ -117,6 +123,12 @@ namespace coreutils {
|
|||||||
|
|
||||||
MString &operator=(char data);
|
MString &operator=(char data);
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Assignment operator for saving a double value..
|
||||||
|
///
|
||||||
|
|
||||||
|
MString &operator=(double value);
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
|
Binary file not shown.
@ -82,6 +82,14 @@ int main(int argc, char **argv) {
|
|||||||
// coreutils::MString test24 = std::endl;
|
// coreutils::MString test24 = std::endl;
|
||||||
// std::cout << "mstring << endl: " << 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user