"Fossies" - the Fresh Open Source Software Archive

Member "devtodo-0.1.20/src/Todo.cc" (9 May 2006, 2788 Bytes) of package /linux/privat/old/devtodo-0.1.20.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Todo.cc" see the Fossies "Dox" file reference documentation.

    1 #include <algorithm>
    2 #include "support.h"
    3 #include "Todo.h"
    4 
    5 Todo::Todo() : priority(None), done(false), added(0), doneTime(0), 
    6     unfilteredchildren(0), filtered(true), type(Note), child(0), in(0), 
    7     parent(0), db(0) {
    8     
    9     child = new multiset<Todo>;
   10 }
   11 
   12 Todo::Todo(const Todo &other) {
   13     *this = other;
   14 }
   15 
   16 Todo::~Todo() {
   17     if (type == Note && child != NULL)
   18         delete child;
   19 }
   20 
   21 void Todo::incUnFilteredChildren() {
   22     unfilteredchildren++;
   23     if (parent) parent->incUnFilteredChildren();
   24 }
   25 
   26 void Todo::decUnFilteredChildren() {
   27     if (unfilteredchildren) unfilteredchildren--;
   28     if (parent) parent->decUnFilteredChildren();
   29 }
   30 
   31 int Todo::operator == (Todo const &other) const {
   32     return priority == other.priority &&
   33         text == other.text &&
   34         comment == other.comment &&
   35         done == other.done &&
   36         added == other.added &&
   37         doneTime == other.doneTime;
   38 }
   39 
   40 // Enforces the sort order of Todo database items
   41 int Todo::operator < (Todo const &other) const {
   42     for (vector<Options::Sort>::iterator i = options.sort.begin(); i != options.sort.end(); ++i) {
   43         switch ((*i).key) {
   44             case Options::Sort::Created :
   45                 if (added != other.added) {
   46                     if (added < other.added)
   47                         return (*i).dir;
   48                     else
   49                         return !(*i).dir;
   50                 }
   51             break;
   52             case Options::Sort::Completed :
   53                 if (doneTime != other.doneTime) 
   54                     if (doneTime < other.doneTime)
   55                         return (*i).dir;
   56                     else
   57                         return !(*i).dir;
   58             break;
   59             case Options::Sort::Text :
   60                 if (text != other.text) 
   61                     if (text < other.text)
   62                         return (*i).dir;
   63                     else
   64                         return !(*i).dir;
   65             break;
   66             case Options::Sort::Priority :
   67                 if (priority != other.priority) 
   68                     if (priority < other.priority)
   69                         return (*i).dir;
   70                     else
   71                         return !(*i).dir;
   72             break;
   73             case Options::Sort::Duration : {
   74             time_t d = doneTime - added, od = other.doneTime - other.added;
   75 
   76                 if (!done) d = 0;
   77                 if (!other.done) od = 0;
   78 
   79                 if (d != od) 
   80                     if (d < od)
   81                         return (*i).dir;
   82                     else
   83                         return !(*i).dir;
   84             } break;
   85             case Options::Sort::Done :
   86                 if (done != other.done)
   87                     if (done && !other.done)
   88                         return (*i).dir;
   89                     else
   90                         return !(*i).dir;
   91             break;
   92             case Options::Sort::None :
   93                 return 0;
   94             break;
   95         }
   96     }
   97     return 0;
   98 }
   99 
  100 Todo &Todo::operator = (const Todo &other)
  101 {
  102     if (this != &other)
  103     {
  104         priority = other.priority;
  105         text = other.text;
  106         todofile = other.todofile;
  107         comment = other.comment;
  108         done = other.done;
  109         added = other.added;
  110         doneTime = other.doneTime;
  111 
  112         index = other.index;
  113         unfilteredchildren = other.unfilteredchildren;
  114         filtered = other.filtered;
  115         type = other.type;
  116 
  117         parent = other.parent;
  118         db = other.db;
  119 
  120         in = other.in;
  121 
  122         if (type == Link)
  123             child = other.child;
  124         else {
  125             child = new multiset<Todo>;
  126             *child = *other.child;
  127         }
  128     }
  129 
  130     return *this;
  131 }