Trying to fix MString assignments.
This commit is contained in:
parent
74ab316e64
commit
d020363bc9
2
File.h
2
File.h
@ -16,7 +16,7 @@ namespace coreutils {
|
|||||||
class File {
|
class File {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
File(std::string fileName, int mode = O_RDONLY, int authority = 0664);
|
File(std::string fileName, int mode, int authority);
|
||||||
File(ZString &fileName, int mode = O_RDONLY, int authority = 0664);
|
File(ZString &fileName, int mode = O_RDONLY, int authority = 0664);
|
||||||
~File();
|
~File();
|
||||||
void setBufferSize(size_t size);
|
void setBufferSize(size_t size);
|
||||||
|
33
JSONFile.h
Normal file
33
JSONFile.h
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#ifndef __JSONFile_h__
|
||||||
|
#define __JSONFile_h__
|
||||||
|
|
||||||
|
#include "JString.h"
|
||||||
|
#include "File.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace coreutils {
|
||||||
|
|
||||||
|
///
|
||||||
|
/// Use the JSONFile object where you need a file based persistent backing store
|
||||||
|
/// for the JString style object.
|
||||||
|
///
|
||||||
|
|
||||||
|
class JSONFile : public JString : public File {
|
||||||
|
|
||||||
|
public:
|
||||||
|
JSONFile(ZString path): JString(), File(path, O_RDWR, 0644) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~JSONFile() {
|
||||||
|
write(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -63,7 +63,7 @@ namespace coreutils {
|
|||||||
if(label == path[0]) {
|
if(label == path[0]) {
|
||||||
if(path.getList().size() == 1)
|
if(path.getList().size() == 1)
|
||||||
{
|
{
|
||||||
std::cout << "cursor: " << unparsed() << std::endl;
|
// std::cout << "cursor: " << unparsed() << std::endl;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return locate(path[1]);
|
return locate(path[1]);
|
||||||
|
@ -56,9 +56,7 @@ namespace coreutils {
|
|||||||
Proxy(JString &jstring, ZString key) : jstring(jstring), key(key) {}
|
Proxy(JString &jstring, ZString key) : jstring(jstring), key(key) {}
|
||||||
|
|
||||||
operator coreutils::ZString () {
|
operator coreutils::ZString () {
|
||||||
ZString result;
|
return jstring.find(key);
|
||||||
result = jstring.find(key);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Proxy& operator=(coreutils::ZString value) {
|
Proxy& operator=(coreutils::ZString value) {
|
||||||
|
17
MString.cpp
17
MString.cpp
@ -81,11 +81,18 @@ namespace coreutils {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString &MString::operator=(coreutils::ZString value) {
|
MString &MString::operator=(coreutils::ZString value) {
|
||||||
setSize(value.getLength());
|
setSize(value.getLength());
|
||||||
memcpy(data, value.getData(), value.getLength());
|
memcpy(data, value.getData(), value.getLength());
|
||||||
length = value.getLength();
|
length = value.getLength();
|
||||||
return *this;
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MString &MString::operator=(std::string value) {
|
||||||
|
setSize(value.length());
|
||||||
|
memcpy(data, value.c_str(), value.length());
|
||||||
|
length = value.length();
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
MString &MString::operator=(const char *value) {
|
MString &MString::operator=(const char *value) {
|
||||||
|
@ -96,7 +96,9 @@ namespace coreutils
|
|||||||
///
|
///
|
||||||
|
|
||||||
MString &operator=(coreutils::MString data);
|
MString &operator=(coreutils::MString data);
|
||||||
MString &operator=(coreutils::ZString data);
|
MString &operator=(coreutils::ZString value);
|
||||||
|
|
||||||
|
MString &operator=(std::string value);
|
||||||
|
|
||||||
///
|
///
|
||||||
/// Assignment operator will copy data to backing store.
|
/// Assignment operator will copy data to backing store.
|
||||||
|
1
testing/json.sample
Normal file
1
testing/json.sample
Normal file
@ -0,0 +1 @@
|
|||||||
|
{"name":"Stephonivich","race":"Human","health","100"}
|
Binary file not shown.
Binary file not shown.
@ -29,6 +29,7 @@ int main(int argc, char **argv) {
|
|||||||
coreutils::MString test4;
|
coreutils::MString test4;
|
||||||
test4 << "this is a test." << test7;
|
test4 << "this is a test." << test7;
|
||||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||||
|
|
||||||
test4 << "another test " << 75;
|
test4 << "another test " << 75;
|
||||||
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
std::cout << "char* operator<<: [" << test4 << "]." << std::endl;
|
||||||
|
|
||||||
@ -64,10 +65,18 @@ int main(int argc, char **argv) {
|
|||||||
coreutils::MString test21;
|
coreutils::MString test21;
|
||||||
test21 = test20;
|
test21 = test20;
|
||||||
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
|
std::cout << "mstring = zstring: [" << test21 << "]" << std::endl;
|
||||||
|
|
||||||
coreutils::MString test22;
|
coreutils::MString test22;
|
||||||
test22 << test20;
|
test22 << test20;
|
||||||
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
|
std::cout << "mstring << zstring: [" << test22 << "]" << std::endl;
|
||||||
|
|
||||||
|
std::string test23 = "this is a string";
|
||||||
|
test22 = test23;
|
||||||
|
std::cout << "mstring = string: [" << test22 << "]" << std::endl;
|
||||||
|
|
||||||
|
test22 << test23;
|
||||||
|
std::cout << "mstring << string: [" << test22 << "]" << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Binary file not shown.
@ -1,5 +1,6 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "../ZString.h"
|
#include "../ZString.h"
|
||||||
|
#include "../MString.h"
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
@ -44,4 +45,12 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << "find MX: " << testA.find("MX") << std::endl;
|
std::cout << "find MX: " << testA.find("MX") << std::endl;
|
||||||
std::cout << "unparsed: " << testA.unparsed() << std::endl;
|
std::cout << "unparsed: " << testA.unparsed() << std::endl;
|
||||||
|
|
||||||
|
std::string testb = "this is a string";
|
||||||
|
coreutils::ZString testc = testb;
|
||||||
|
std::cout << testc << std::endl;
|
||||||
|
|
||||||
|
coreutils::MString testd = "this is an mstring";
|
||||||
|
testc = testd;
|
||||||
|
std::cout << testc << std::endl;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user