Teuchos_XMLParameterListReader.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "Teuchos_XMLParameterListReader.hpp"
00030 #include "Teuchos_TestForException.hpp"
00031 #include "Teuchos_StrUtils.hpp"
00032
00033 using namespace Teuchos;
00034
00035 XMLParameterListReader::XMLParameterListReader()
00036 {;}
00037
00038 ParameterList XMLParameterListReader::toParameterList(const XMLObject& xml) const
00039 {
00040 TEST_FOR_EXCEPTION(xml.getTag() != "ParameterList", std::runtime_error,
00041 "XMLParameterListReader expected tag ParameterList, found "
00042 << xml.getTag());
00043
00044 ParameterList rtn;
00045
00046 if (xml.hasAttribute("name"))
00047 {
00048 rtn.setName(xml.getAttribute("name"));
00049 }
00050
00051 for (int i=0; i<xml.numChildren(); i++)
00052 {
00053 XMLObject child = xml.getChild(i);
00054
00055 TEST_FOR_EXCEPTION( (child.getTag() != "ParameterList"
00056 && child.getTag() != "Parameter"),
00057 std::runtime_error,
00058 "XMLParameterListReader expected tag "
00059 "ParameterList or Parameter, found "
00060 << child.getTag());
00061
00062 if (child.getTag()=="ParameterList")
00063 {
00064 const std::string& name = child.getRequired("name");
00065
00066 ParameterList sublist = toParameterList(child);
00067 sublist.setName(name);
00068
00069 rtn.set(name, sublist);
00070 }
00071 else
00072 {
00073 const std::string& name = child.getRequired("name");
00074 const std::string& type = child.getRequired("type");
00075
00076 bool isDefault = false;
00077 bool isUsed = false;
00078 if (child.hasAttribute("isDefault"))
00079 {
00080 isDefault = child.getRequiredBool("isDefault");
00081 }
00082 if (child.hasAttribute("isUsed"))
00083 {
00084 isUsed = child.getRequiredBool("isUsed");
00085 }
00086
00087
00088
00089
00090 ParameterEntry entry;
00091 if (type=="double" || type=="float")
00092 {
00093 entry.setValue<double>(child.getRequiredDouble("value"),
00094 isDefault);
00095 if (isUsed) {
00096 double tmp = entry.getValue<double>(&tmp);
00097 }
00098 }
00099 else if (type=="int")
00100 {
00101 entry.setValue<int>(child.getRequiredInt("value"),
00102 isDefault);
00103 if (isUsed) {
00104 int tmp = entry.getValue<int>(&tmp);
00105 }
00106 }
00107 else if (type=="bool")
00108 {
00109 entry.setValue<bool>(child.getRequiredBool("value"),
00110 isDefault);
00111 if (isUsed) {
00112 bool tmp = entry.getValue<bool>(&tmp);
00113 }
00114 }
00115 else if (type=="string")
00116 {
00117 entry.setValue<std::string>(child.getRequired("value"),
00118 isDefault);
00119 if (isUsed) {
00120 std::string tmp = entry.getValue<std::string>(&tmp);
00121 }
00122 }
00123 else
00124 {
00125 entry.setValue<std::string>(child.getRequired("value"),
00126 isDefault);
00127 if (isUsed) {
00128 std::string tmp = entry.getValue<std::string>(&tmp);
00129 }
00130 }
00131 rtn.setEntry(name, entry);
00132 }
00133
00134 }
00135
00136 return rtn;
00137
00138 }