00001 /* -*- Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */ 00002 // 00003 // Copyright (c) 1997 by the University of Southern California 00004 // All rights reserved. 00005 // 00006 // Permission to use, copy, modify, and distribute this software and its 00007 // documentation in source and binary forms for non-commercial purposes 00008 // and without fee is hereby granted, provided that the above copyright 00009 // notice appear in all copies and that both the copyright notice and 00010 // this permission notice appear in supporting documentation. and that 00011 // any documentation, advertising materials, and other materials related 00012 // to such distribution and use acknowledge that the software was 00013 // developed by the University of Southern California, Information 00014 // Sciences Institute. The name of the University may not be used to 00015 // endorse or promote products derived from this software without 00016 // specific prior written permission. 00017 // 00018 // THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about 00019 // the suitability of this software for any purpose. THIS SOFTWARE IS 00020 // PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 00021 // INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF 00022 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00023 // 00024 // Other copyrights might apply to parts of this software and are so 00025 // noted when applicable. 00026 // 00027 // utilities.h 00028 // Miscellaneous useful definitions, including debugging routines. 00029 // 00030 // Author: 00031 // Mohit Talwar (mohit@catarina.usc.edu) 00032 // 00033 // $Header: /nfs/jade/vint/CVSROOT/ns-2/rap/utilities.h,v 1.5 1999/09/24 23:44:45 haoboy Exp $ 00034 00035 #ifndef UTILITIES_H 00036 #define UTILITIES_H 00037 00038 #include <stdio.h> 00039 #include <stdlib.h> 00040 #include <assert.h> 00041 #include <limits.h> 00042 #include <memory.h> 00043 00044 #include "agent.h" 00045 #include "tclcl.h" 00046 #include "packet.h" 00047 #include "address.h" 00048 #include "ip.h" 00049 #include "random.h" 00050 #include "raplist.h" 00051 00052 // Functions... 00053 extern FILE * DebugEnable(unsigned int nodeid); 00054 00055 // Print debug message if flag is enabled 00056 extern void Debug (int debugFlag, FILE *log, char* format, ...); 00057 00058 00059 00060 // Data structures 00061 class DoubleListElem { 00062 public: 00063 DoubleListElem() : prev_(0), next_(0) {} 00064 00065 DoubleListElem* next() const { return next_; } 00066 DoubleListElem* prev() const { return prev_; } 00067 00068 virtual void detach() { 00069 if (prev_ != 0) prev_->next_ = next_; 00070 if (next_ != 0) next_->prev_ = prev_; 00071 prev_ = next_ = 0; 00072 } 00073 // Add new element s before this one 00074 virtual void insert(DoubleListElem *s) { 00075 s->next_ = this; 00076 s->prev_ = prev_; 00077 if (prev_ != 0) prev_->next_ = s; 00078 prev_ = s; 00079 } 00080 // Add new element s after this one 00081 virtual void append(DoubleListElem *s) { 00082 s->next_ = next_; 00083 s->prev_ = this; 00084 if (next_ != 0) next_->prev_ = s; 00085 next_ = s; 00086 } 00087 00088 private: 00089 DoubleListElem *prev_, *next_; 00090 }; 00091 00092 class DoubleList { 00093 public: 00094 DoubleList() : head_(0), tail_(0) {} 00095 virtual void destroy(); 00096 DoubleListElem* head() { return head_; } 00097 DoubleListElem* tail() { return tail_; } 00098 00099 void detach(DoubleListElem *e) { 00100 if (head_ == e) 00101 head_ = e->next(); 00102 if (tail_ == e) 00103 tail_ = e->prev(); 00104 e->detach(); 00105 } 00106 void insert(DoubleListElem *src, DoubleListElem *dst) { 00107 dst->insert(src); 00108 if (dst == head_) 00109 head_ = src; 00110 } 00111 void append(DoubleListElem *src, DoubleListElem *dst) { 00112 dst->append(src); 00113 if (dst == tail_) 00114 tail_ = src; 00115 } 00116 protected: 00117 DoubleListElem *head_, *tail_; 00118 }; 00119 00120 00121 #endif // UTILITIES_H
1.3.3