26#include <ql/errors.hpp>
27#include <ql/time/period.hpp>
28#include <ql/time/calendar.hpp>
29#include <ql/time/businessdayconvention.hpp>
30#include <ql/types.hpp>
52using QuantLib::Period;
78 void toFile(
const string& filename)
const;
107 void fromFile(
const std::string& filename);
108 void toFile(
const std::string& filename)
const;
129 const vector<string>& attrNames,
const vector<string>& attrs);
138 std::ostringstream oss;
145 const string& attrName =
"",
const string& attr =
"") {
146 std::ostringstream oss;
147 if (values.size() == 0) {
151 for (Size i = 1; i < values.size(); i++) {
152 oss <<
", " << values[i];
158 template <
class T =
string>
160 const vector<T>& values);
163 template <
class T =
string>
166 const vector<T>& values,
const string& attrName,
167 const vector<string>& attrs);
168 template <
class T =
string>
170 const vector<T>& values,
const vector<string>& attrNames,
171 const vector<vector<string>>& attrs);
172 template <
class T =
string>
174 const vector<T>& values,
const string& attrName,
175 const vector<string>& attrs);
176 template <
class T =
string>
178 const vector<T>& values,
const vector<string>& attrNames,
179 const vector<vector<string>>& attrs);
182 const string& firstName,
const string& secondName,
const map<string, string>& values);
185 static string getChildValue(
XMLNode* node,
const string&
name,
bool mandatory =
false,
const string& defaultValue =
string());
190 const QuantLib::Period& defaultValue = 0 * QuantLib::Days);
192 bool mandatory =
false);
193 static vector<string>
195 vector<string>& attrs,
196 bool mandatory =
false);
199 const vector<string>& attrNames,
200 const vector<std::reference_wrapper<vector<string>>>& attrs,
201 bool mandatory =
false);
204 const string& attrName, vector<string>& attrs,
205 const std::function<T(
string)> parser,
206 bool mandatory =
false);
210 const vector<string>& attrNames,
211 const vector<std::reference_wrapper<vector<string>>>& attrs,
212 const std::function<T(
string)> parser,
213 bool mandatory =
false);
216 bool mandatory =
false);
223 const string& firstName,
const string& secondName,
224 bool mandatory =
false);
227 const string& attributeName,
bool mandatory =
false);
244 const string& attrName, vector<string>& attrs,
245 bool mandatory =
false);
247 const vector<string>& attrNames,
248 const vector<std::reference_wrapper<vector<string>>>& attrs,
249 bool mandatory =
false);
Small XML Document wrapper class.
void appendNode(XMLNode *)
XMLDocument()
create an empty doc.
std::string toString() const
return the XML Document as a string.
rapidxml::xml_document< char > * doc()
XMLNode * allocNode(const string &nodeName)
util functions that wrap rapidxml
void toFile(const string &filename) const
save the XML Document to the given file.
void fromXMLString(const string &xmlString)
load a document from a hard-coded string
rapidxml::xml_document< char > * _doc
XMLNode * getFirstNode(const string &name) const
char * allocString(const string &str)
Base class for all serializable classes.
std::string toXMLString() const
Parse from XML string.
virtual ~XMLSerializable()
void fromXMLString(const std::string &xml)
Parse from XML string.
virtual XMLNode * toXML(XMLDocument &doc) const =0
virtual void fromXML(XMLNode *node)=0
void fromFile(const std::string &filename)
void toFile(const std::string &filename) const
static void addChildrenWithAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
static void addAttribute(XMLDocument &doc, XMLNode *node, const string &attrName, const string &attrValue)
static vector< Real > getChildrenValuesAsDoubles(XMLNode *node, const string &names, const string &name, bool mandatory=false)
static void addChildren(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values)
static string getAttribute(XMLNode *node, const string &attrName)
static void addGenericChildAsList(XMLDocument &doc, XMLNode *n, const string &name, const vector< T > &values, const string &attrName="", const string &attr="")
static void checkNode(XMLNode *n, const string &expectedName)
static void addGenericChild(XMLDocument &doc, XMLNode *n, const char *name, const T &value)
Adds <Name>p1,p2,p3</Name>
static vector< XMLNode * > getChildrenNodes(XMLNode *node, const string &name)
Returns all the children with a given name.
static Real getChildValueAsDouble(XMLNode *node, const string &name, bool mandatory=false, double defaultValue=0.0)
static XMLNode * locateNode(XMLNode *n, const string &name="")
static void addChildAsCdata(XMLDocument &doc, XMLNode *n, const string &name, const string &value)
static string getNodeName(XMLNode *n)
Get and set a node's name.
static map< string, string > getChildrenAttributesAndValues(XMLNode *parent, const string &names, const string &attributeName, bool mandatory=false)
static string getChildValue(XMLNode *node, const string &name, bool mandatory=false, const string &defaultValue=string())
static bool getChildValueAsBool(XMLNode *node, const string &name, bool mandatory=false, bool defaultValue=true)
static XMLNode * getChildNode(XMLNode *n, const string &name="")
static void addChildrenWithOptionalAttributes(XMLDocument &doc, XMLNode *n, const string &names, const string &name, const vector< T > &values, const string &attrName, const vector< string > &attrs)
static string getNodeValue(XMLNode *node)
Get a node's value.
static int getChildValueAsInt(XMLNode *node, const string &name, bool mandatory=false, int defaultValue=0)
static Period getChildValueAsPeriod(XMLNode *node, const string &name, bool mandatory=false, const QuantLib::Period &defaultValue=0 *QuantLib::Days)
static XMLNode * getNextSibling(XMLNode *node, const string &name="")
Get a node's next sibling node.
static vector< string > getChildrenValuesAsStrings(XMLNode *node, const string &name, bool mandatory=false)
static vector< string > getChildrenValuesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
static vector< Real > getChildrenValuesAsDoublesCompact(XMLNode *node, const string &name, bool mandatory=false)
static string convertToString(const Real value)
static vector< string > getChildrenValues(XMLNode *node, const string &names, const string &name, bool mandatory=false)
static void setNodeName(XMLDocument &doc, XMLNode *node, const string &name)
static XMLNode * addChild(XMLDocument &doc, XMLNode *n, const string &name)
static string toString(XMLNode *node)
Write a node out as a string.
static void appendNode(XMLNode *parent, XMLNode *child)
static vector< Period > getChildrenValuesAsPeriods(XMLNode *node, const string &name, bool mandatory=false)
static vector< XMLNode * > getChildrenNodesWithAttributes(XMLNode *node, const string &names, const string &name, const string &attrName, vector< string > &attrs, bool mandatory=false)
static vector< Real > getNodeValueAsDoublesCompact(XMLNode *node)
Get a node's compact values as vector of doubles.
SafeStack< ValueType > value
rapidxml::xml_node< char > XMLNode
Serializable Credit Default Swap.