00001 /* 00002 * Copyright (C) 2003 CTIE, Monash University 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License 00006 * as published by the Free Software Foundation; either version 2 00007 * of the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef _ETH_UTILS_H_ 00020 #define _ETH_UTILS_H_ 00021 00022 #include <stdio.h> 00023 #include <ostream> 00024 00025 00026 // 00027 // Macro to prevent executing ev<< statements in Express mode. 00028 // Compare ev/sec values with code compiled with #define EV ev. 00029 // After 3.0a4 change to: 00030 // #define EV ev.disabled()?ev:ev 00031 // 00032 #define EV ev.disable_tracing?ev:ev 00033 00034 00035 00036 #define MAX_LINE 100 00037 00038 00039 // Function reads from a file stream pointed to by 'fp' and stores characters until the '\n' or EOF 00040 // character is found, the resultant string is returned. Note that neither '\n' nor EOF character 00041 // is stored to the resultant string, also note that if on a line containing useful data that EOF occurs, 00042 // then that line will not be read in, hence must terminate file with unused line. 00043 extern char* fgetline(FILE *fp); 00044 00045 00046 class MessageId; 00047 00051 class MessageTracer 00052 { 00053 protected: 00054 static MessageTracer trc; 00055 FILE *f; 00056 MessageId *lastId; 00057 void open(); 00058 public: 00059 static inline MessageTracer *instance() {return &trc;} 00060 MessageTracer(); 00061 ~MessageTracer(); 00062 void created(MessageId *m); 00063 void cloned(MessageId *m); 00064 void assigned(MessageId *m); 00065 void deleted(MessageId *m); 00066 }; 00067 00068 00072 class MessageId 00073 { 00074 public: 00075 static unsigned int nextId; 00076 static unsigned int nextTreeId; 00077 unsigned int id; 00078 unsigned int treeId; 00079 unsigned int parentId; 00080 public: 00081 MessageId() {id=++nextId; treeId=++nextTreeId; parentId=0; MessageTracer::instance()->created(this);} 00082 MessageId(const MessageId& m) {id=++nextId; treeId=m.treeId; parentId=m.id; MessageTracer::instance()->cloned(this);} 00083 ~MessageId() {MessageTracer::instance()->deleted(this);} 00084 MessageId& operator=(const MessageId& m) {id=++nextId; treeId=m.treeId; parentId=m.id; MessageTracer::instance()->assigned(this); return *this;} 00085 }; 00086 00087 inline std::ostream& operator<<(std::ostream& out, const MessageId& m) 00088 { 00089 out << "Id:" << m.id << " TreeId: " << m.treeId << " ParentId:" << m.parentId; return out; 00090 } 00091 00092 #endif 00093
1.2.17