|
1 | 1 | #include <boost/filesystem.hpp>
|
2 | 2 | #include <boost/lexical_cast.hpp>
|
3 | 3 | #include <sstream>
|
| 4 | +#include <string> |
4 | 5 | #include "meta.h"
|
5 | 6 | #include "../log/log.h"
|
6 | 7 | #include "../kit.h"
|
@@ -344,7 +345,7 @@ MetaLoop MetaBase<Mutex,Storage,This>::each(
|
344 | 345 |
|
345 | 346 | // use type checks with typeid() before attempting conversion
|
346 | 347 | // or boost::any cast?
|
347 |
| -// POD types should also work if behind smart ptrs |
| 348 | +// POD types should also work if behind smart ptrs -- not yet impl |
348 | 349 | // only Storage's to other trees should serialize (not weak)
|
349 | 350 |
|
350 | 351 | /*
|
@@ -532,17 +533,42 @@ std::string MetaBase<Mutex,Storage,This> :: serialize(MetaFormat fmt, unsigned f
|
532 | 533 | if(m)
|
533 | 534 | {
|
534 | 535 | data += "["+e.key+"]\n";
|
535 |
| - for(auto&& j: *m) |
536 |
| - data += j.key + "=" + kit::any_to_string(j.value) + "\n"; |
| 536 | + for(auto&& j: *m){ |
| 537 | + // TODO: write sub category [foo.bar] |
| 538 | + //if(e.type.id==MetaType::ID::META) |
| 539 | + // data += j.key + "=" + boost::any_cast<Storage<MetaBase<Mutex,Storage,This>>>(j.value) + "\n"; |
| 540 | + if(j.type.id==MetaType::ID::INT) |
| 541 | + data += j.key + "=" + std::to_string(boost::any_cast<int>(j.value)) + "\n"; |
| 542 | + else if(j.type.id==MetaType::ID::REAL) |
| 543 | + data += j.key + "=" + std::to_string(boost::any_cast<double>(j.value)) + "\n"; |
| 544 | + else if(j.type.id==MetaType::ID::BOOL) |
| 545 | + data += j.key + "=" + (boost::any_cast<bool>(j.value)?"true":"false") + "\n"; |
| 546 | + else if(j.type.id==MetaType::ID::STRING) |
| 547 | + data += j.key + "=" + boost::any_cast<std::string>(j.value) + "\n"; |
| 548 | + else{ |
| 549 | + //LOG(std::to_string(int(j.type.id))); |
| 550 | + WARNING("warning: cannot serialize value"); |
| 551 | + } |
| 552 | + } |
537 | 553 | data += "\n";
|
538 | 554 | }
|
539 | 555 | else
|
540 | 556 | {
|
541 |
| - data += e.key + "=" + kit::any_to_string(e.value) + "\n"; |
| 557 | + //data += e.key + "=" + kit::any_to_string(e.value) + "\n"; |
| 558 | + if(e.type.id==MetaType::ID::INT) |
| 559 | + data += e.key + "=" + std::to_string(boost::any_cast<int>(e.value)) + "\n"; |
| 560 | + else if(e.type.id==MetaType::ID::REAL) |
| 561 | + data += e.key + "=" + std::to_string(boost::any_cast<double>(e.value)) + "\n"; |
| 562 | + else if(e.type.id==MetaType::ID::BOOL) |
| 563 | + data += e.key + "=" + (boost::any_cast<bool>(e.value)?"true":"false") + "\n"; |
| 564 | + else if(e.type.id==MetaType::ID::STRING) |
| 565 | + data += e.key + "=" + boost::any_cast<std::string>(e.value) + "\n"; |
| 566 | + else |
| 567 | + WARNING("warning: cannot serialize value"); |
542 | 568 | }
|
543 | 569 | }
|
544 | 570 | }
|
545 |
| - //else if (fmt == MetaFormat::HUMAN) |
| 571 | + //else if (fmt == MetaFormat::YAML) |
546 | 572 | // assert(false);
|
547 | 573 | else
|
548 | 574 | assert(false);
|
@@ -653,9 +679,8 @@ void MetaBase<Mutex,Storage,This> :: deserialize(MetaFormat fmt, std::istream& d
|
653 | 679 | //deserialize_json(root, pth_vec);
|
654 | 680 | }
|
655 | 681 | }
|
656 |
| - else if (fmt == MetaFormat::HUMAN) |
| 682 | + else if (fmt == MetaFormat::YAML) |
657 | 683 | {
|
658 |
| - // human deserialization unsupported |
659 | 684 | assert(false);
|
660 | 685 | }
|
661 | 686 | else if (fmt == MetaFormat::INI)
|
|
0 commit comments