amount_t and commodity_t objects can now stream themselves to XML.
This commit is contained in:
parent
e851c02d27
commit
094c64b67c
5 changed files with 68 additions and 0 deletions
|
|
@ -1396,6 +1396,22 @@ void amount_t::write(std::ostream& out, unsigned int index) const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void amount_t::read_xml(std::istream& in)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void amount_t::write_xml(std::ostream& out, const int depth) const
|
||||||
|
{
|
||||||
|
xml_print(out, "<amount>\n", depth);
|
||||||
|
|
||||||
|
commodity().write_xml(out, depth + 1);
|
||||||
|
|
||||||
|
xml_print(out, "<quantity>", depth + 1);
|
||||||
|
out << quantity_string() << "</quantity>\n";
|
||||||
|
|
||||||
|
xml_print(out, "</amount>\n", depth);
|
||||||
|
}
|
||||||
|
|
||||||
bool amount_t::valid() const
|
bool amount_t::valid() const
|
||||||
{
|
{
|
||||||
if (quantity) {
|
if (quantity) {
|
||||||
|
|
|
||||||
|
|
@ -703,6 +703,9 @@ public:
|
||||||
char ** pool_next = NULL);
|
char ** pool_next = NULL);
|
||||||
void write(std::ostream& out, unsigned int index = 0) const;
|
void write(std::ostream& out, unsigned int index = 0) const;
|
||||||
|
|
||||||
|
void read_xml(std::istream& in);
|
||||||
|
void write_xml(std::ostream& out, const int depth = 0) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debugging methods. There are two methods defined to help with
|
* Debugging methods. There are two methods defined to help with
|
||||||
* debugging:
|
* debugging:
|
||||||
|
|
|
||||||
|
|
@ -739,6 +739,40 @@ void annotated_commodity_t::write_annotations(std::ostream& out,
|
||||||
out << " (" << *info.tag << ')';
|
out << " (" << *info.tag << ')';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void commodity_t::read_xml(std::istream& in)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void commodity_t::write_xml(std::ostream& out, const int depth) const
|
||||||
|
{
|
||||||
|
xml_print(out, "<commodity flags=\"", depth);
|
||||||
|
|
||||||
|
if (! (flags() & COMMODITY_STYLE_SUFFIXED)) out << 'P';
|
||||||
|
if (flags() & COMMODITY_STYLE_SEPARATED) out << 'S';
|
||||||
|
if (flags() & COMMODITY_STYLE_THOUSANDS) out << 'T';
|
||||||
|
if (flags() & COMMODITY_STYLE_EUROPEAN) out << 'E';
|
||||||
|
out << "\">\n";
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
// jww (2006-03-02): !!!
|
||||||
|
if (price) {
|
||||||
|
for (int i = 0; i < depth + 2; i++) out << ' ';
|
||||||
|
out << "<symbol>" << base->symbol << "</symbol>\n";
|
||||||
|
for (int i = 0; i < depth + 2; i++) out << ' ';
|
||||||
|
out << "<price>\n";
|
||||||
|
xml_write_amount(out, *price, depth + 4);
|
||||||
|
for (int i = 0; i < depth + 2; i++) out << ' ';
|
||||||
|
out << "</price>\n";
|
||||||
|
} else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
xml_print(out, "<symbol>", depth + 1);
|
||||||
|
out << symbol() << "</symbol>\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
xml_print(out, "</commodity>\n", depth);
|
||||||
|
}
|
||||||
|
|
||||||
bool compare_amount_commodities::operator()(const amount_t * left,
|
bool compare_amount_commodities::operator()(const amount_t * left,
|
||||||
const amount_t * right) const
|
const amount_t * right) const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -359,6 +359,9 @@ public:
|
||||||
void read(char *& data);
|
void read(char *& data);
|
||||||
void write(std::ostream& out) const;
|
void write(std::ostream& out) const;
|
||||||
|
|
||||||
|
void read_xml(std::istream& in);
|
||||||
|
void write_xml(std::ostream& out, const int depth = 0) const;
|
||||||
|
|
||||||
bool valid() const;
|
bool valid() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
12
src/utils.h
12
src/utils.h
|
|
@ -535,6 +535,18 @@ inline char peek_next_nonws(std::istream& in) {
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void xml_space(std::ostream& out, const int depth = 0) {
|
||||||
|
for (int i = 0; i < depth; i++)
|
||||||
|
out << " ";
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void xml_print(std::ostream& out,
|
||||||
|
const string& str,
|
||||||
|
const int depth = 0) {
|
||||||
|
xml_space(out, depth);
|
||||||
|
out << str;
|
||||||
|
}
|
||||||
|
|
||||||
#define READ_INTO(str, targ, size, var, cond) { \
|
#define READ_INTO(str, targ, size, var, cond) { \
|
||||||
char * _p = targ; \
|
char * _p = targ; \
|
||||||
var = str.peek(); \
|
var = str.peek(); \
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue