Teuchos_XMLParameterListWriter.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_XMLParameterListWriter.hpp"
00030
00031 using namespace Teuchos;
00032
00033 XMLParameterListWriter::XMLParameterListWriter()
00034 {;}
00035
00036
00037 XMLObject XMLParameterListWriter::toXML(const ParameterList& p) const
00038 {
00039 XMLObject rtn("ParameterList");
00040
00041 for (ParameterList::ConstIterator i=p.begin(); i!=p.end(); ++i)
00042 {
00043 const ParameterEntry& val = p.entry(i);
00044 const std::string& name = p.name(i);
00045 XMLObject child = toXML(val);
00046 child.addAttribute("name", name);
00047 rtn.addChild(child);
00048 }
00049
00050 return rtn;
00051 }
00052
00053 XMLObject XMLParameterListWriter::toXML(const ParameterEntry& entry) const
00054 {
00055 if (entry.isList())
00056 {
00057 return toXML(getValue<ParameterList>(entry));
00058 }
00059
00060 XMLObject rtn("Parameter");
00061 std::string type;
00062 std::string value;
00063
00064 if (entry.isType<int>())
00065 {
00066 type = "int";
00067 value = toString(any_cast<int>(entry.getAny(false)));
00068 }
00069 else if (entry.isType<double>())
00070 {
00071 type = "double";
00072 value = toString(any_cast<double>(entry.getAny(false)));
00073 }
00074 else if (entry.isType<float>())
00075 {
00076 type = "float";
00077 value = toString(any_cast<float>(entry.getAny(false)));
00078 }
00079 else if (entry.isType<std::string>())
00080 {
00081 type = "string";
00082 value = toString(any_cast<std::string>(entry.getAny(false)));
00083 }
00084 else if (entry.isType<char>())
00085 {
00086 type = "char";
00087 value = toString(any_cast<char>(entry.getAny(false)));
00088 }
00089 else if (entry.isType<bool>())
00090 {
00091 type = "bool";
00092 value = toString(any_cast<bool>(entry.getAny(false)));
00093 }
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 else
00118 {
00119 type = "any";
00120 std::ostringstream ss;
00121 ss << entry;
00122 value = TEUCHOS_OSTRINGSTREAM_GET_C_STR(ss);
00123 }
00124
00125
00126 rtn.addAttribute("type", type);
00127 rtn.addAttribute("value", value);
00128
00129 if (entry.isDefault())
00130 {
00131 rtn.addAttribute("isDefault", "true");
00132 }
00133
00134 if (entry.isUsed())
00135 {
00136 rtn.addAttribute("isUsed","true");
00137 }
00138
00139 return rtn;
00140 }