Mercurial > hg > orthanc
comparison Plugins/Samples/Common/OrthancPluginCppWrapper.cpp @ 2265:e46b0ee6c19d
allowSingleString in OrthancConfiguration::LookupListOfStrings
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 14 Feb 2017 15:59:19 +0100 |
parents | 8e5e0de75839 |
children | a344e47e9c9a |
comparison
equal
deleted
inserted
replaced
2264:8e5e0de75839 | 2265:e46b0ee6c19d |
---|---|
596 } | 596 } |
597 } | 597 } |
598 | 598 |
599 | 599 |
600 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, | 600 bool OrthancConfiguration::LookupListOfStrings(std::list<std::string>& target, |
601 const std::string& key) const | 601 const std::string& key, |
602 bool allowSingleString) const | |
602 { | 603 { |
603 assert(configuration_.type() == Json::objectValue); | 604 assert(configuration_.type() == Json::objectValue); |
604 | 605 |
605 target.clear(); | 606 target.clear(); |
606 | 607 |
607 if (!configuration_.isMember(key)) | 608 if (!configuration_.isMember(key)) |
608 { | 609 { |
609 return false; | 610 return false; |
610 } | 611 } |
611 | 612 |
612 bool ok = true; | 613 switch (configuration_[key].type()) |
614 { | |
615 case Json::arrayValue: | |
616 { | |
617 bool ok = true; | |
613 | 618 |
614 if (configuration_[key].type() != Json::arrayValue) | 619 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) |
615 { | |
616 ok = false; | |
617 } | |
618 else | |
619 { | |
620 for (Json::Value::ArrayIndex i = 0; ok && i < configuration_[key].size(); i++) | |
621 { | |
622 if (configuration_[key][i].type() == Json::stringValue) | |
623 { | 620 { |
624 target.push_back(configuration_[key][i].asString()); | 621 if (configuration_[key][i].type() == Json::stringValue) |
622 { | |
623 target.push_back(configuration_[key][i].asString()); | |
624 } | |
625 else | |
626 { | |
627 ok = false; | |
628 } | |
625 } | 629 } |
626 else | 630 |
631 if (ok) | |
627 { | 632 { |
628 ok = false; | 633 return true; |
629 } | 634 } |
635 | |
636 break; | |
630 } | 637 } |
631 } | 638 |
632 | 639 case Json::stringValue: |
633 if (ok) | 640 if (allowSingleString) |
634 { | 641 { |
635 return true; | 642 target.push_back(configuration_[key].asString()); |
636 } | 643 return true; |
637 else | 644 } |
638 { | 645 |
639 if (context_ != NULL) | 646 break; |
640 { | 647 |
641 std::string s = ("The configuration option \"" + GetPath(key) + | 648 default: |
642 "\" is not a list of strings as expected"); | 649 break; |
643 OrthancPluginLogError(context_, s.c_str()); | 650 } |
644 } | 651 |
645 | 652 if (context_ != NULL) |
646 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | 653 { |
647 } | 654 std::string s = ("The configuration option \"" + GetPath(key) + |
655 "\" is not a list of strings as expected"); | |
656 OrthancPluginLogError(context_, s.c_str()); | |
657 } | |
658 | |
659 ORTHANC_PLUGINS_THROW_EXCEPTION(BadFileFormat); | |
648 } | 660 } |
649 | 661 |
650 | 662 |
651 std::string OrthancConfiguration::GetStringValue(const std::string& key, | 663 std::string OrthancConfiguration::GetStringValue(const std::string& key, |
652 const std::string& defaultValue) const | 664 const std::string& defaultValue) const |