• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/rap/utilities.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8; indent-tabs-mode:t -*- */
00002 
00003 /*
00004  * utilities.h
00005  * Copyright (C) 1997 by the University of Southern California
00006  * $Id: utilities.h,v 1.7 2005/08/25 18:58:11 johnh Exp $
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License,
00010  * version 2, as published by the Free Software Foundation.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License along
00018  * with this program; if not, write to the Free Software Foundation, Inc.,
00019  * 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00020  *
00021  *
00022  * The copyright of this module includes the following
00023  * linking-with-specific-other-licenses addition:
00024  *
00025  * In addition, as a special exception, the copyright holders of
00026  * this module give you permission to combine (via static or
00027  * dynamic linking) this module with free software programs or
00028  * libraries that are released under the GNU LGPL and with code
00029  * included in the standard release of ns-2 under the Apache 2.0
00030  * license or under otherwise-compatible licenses with advertising
00031  * requirements (or modified versions of such code, with unchanged
00032  * license).  You may copy and distribute such a system following the
00033  * terms of the GNU GPL for this module and the licenses of the
00034  * other code concerned, provided that you include the source code of
00035  * that other code when and as the GNU GPL requires distribution of
00036  * source code.
00037  *
00038  * Note that people who make modified versions of this module
00039  * are not obligated to grant this special exception for their
00040  * modified versions; it is their choice whether to do so.  The GNU
00041  * General Public License gives permission to release a modified
00042  * version without this exception; this exception also makes it
00043  * possible to release a modified version which carries forward this
00044  * exception.
00045  *
00046  */
00047 
00048 //
00049 // utilities.h 
00050 //      Miscellaneous useful definitions, including debugging routines.
00051 // 
00052 // Author:
00053 //   Mohit Talwar (mohit@catarina.usc.edu)
00054 //
00055 // $Header: /cvsroot/nsnam/ns-2/rap/utilities.h,v 1.7 2005/08/25 18:58:11 johnh Exp $
00056 
00057 #ifndef UTILITIES_H
00058 #define UTILITIES_H
00059 
00060 #include <stdio.h>
00061 #include <stdlib.h>
00062 #include <assert.h>
00063 #include <limits.h>
00064 #include <memory.h>
00065 
00066 #include "agent.h"
00067 #include "tclcl.h"
00068 #include "packet.h"
00069 #include "address.h"
00070 #include "ip.h"
00071 #include "random.h"
00072 #include "raplist.h"
00073 
00074 // Functions...
00075 extern FILE * DebugEnable(unsigned int nodeid);
00076 
00077 // Print debug message if flag is enabled
00078 extern void Debug (int debugFlag, FILE *log, char* format, ...); 
00079 
00080 
00081 
00082 // Data structures
00083 class DoubleListElem {
00084 public:
00085         DoubleListElem() : prev_(0), next_(0) {}
00086 
00087         virtual ~DoubleListElem () {}
00088 
00089         DoubleListElem* next() const { return next_; }
00090         DoubleListElem* prev() const { return prev_; }
00091 
00092         virtual void detach() {
00093                 if (prev_ != 0) prev_->next_ = next_;
00094                 if (next_ != 0) next_->prev_ = prev_;
00095                 prev_ = next_ = 0;
00096         }
00097         // Add new element s before this one
00098         virtual void insert(DoubleListElem *s) {
00099                 s->next_ = this;
00100                 s->prev_ = prev_;
00101                 if (prev_ != 0) prev_->next_ = s;
00102                 prev_ = s;
00103         }
00104         // Add new element s after this one
00105         virtual void append(DoubleListElem *s) {
00106                 s->next_ = next_;
00107                 s->prev_ = this;
00108                 if (next_ != 0) next_->prev_ = s;
00109                 next_ = s;
00110         }
00111 
00112 private:
00113         DoubleListElem *prev_, *next_;
00114 };
00115 
00116 class DoubleList {
00117 public:
00118         DoubleList() : head_(0), tail_(0) {}
00119         virtual ~DoubleList() {}
00120         virtual void destroy();
00121         DoubleListElem* head() { return head_; }
00122         DoubleListElem* tail() { return tail_; }
00123 
00124         void detach(DoubleListElem *e) {
00125                 if (head_ == e)
00126                         head_ = e->next();
00127                 if (tail_ == e)
00128                         tail_ = e->prev();
00129                 e->detach();
00130         }
00131         void insert(DoubleListElem *src, DoubleListElem *dst) {
00132                 dst->insert(src);
00133                 if (dst == head_)
00134                         head_ = src;
00135         }
00136         void append(DoubleListElem *src, DoubleListElem *dst) {
00137                 dst->append(src);
00138                 if (dst == tail_)
00139                         tail_ = src;
00140         }
00141 protected:
00142         DoubleListElem *head_, *tail_;
00143 };
00144 
00145 
00146 #endif // UTILITIES_H

Generated on Tue Aug 10 2010 16:16:08 for ns-2.33 by  doxygen 1.7.1