• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/trace/basetrace.h

00001 /* -*-  Mode:C++; c-basic-offset:8; tab-width:8 -*- */
00002 /*
00003  * Copyright (c) 1997 Regents of the University of California.
00004  * All rights reserved.
00005  * 
00006  * Redistribution and use in source and binary forms, with or without
00007  * modification, are permitted provided that the following conditions
00008  * are met:
00009  * 1. Redistributions of source code must retain the above copyright
00010  *    notice, this list of conditions and the following disclaimer.
00011  * 2. Redistributions in binary form must reproduce the above copyright
00012  *    notice, this list of conditions and the following disclaimer in the
00013  *    documentation and/or other materials provided with the distribution.
00014  * 3. All advertising materials mentioning features or use of this software
00015  *    must display the following acknowledgement:
00016  *      This product includes software developed by the MASH Research
00017  *      Group at the University of California Berkeley.
00018  * 4. Neither the name of the University nor of the Research Group may be
00019  *    used to endorse or promote products derived from this software without
00020  *    specific prior written permission.
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00023  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00026  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00027  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00028  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00029  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00031  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00032  * SUCH DAMAGE.
00033  *
00034 
00035  */
00036 
00037 #ifndef ns_basetrace_h
00038 #define ns_basetrace_h
00039 
00040 #include <math.h> //floor
00041 #include "tcp.h"
00042 
00043 class BaseTrace : public TclObject {
00044 public:
00045         BaseTrace();
00046         ~BaseTrace();
00047         virtual int command(int argc, const char*const* argv);
00048         virtual void dump();
00049         virtual void namdump();
00050         inline char* buffer() { return wrk_ ; }
00051         inline char *nbuffer() {return nwrk_; }
00052 
00053         inline Tcl_Channel channel() { return channel_; }
00054         inline void channel(Tcl_Channel ch) {channel_ = ch; }
00055 
00056         inline Tcl_Channel namchannel() { return namChan_; }
00057         inline void namchannel(Tcl_Channel namch) {namChan_ = namch; }
00058 
00059         void flush(Tcl_Channel channel) { Tcl_Flush(channel); }
00060 
00061         //Default rounding is to 6 digits after decimal
00062 #define PRECISION 1.0E+6
00063         //According to freeBSD /usr/include/float.h 15 is the number of digits 
00064         // in a double.  We can specify all of them, because we're rounding to
00065         // 6 digits after the decimal and and %g removes trailing zeros.
00066 #define TIME_FORMAT "%.15g"
00067         // annoying way of tackling sprintf rounding platform 
00068         // differences :
00069         // use round(Scheduler::instance().clock()) instead of 
00070         // Scheduler::instance().clock().
00071         
00072         static double round (double x, double precision=PRECISION) {
00073                 return (double)floor(x*precision + 0.5)/precision;
00074         }
00075 
00076         inline bool tagged() { return tagged_; }
00077         inline void tagged(bool tag) { tagged_ = tag; }
00078         
00079 protected:
00080         Tcl_Channel channel_;
00081         Tcl_Channel namChan_;
00082         char *wrk_;
00083         char *nwrk_;
00084         bool tagged_;
00085 };
00086 
00087 class EventTrace : public BaseTrace {
00088 public:
00089         EventTrace() : BaseTrace() {}
00090         virtual void trace();
00091 };
00092 
00093 #endif // BaseTrace

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