//-------------------------------------------------------------------*--------* // Test of POST++ on a simple doubly-linked list. // Jiri Soukup, Aug.10, 2004 //-------------------------------------------------------------------*--------* #include #include "..\post\object.h" USE_POST_NAMESPACE class ListNode : public object { friend class List; public: CLASSINFO(ListNode, REF(next) REF(prev)); ListNode *getNext(){return next;} private: ListNode(int i){id=i; next=prev=NULL;}; ListNode *next; ListNode *prev; int id; }; REGISTER(ListNode); class List : public object { public: CLASSINFO(List, REF(tail)); ListNode *getTail(){return tail;} ListNode *getHead(){if(tail)return tail->next; else return NULL;} void addTail(ListNode *n){ if(tail){ n->next=tail->next; tail->next->prev=n; tail->next=n; n->prev=tail; } else { n->next=n->prev=n;} tail=n; count++; } int getCount(){return count;} private: List(int startCount){count=startCount; tail=NULL;}; ListNode *tail; int count; }; REGISTER(List); #define ELAPSED int(time(NULL)-start) #define RESET start=time(NULL) int main(int argc,char **argv) { List *root; ListNode *n, *tail;; time_t start,start0; int i,NUM; if(argc!=2){ printf("syntax: list numOfNodes\n"); return 1; } NUM=atoi(argv[1]); RESET; start0=start; storage list_storage("list.odb",200000000); // same as in DOL printf("opening list_storage "); if (list_storage.open()) { root = (List*)list_storage.get_root_object(); if(root){ printf("%d sec\ncount=", ELAPSED); RESET; tail=root->getTail(); for(n=root->getHead(), i=0; n; n=n->getNext()){ i++; if(n==tail)break; } printf("%d in %d sec\n",i,ELAPSED); RESET; } else { printf(" %d sec\ncreating list of %d nodes ", ELAPSED, NUM); RESET; root=new_in(list_storage,List); list_storage.set_root_object(root); for(i=0; iaddTail(n); } printf("%d sec\n",ELAPSED); RESET; list_storage.flush(); list_storage.close(); printf("database closed %d sec\n", ELAPSED); } start=start0; printf("total time %d sec\n", ELAPSED); return 0; } else { printf("error: failed to open database\n"); return 1; } }