mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-04 19:25:56 +01:00
Fixing JSON error for complex numbers
This commit is contained in:
parent
8ba0494485
commit
5aafa335fe
@ -40,10 +40,8 @@ JSONWriter::~JSONWriter(void)
|
|||||||
delete_comma();
|
delete_comma();
|
||||||
ss_ << "}";
|
ss_ << "}";
|
||||||
|
|
||||||
cout << ss_.str() << endl;
|
|
||||||
// write prettified JSON to file
|
// write prettified JSON to file
|
||||||
std::ofstream os(fileName_);
|
std::ofstream os(fileName_);
|
||||||
std::cout << "Writing on file" << std::endl;
|
|
||||||
os << std::setw(2) << json::parse(ss_.str()) << std::endl;
|
os << std::setw(2) << json::parse(ss_.str()) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,7 +94,7 @@ JSONReader::JSONReader(const string &fileName)
|
|||||||
|
|
||||||
// test
|
// test
|
||||||
// serialize to standard output
|
// serialize to standard output
|
||||||
std::cout << "JSONReader::JSONReader : " << jobject_ << endl;
|
//std::cout << "JSONReader::JSONReader : " << jobject_ << endl;
|
||||||
jcur_ = jobject_;
|
jcur_ = jobject_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +112,7 @@ bool JSONReader::push(const string &s)
|
|||||||
std::cout << "out of range: " << e.what() << '\n';
|
std::cout << "out of range: " << e.what() << '\n';
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cout << "JSONReader::push : " << s << " : "<< jcur_ << endl;
|
//cout << "JSONReader::push : " << s << " : "<< jcur_ << endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -135,7 +133,7 @@ void JSONReader::pop(void)
|
|||||||
else
|
else
|
||||||
do_pop.pop_back();
|
do_pop.pop_back();
|
||||||
|
|
||||||
cout << "JSONReader::pop : " << jcur_ << endl;
|
//cout << "JSONReader::pop : " << jcur_ << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JSONReader::nextElement(const std::string &s)
|
bool JSONReader::nextElement(const std::string &s)
|
||||||
@ -158,14 +156,14 @@ bool JSONReader::nextElement(const std::string &s)
|
|||||||
template <>
|
template <>
|
||||||
void JSONReader::readDefault(const string &s, string &output)
|
void JSONReader::readDefault(const string &s, string &output)
|
||||||
{
|
{
|
||||||
cout << "JSONReader::readDefault(string) : " << s<< " " << jcur_ << endl;
|
//cout << "JSONReader::readDefault(string) : " << s<< " " << jcur_ << endl;
|
||||||
if (s.size()){
|
if (s.size()){
|
||||||
std::cout << "String: "<< jcur_[s] << std::endl;
|
//std::cout << "String: "<< jcur_[s] << std::endl;
|
||||||
output = jcur_[s];
|
output = jcur_[s];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "String: "<< jcur_ << std::endl;
|
//std::cout << "String: "<< jcur_ << std::endl;
|
||||||
output = jcur_;
|
output = jcur_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ namespace Grid
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
void JSONWriter::writeDefault(const std::string &s, const U &x)
|
void JSONWriter::writeDefault(const std::string &s, const U &x)
|
||||||
{
|
{
|
||||||
std::cout << "JSONReader::writeDefault(U) : " << s << std::endl;
|
//std::cout << "JSONReader::writeDefault(U) : " << s << std::endl;
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << std::boolalpha << x;
|
os << std::boolalpha << x;
|
||||||
if (s.size())
|
if (s.size())
|
||||||
@ -118,7 +118,7 @@ namespace Grid
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
void JSONWriter::writeDefault(const std::string &s, const std::complex<U> &x)
|
void JSONWriter::writeDefault(const std::string &s, const std::complex<U> &x)
|
||||||
{
|
{
|
||||||
std::cout << "JSONReader::writeDefault(complex) : " << s << std::endl;
|
//std::cout << "JSONReader::writeDefault(complex) : " << s << std::endl;
|
||||||
std::ostringstream os;
|
std::ostringstream os;
|
||||||
os << "["<< std::boolalpha << x.real() << ", " << x.imag() << "]";
|
os << "["<< std::boolalpha << x.real() << ", " << x.imag() << "]";
|
||||||
if (s.size())
|
if (s.size())
|
||||||
@ -130,7 +130,7 @@ namespace Grid
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
void JSONWriter::writeDefault(const std::string &s, const std::vector<U> &x)
|
void JSONWriter::writeDefault(const std::string &s, const std::vector<U> &x)
|
||||||
{
|
{
|
||||||
std::cout << "JSONReader::writeDefault(vec U) : " << s << std::endl;
|
//std::cout << "JSONReader::writeDefault(vec U) : " << s << std::endl;
|
||||||
|
|
||||||
if (s.size())
|
if (s.size())
|
||||||
ss_ << " \""<<s<<"\" : [";
|
ss_ << " \""<<s<<"\" : [";
|
||||||
@ -146,7 +146,7 @@ namespace Grid
|
|||||||
|
|
||||||
template<std::size_t N>
|
template<std::size_t N>
|
||||||
void JSONWriter::writeDefault(const std::string &s, const char(&x)[N]){
|
void JSONWriter::writeDefault(const std::string &s, const char(&x)[N]){
|
||||||
std::cout << "JSONReader::writeDefault(char U) : " << s << std::endl;
|
//std::cout << "JSONReader::writeDefault(char U) : " << s << std::endl;
|
||||||
|
|
||||||
if (s.size())
|
if (s.size())
|
||||||
ss_ << "\""<< s << "\" : \"" << x << "\" ," ;
|
ss_ << "\""<< s << "\" : \"" << x << "\" ," ;
|
||||||
@ -158,15 +158,15 @@ namespace Grid
|
|||||||
template <typename U>
|
template <typename U>
|
||||||
void JSONReader::readDefault(const std::string &s, U &output)
|
void JSONReader::readDefault(const std::string &s, U &output)
|
||||||
{
|
{
|
||||||
std::cout << "JSONReader::readDefault(U) : " << s << " : "<< jcur_ << std::endl;
|
//std::cout << "JSONReader::readDefault(U) : " << s << " : "<< jcur_ << std::endl;
|
||||||
|
|
||||||
if (s.size()){
|
if (s.size()){
|
||||||
std::cout << "String: "<< jcur_[s] << std::endl;
|
//std::cout << "String: "<< jcur_[s] << std::endl;
|
||||||
output = jcur_[s];
|
output = jcur_[s];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "String: "<< jcur_ << std::endl;
|
//std::cout << "String: "<< jcur_ << std::endl;
|
||||||
output = jcur_;
|
output = jcur_;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -177,7 +177,7 @@ namespace Grid
|
|||||||
void JSONReader::readDefault(const std::string &s, std::complex<U> &output)
|
void JSONReader::readDefault(const std::string &s, std::complex<U> &output)
|
||||||
{
|
{
|
||||||
U tmp1, tmp2;
|
U tmp1, tmp2;
|
||||||
std::cout << "JSONReader::readDefault( complex U) : " << s << " : "<< jcur_ << std::endl;
|
//std::cout << "JSONReader::readDefault( complex U) : " << s << " : "<< jcur_ << std::endl;
|
||||||
json j = jcur_;
|
json j = jcur_;
|
||||||
json::iterator it = j.begin();
|
json::iterator it = j.begin();
|
||||||
jcur_ = *it;
|
jcur_ = *it;
|
||||||
@ -197,14 +197,14 @@ namespace Grid
|
|||||||
{
|
{
|
||||||
std::string buf;
|
std::string buf;
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
std::cout << "JSONReader::readDefault(vec) : " << jcur_ << std::endl;
|
//std::cout << "JSONReader::readDefault(vec) : " << jcur_ << std::endl;
|
||||||
if (s.size())
|
if (s.size())
|
||||||
push(s);
|
push(s);
|
||||||
|
|
||||||
json j = jcur_;
|
json j = jcur_;
|
||||||
for (json::iterator it = j.begin(); it != j.end(); ++it) {
|
for (json::iterator it = j.begin(); it != j.end(); ++it) {
|
||||||
jcur_ = *it;
|
jcur_ = *it;
|
||||||
std::cout << "Value: " << it.value() << "\n";
|
//std::cout << "Value: " << it.value() << "\n";
|
||||||
output.resize(i + 1);
|
output.resize(i + 1);
|
||||||
read("", output[i++]);
|
read("", output[i++]);
|
||||||
}
|
}
|
||||||
|
@ -233,11 +233,13 @@ int main(int argc,char **argv)
|
|||||||
myclass jcopy1;
|
myclass jcopy1;
|
||||||
std::vector<myclass> jveccopy1;
|
std::vector<myclass> jveccopy1;
|
||||||
read(RD,"obj",jcopy1);
|
read(RD,"obj",jcopy1);
|
||||||
//read(RD,"objvec", jveccopy1);
|
read(RD,"objvec", jveccopy1);
|
||||||
//std::cout << "Loaded (JSON) -----------------" << std::endl;
|
std::cout << "Loaded (JSON) -----------------" << std::endl;
|
||||||
//std::cout << jcopy1 << std::endl << jveccopy1 << std::endl;
|
std::cout << jcopy1 << std::endl << jveccopy1 << std::endl;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
/*
|
||||||
|
// This is still work in progress
|
||||||
{
|
{
|
||||||
// Testing the next element function
|
// Testing the next element function
|
||||||
JSONReader RD("test.json");
|
JSONReader RD("test.json");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user