summaryrefslogtreecommitdiff
path: root/src/item.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/item.h')
-rw-r--r--src/item.h97
1 files changed, 75 insertions, 22 deletions
diff --git a/src/item.h b/src/item.h
index 4d19e36a..5518a063 100644
--- a/src/item.h
+++ b/src/item.h
@@ -50,6 +50,53 @@
namespace ledger {
+struct position_t
+{
+ path pathname;
+ istream_pos_type beg_pos;
+ std::size_t beg_line;
+ istream_pos_type end_pos;
+ std::size_t end_line;
+
+ position_t() : beg_pos(0), beg_line(0), end_pos(0), end_line(0) {
+ TRACE_CTOR(position_t, "");
+ }
+ position_t(const position_t& pos) {
+ TRACE_CTOR(position_t, "copy");
+ *this = pos;
+ }
+ ~position_t() throw() {
+ TRACE_DTOR(position_t);
+ }
+
+ position_t& operator=(const position_t& pos) {
+ if (this != &pos) {
+ pathname = pos.pathname;
+ beg_pos = pos.beg_pos;
+ beg_line = pos.beg_line;
+ end_pos = pos.end_pos;
+ end_line = pos.end_line;
+ }
+ return *this;
+ }
+
+#if defined(HAVE_BOOST_SERIALIZATION)
+private:
+ /** Serialization. */
+
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* version */) {
+ ar & pathname;
+ ar & beg_pos;
+ ar & beg_line;
+ ar & end_pos;
+ ar & end_line;
+ }
+#endif // HAVE_BOOST_SERIALIZATION
+};
+
/**
* @brief Brief
*
@@ -61,28 +108,21 @@ public:
#define ITEM_NORMAL 0x00 // no flags at all, a basic posting
// jww (2009-10-27): I'm not consistent on the difference between these two.
#define ITEM_GENERATED 0x01 // posting was not found in a journal
-#define ITEM_TEMP 0x02 // posting is a temporary object
+#define ITEM_TEMP 0x02 // posting is a managed temporary
enum state_t { UNCLEARED = 0, CLEARED, PENDING };
- state_t _state;
-
- optional<date_t> _date;
- optional<date_t> _date_eff;
- optional<string> note;
-
typedef std::map<string, optional<string> > string_map;
- optional<string_map> metadata;
- path pathname;
- istream_pos_type beg_pos;
- std::size_t beg_line;
- istream_pos_type end_pos;
- std::size_t end_line;
+ state_t _state;
+ optional<date_t> _date;
+ optional<date_t> _date_eff;
+ optional<string> note;
+ optional<position_t> pos;
+ optional<string_map> metadata;
item_t(flags_t _flags = ITEM_NORMAL, const optional<string>& _note = none)
- : supports_flags<>(_flags), _state(UNCLEARED), note(_note),
- beg_pos(0), beg_line(0), end_pos(0), end_line(0)
+ : supports_flags<>(_flags), _state(UNCLEARED), note(_note)
{
TRACE_CTOR(item_t, "flags_t, const string&");
}
@@ -102,14 +142,8 @@ public:
_date = item._date;
_date_eff = item._date_eff;
-
note = item.note;
-
- pathname = item.pathname;
- beg_pos = item.beg_pos;
- beg_line = item.beg_line;
- end_pos = item.end_pos;
- end_line = item.end_line;
+ pos = item.pos;
}
virtual bool operator==(const item_t& xact) {
@@ -158,6 +192,25 @@ public:
virtual expr_t::ptr_op_t lookup(const string& name);
bool valid() const;
+
+#if defined(HAVE_BOOST_SERIALIZATION)
+private:
+ /** Serialization. */
+
+ friend class boost::serialization::access;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* version */) {
+ ar & boost::serialization::base_object<supports_flags<> >(*this);
+ ar & boost::serialization::base_object<scope_t>(*this);
+ ar & _state;
+ ar & _date;
+ ar & _date_eff;
+ ar & note;
+ ar & metadata;
+ ar & pos;
+ }
+#endif // HAVE_BOOST_SERIALIZATION
};
value_t get_comment(item_t& item);