Switched to git
[ttodo.git] / tde.cc
blobcd392d3c5a2aa14ff4fd418b4ad74e88fadc3654
1 // This file is part of a terminal todo application.
2 //
3 // Copyright (C) 2006 by Mike Sharov <msharov@users.sourceforge.net>
4 // This file is free software, distributed under the MIT License.
5 //
6 // tde.cc
7 //
9 #include "tde.h"
10 #include <time.h>
12 /// Default constructor.
13 CTodoItem::CTodoItem (id_t id)
14 : m_Text (),
15 m_Comment (),
16 m_Epoch (0),
17 m_Created (0),
18 m_Started (0),
19 m_Effort (0),
20 m_Due (0),
21 m_Done (0),
22 m_Id (id),
23 m_Priority (priority_Medium),
24 m_Progress (0),
25 m_bHasSublist (false),
26 m_Refs (0)
28 const time_t now (time (NULL));
29 m_Created = uint32_t(now);
30 m_Epoch = now >> 32;
33 /// Reads the object from stream \p is.
34 void CTodoItem::read (istream& is)
36 is >> m_Epoch >> m_Created >> m_Started >> m_Effort >> m_Due >> m_Done
37 >> m_Id >> m_Priority >> m_Progress >> m_bHasSublist >> m_Refs
38 >> m_Text >> m_Comment >> ios::align(4);
41 /// Writes the object to stream \p os.
42 void CTodoItem::write (ostream& os) const
44 os << m_Epoch << m_Created << m_Started << m_Effort << m_Due << m_Done
45 << m_Id << m_Priority << m_Progress << m_bHasSublist << m_Refs
46 << m_Text << m_Comment << ios::align(4);
49 /// Returns the size of the written object.
50 size_t CTodoItem::stream_size (void) const
52 return (Align (stream_size_of (m_Epoch) +
53 stream_size_of (m_Created) +
54 stream_size_of (m_Started) +
55 stream_size_of (m_Effort) +
56 stream_size_of (m_Due) +
57 stream_size_of (m_Done) +
58 stream_size_of (m_Id) +
59 stream_size_of (m_Priority) +
60 stream_size_of (m_Progress) +
61 stream_size_of (m_bHasSublist) +
62 stream_size_of (m_Refs) +
63 stream_size_of (m_Text) +
64 stream_size_of (m_Comment), 4));
67 /// Marks the item's \p progress and sets the done time if appropriate.
68 void CTodoItem::MarkComplete (uint8_t progress)
70 assert (progress <= 100 && "Progress field is a percentage");
71 m_Progress = progress;
72 if (m_Progress == 100)
73 m_Done = time (NULL);
76 /// Returns text string containing the combined date.
77 const char* CTodoItem::TimeTText (uint32_t v) const
79 time_t t (MakeTimeT (v));
80 return (ctime (&t));