diff --git a/File.h b/File.h index 280a6b9..f24502b 100644 --- a/File.h +++ b/File.h @@ -16,7 +16,7 @@ namespace coreutils { class File { 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(); void setBufferSize(size_t size); diff --git a/JSONFile.h b/JSONFile.h new file mode 100644 index 0000000..2d1eef8 --- /dev/null +++ b/JSONFile.h @@ -0,0 +1,33 @@ +#ifndef __JSONFile_h__ +#define __JSONFile_h__ + +#include "JString.h" +#include "File.h" +#include +#include + +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 diff --git a/JString.cpp b/JString.cpp index 1c8c5ee..a3f105d 100644 --- a/JString.cpp +++ b/JString.cpp @@ -63,7 +63,7 @@ namespace coreutils { if(label == path[0]) { if(path.getList().size() == 1) { - std::cout << "cursor: " << unparsed() << std::endl; +// std::cout << "cursor: " << unparsed() << std::endl; return true; } return locate(path[1]); diff --git a/JString.h b/JString.h index 0a16dca..cf36dc5 100644 --- a/JString.h +++ b/JString.h @@ -56,9 +56,7 @@ namespace coreutils { Proxy(JString &jstring, ZString key) : jstring(jstring), key(key) {} operator coreutils::ZString () { - ZString result; - result = jstring.find(key); - return result; + return jstring.find(key); } Proxy& operator=(coreutils::ZString value) { diff --git a/MString.cpp b/MString.cpp index 3a3aa17..bc56a65 100644 --- a/MString.cpp +++ b/MString.cpp @@ -81,13 +81,20 @@ namespace coreutils { return *this; } - MString &MString::operator=(coreutils::ZString value) { - setSize(value.getLength()); - memcpy(data, value.getData(), value.getLength()); - length = value.getLength(); - return *this; + MString &MString::operator=(coreutils::ZString value) { + setSize(value.getLength()); + memcpy(data, value.getData(), value.getLength()); + length = value.getLength(); + 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) { int len = strlen(value); setSize(len); diff --git a/MString.h b/MString.h index dcb96d7..41bf47d 100644 --- a/MString.h +++ b/MString.h @@ -94,9 +94,11 @@ namespace coreutils /// /// Assignment operator will copy data to backing store. /// - + 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. diff --git a/testing/json.sample b/testing/json.sample new file mode 100644 index 0000000..1fb16ca --- /dev/null +++ b/testing/json.sample @@ -0,0 +1 @@ +{"name":"Stephonivich","race":"Human","health","100"} \ No newline at end of file diff --git a/testing/jstring_test b/testing/jstring_test index 4517133..4854818 100755 Binary files a/testing/jstring_test and b/testing/jstring_test differ diff --git a/testing/mstring_test b/testing/mstring_test index abc082a..a38adc3 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 26ac054..fdf41e6 100644 --- a/testing/mstring_test.cpp +++ b/testing/mstring_test.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) { coreutils::MString ytest("this is a test"); xtest = ytest; std::cout << "assign mstring to mstring: " << xtest << std::endl; - + // Character assignment tests. coreutils::MString test3; test3 = 'a'; @@ -29,6 +29,7 @@ int main(int argc, char **argv) { coreutils::MString test4; test4 << "this is a test." << test7; std::cout << "char* operator<<: [" << test4 << "]." << std::endl; + test4 << "another test " << 75; std::cout << "char* operator<<: [" << test4 << "]." << std::endl; @@ -43,7 +44,7 @@ int main(int argc, char **argv) { std::cout << "streaming from std::string: [" << test14 << "]." << std::endl; coreutils::MString test9("XXXXXXXXXYYYYYYYYYY"); - std::cout << "test insert: " << test9 << std::endl; + std::cout << "test insert: " << test9 << std::endl; coreutils::MString test8("zzz"); test9.insert(test8, 9); test9.insert("aaaaa", 9); @@ -64,10 +65,18 @@ int main(int argc, char **argv) { coreutils::MString test21; test21 = test20; std::cout << "mstring = zstring: [" << test21 << "]" << std::endl; + coreutils::MString test22; test22 << test20; 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; } diff --git a/testing/zstring_test b/testing/zstring_test index 3210ac0..4fc5ae8 100755 Binary files a/testing/zstring_test and b/testing/zstring_test differ diff --git a/testing/zstring_test.cpp b/testing/zstring_test.cpp index 9233561..56ac33a 100644 --- a/testing/zstring_test.cpp +++ b/testing/zstring_test.cpp @@ -1,5 +1,6 @@ #include #include "../ZString.h" +#include "../MString.h" 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 << "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; + }