testing changes and JString
This commit is contained in:
1 parent
f39bdc98f6
commit
2a8cfcee2a
5 files changed
+223
No files matched your search
Executable
BIN
Binary file not shown.
@@ -0,0 +1,33 @@
|
||||
#include <iostream>
|
||||
#include "../JString.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
// coreutils::JString test1;
|
||||
// std::cout << "empty jstring: [" << test1 << "]." << std::endl;
|
||||
// test1.set("key1", "data1");
|
||||
// std::cout << "add key1 jstring: [" << test1 << "]." << std::endl;
|
||||
// test1.set("key2", "data2");
|
||||
// std::cout << "add key2 jstring: [" << test1 << "]." << std::endl;
|
||||
// test1.set("key3", "data3");
|
||||
// std::cout << test1["key1"] << test1["key2"] << test1["key3"] << std::endl;
|
||||
// std::cout << test1 << std::endl;
|
||||
// test1.set("key2", "data5");
|
||||
// test1.set("key4", "data4");
|
||||
// std::cout << test1 << std::endl;
|
||||
|
||||
coreutils::JString test2("{\"key1\":[{\"id\":\"1\",\"name\":\"Brad\"},{\"id\":\"2\",\"name\":\"Jenn\"},{\"id\":\"3\",\"name\":\"Skye\"}],\"key2\":\"data5\",\"key3\":\"data3\",\"key4\":\"data4\"}");
|
||||
|
||||
// std::cout << test2["key2"] << std::endl;
|
||||
// std::cout << test2["key1"] << std::endl;
|
||||
// std::cout << "value: " << test2["key1.name[id=2]"] << std::endl;
|
||||
// std::cout << "value: " << test2["key1.name[id=3]"] << std::endl;
|
||||
|
||||
test2["key2"] = "newvalue1";
|
||||
std::cout << test2["key2"] << std::endl;
|
||||
// test2 = "newvalue";
|
||||
std::cout << test2 << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Executable
BIN
Binary file not shown.
@@ -0,0 +1,70 @@
|
||||
#include <iostream>
|
||||
#include <cstddef>
|
||||
|
||||
using namespace std;
|
||||
|
||||
struct proxy_obj;
|
||||
|
||||
struct my_bit_array
|
||||
{
|
||||
|
||||
uint8_t bit_array_;
|
||||
|
||||
proxy_obj operator[](int n);
|
||||
}
|
||||
;
|
||||
|
||||
struct proxy_obj
|
||||
{
|
||||
|
||||
my_bit_array& my_bit_array_;
|
||||
int n_;
|
||||
|
||||
proxy_obj(my_bit_array& bit_array, int n)
|
||||
: my_bit_array_(bit_array), n_(n)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
proxy_obj& operator=(bool b)
|
||||
{
|
||||
|
||||
uint8_t set_mask = 0x01 << n_;
|
||||
|
||||
if(b) my_bit_array_.bit_array_ |= set_mask;
|
||||
else my_bit_array_.bit_array_ &= (~set_mask);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
operator bool()
|
||||
{
|
||||
return my_bit_array_.bit_array_ & (0x01 << n_);
|
||||
}
|
||||
|
||||
}
|
||||
;
|
||||
|
||||
proxy_obj my_bit_array::operator[](int n)
|
||||
{
|
||||
|
||||
return proxy_obj(*this, n);
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
my_bit_array bit_set;
|
||||
|
||||
bit_set[0] = false;
|
||||
bool b = bit_set[0];
|
||||
cout << b << endl;
|
||||
|
||||
bit_set[3] = true;
|
||||
b = bit_set[3];
|
||||
cout << b << endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user