Revised file format to conform to standard IFF layout
[ttodo.git] / tde.cc
bloba25693da08afa7d76816216da7491b0c94a6b92b
1 // tde.cc
2 //
4 #include "tde.h"
5 #include <time.h>
7 /// Default constructor.
8 CTodoItem::CTodoItem (id_t id)
9 : m_Text (),
10 m_Comment (),
11 m_Epoch (0),
12 m_Created (0),
13 m_Done (0),
14 m_Id (id),
15 m_Priority (priority_Medium),
16 m_Progress (0),
17 m_bHasSublist (false),
18 m_Refs (0)
20 const time_t now (time (NULL));
21 m_Created = uint32_t(now);
22 m_Epoch = now >> 32;
25 /// Reads the object from stream \p is.
26 void CTodoItem::read (istream& is)
28 is >> m_Epoch >> m_Created >> m_Done
29 >> m_Id >> m_Priority >> m_Progress >> m_bHasSublist >> m_Refs
30 >> m_Text >> m_Comment >> ios::align(4);
33 /// Writes the object to stream \p os.
34 void CTodoItem::write (ostream& os) const
36 os << m_Epoch << m_Created << m_Done
37 << m_Id << m_Priority << m_Progress << m_bHasSublist << m_Refs
38 << m_Text << m_Comment << ios::align(4);
41 /// Returns the size of the written object.
42 size_t CTodoItem::stream_size (void) const
44 return (Align (stream_size_of (m_Epoch) +
45 stream_size_of (m_Created) +
46 stream_size_of (m_Done) +
47 stream_size_of (m_Id) +
48 stream_size_of (m_Priority) +
49 stream_size_of (m_Progress) +
50 stream_size_of (m_bHasSublist) +
51 stream_size_of (m_Refs) +
52 stream_size_of (m_Text) +
53 stream_size_of (m_Comment), 4));
56 /// Marks the item's \p progress and sets the done time if appropriate.
57 void CTodoItem::MarkComplete (uint8_t progress)
59 assert (progress <= 100 && "Progress field is a percentage");
60 m_Progress = progress;
61 if (m_Progress == 100)
62 m_Done = time (NULL);
65 /// Returns text string containing the combined date.
66 const char* CTodoItem::TimeTText (uint32_t v) const
68 time_t t (MakeTimeT (v));
69 return (ctime (&t));