Make copying of format_t objects memory-safe
This commit is contained in:
parent
96ec764c4a
commit
036200e959
2 changed files with 4 additions and 16 deletions
|
|
@ -40,16 +40,6 @@ namespace ledger {
|
||||||
format_t::elision_style_t format_t::default_style = TRUNCATE_TRAILING;
|
format_t::elision_style_t format_t::default_style = TRUNCATE_TRAILING;
|
||||||
bool format_t::default_style_changed = false;
|
bool format_t::default_style_changed = false;
|
||||||
|
|
||||||
format_t::element_t::element_t(const element_t& elem)
|
|
||||||
: supports_flags<>(),
|
|
||||||
type(elem.type),
|
|
||||||
min_width(elem.min_width),
|
|
||||||
max_width(elem.max_width),
|
|
||||||
data(elem.data)
|
|
||||||
{
|
|
||||||
TRACE_CTOR(element_t, "copy");
|
|
||||||
}
|
|
||||||
|
|
||||||
void format_t::element_t::dump(std::ostream& out) const
|
void format_t::element_t::dump(std::ostream& out) const
|
||||||
{
|
{
|
||||||
out << "Element: ";
|
out << "Element: ";
|
||||||
|
|
@ -426,7 +416,6 @@ string format_t::real_calc(scope_t& scope)
|
||||||
case element_t::EXPR: {
|
case element_t::EXPR: {
|
||||||
expr_t& expr(boost::get<expr_t>(elem->data));
|
expr_t& expr(boost::get<expr_t>(elem->data));
|
||||||
try {
|
try {
|
||||||
|
|
||||||
expr.compile(scope);
|
expr.compile(scope);
|
||||||
|
|
||||||
value_t value;
|
value_t value;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ class unistring;
|
||||||
|
|
||||||
DECLARE_EXCEPTION(format_error, std::runtime_error);
|
DECLARE_EXCEPTION(format_error, std::runtime_error);
|
||||||
|
|
||||||
class format_t : public expr_base_t<string>
|
class format_t : public expr_base_t<string>, public noncopyable
|
||||||
{
|
{
|
||||||
typedef expr_base_t<string> base_type;
|
typedef expr_base_t<string> base_type;
|
||||||
|
|
||||||
|
|
@ -65,14 +65,12 @@ class format_t : public expr_base_t<string>
|
||||||
std::size_t min_width;
|
std::size_t min_width;
|
||||||
std::size_t max_width;
|
std::size_t max_width;
|
||||||
variant<string, expr_t> data;
|
variant<string, expr_t> data;
|
||||||
scoped_ptr<struct element_t> next;
|
shared_ptr<struct element_t> next;
|
||||||
|
|
||||||
element_t() throw()
|
element_t() throw()
|
||||||
: supports_flags<>(), type(STRING), min_width(0), max_width(0) {
|
: supports_flags<>(), type(STRING), min_width(0), max_width(0) {
|
||||||
TRACE_CTOR(element_t, "");
|
TRACE_CTOR(element_t, "");
|
||||||
}
|
}
|
||||||
element_t(const element_t& elem);
|
|
||||||
|
|
||||||
~element_t() throw() {
|
~element_t() throw() {
|
||||||
TRACE_DTOR(element_t);
|
TRACE_DTOR(element_t);
|
||||||
}
|
}
|
||||||
|
|
@ -84,6 +82,7 @@ class format_t : public expr_base_t<string>
|
||||||
min_width = elem.min_width;
|
min_width = elem.min_width;
|
||||||
max_width = elem.max_width;
|
max_width = elem.max_width;
|
||||||
data = elem.data;
|
data = elem.data;
|
||||||
|
next = elem.next;
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
@ -105,7 +104,7 @@ class format_t : public expr_base_t<string>
|
||||||
void dump(std::ostream& out) const;
|
void dump(std::ostream& out) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
scoped_ptr<element_t> elements;
|
shared_ptr<element_t> elements;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static enum elision_style_t {
|
static enum elision_style_t {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue