mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-13 04:37:05 +01:00
Added JSON parser (without NextElement)
This commit is contained in:
@ -4,8 +4,9 @@
|
||||
|
||||
Source file: ./tests/Test_serialisation.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
Copyright (C) 2015-2016
|
||||
|
||||
Author: Guido Cossu <guido.cossu@ed.ac.uk>
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
@ -58,6 +59,7 @@ namespace Grid {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
using namespace Grid;
|
||||
@ -154,4 +156,51 @@ int main(int argc,char **argv)
|
||||
std::cout << e << " ";
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
std::cout << ".:::::: Testing JSON classes "<< std::endl;
|
||||
|
||||
|
||||
{
|
||||
JSONWriter JW("bother.json");
|
||||
|
||||
// test basic type writing
|
||||
push(JW,"BasicTypes");
|
||||
write(JW,std::string("i16"),i16);
|
||||
write(JW,"u16",u16);
|
||||
write(JW,"i32",i32);
|
||||
write(JW,"u32",u32);
|
||||
write(JW,"i64",i64);
|
||||
write(JW,"u64",u64);
|
||||
write(JW,"f",f);
|
||||
write(JW,"d",d);
|
||||
write(JW,"b",b);
|
||||
pop(JW);
|
||||
|
||||
// test serializable class writing
|
||||
myclass obj(1234); // non-trivial constructor
|
||||
write(JW,"obj",obj);
|
||||
JW.write("obj2", obj);
|
||||
|
||||
std::cout << obj << std::endl;
|
||||
|
||||
std::vector<myclass> vec;
|
||||
vec.push_back(myclass(1234));
|
||||
vec.push_back(myclass(5678));
|
||||
vec.push_back(myclass(3838));
|
||||
write(JW, "objvec", vec);
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
JSONReader RD("bother.json");
|
||||
myclass jcopy1;
|
||||
std::vector<myclass> jveccopy1;
|
||||
read(RD,"obj",jcopy1);
|
||||
read(RD,"objvec", jveccopy1);
|
||||
std::cout << "Loaded (JSON) -----------------" << std::endl;
|
||||
std::cout << jcopy1 << std::endl << jveccopy1 << std::endl;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user