Changed file format to include dependency table.
[ttodo.git] / tde.cc
blob90e5c66defcfc6640d66e3143fb3049c7a106d51
1 // tde.cc
2 //
4 #include "tde.h"
5 #include <time.h>
7 /// Default constructor.
8 CTodoEntry::CTodoEntry (void)
9 : m_Text (),
10 m_Comment (),
11 m_Epoch (0),
12 m_Created (0),
13 m_Done (0),
14 m_Id (rand()),
15 m_SublistId (0),
16 m_Priority (priority_Medium),
17 m_Progress (0)
19 const time_t now (time (NULL));
20 m_Created = uint32_t(now);
21 m_Epoch = now >> 32;
24 /// Reads the object from stream \p is.
25 void CTodoEntry::read (istream& is)
27 is >> m_Epoch >> m_Created >> m_Done
28 >> m_Id >> m_SublistId >> m_Priority >> m_Progress
29 >> m_Text >> m_Comment >> ios::align(4);
32 /// Writes the object to stream \p os.
33 void CTodoEntry::write (ostream& os) const
35 os << m_Epoch << m_Created << m_Done
36 << m_Id << m_SublistId << m_Priority << m_Progress
37 << m_Text << m_Comment << ios::align(4);
40 /// Returns the size of the written object.
41 size_t CTodoEntry::stream_size (void) const
43 return (Align (stream_size_of (m_Epoch) +
44 stream_size_of (m_Created) +
45 stream_size_of (m_Done) +
46 stream_size_of (m_Id) +
47 stream_size_of (m_SublistId) +
48 stream_size_of (m_Priority) +
49 stream_size_of (m_Progress) +
50 stream_size_of (m_Text) +
51 stream_size_of (m_Comment), 4));
54 /// Marks the item's \p progress and sets the done time if appropriate.
55 void CTodoEntry::MarkComplete (uint8_t progress)
57 assert (progress <= 100 && "Progress field is a percentage");
58 m_Progress = progress;
59 m_Done = time (NULL);
60 if (m_Progress != 100)
61 m_Done = 0;
64 /// Returns text string containing the combined date.
65 const char* CTodoEntry::TimeTText (uint32_t v) const
67 time_t t (MakeTimeT (v));
68 return (ctime (&t));