• Main Page
  • Classes
  • Files
  • File List

/Users/yzchen/ns/ns-allinone-2.33/ns-2.33/lib/int.Vec.h

00001 // This may look like C code, but it is really -*- C++ -*-
00002 /* 
00003 Copyright (C) 1988 Free Software Foundation
00004     written by Doug Lea (dl@rocky.oswego.edu)
00005 
00006 This file is part of the GNU C++ Library.  This library is free
00007 software; you can redistribute it and/or modify it under the terms of
00008 the GNU Library General Public License as published by the Free
00009 Software Foundation; either version 2 of the License, or (at your
00010 option) any later version.  This library is distributed in the hope
00011 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00012 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00013 PURPOSE.  See the GNU Library General Public License for more details.
00014 You should have received a copy of the GNU Library General Public
00015 License along with this library; if not, write to the Free Software
00016 Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017 
00018 Linking this file statically or dynamically with other modules is making
00019 a combined work based on this file.  Thus, the terms and conditions of
00020 the GNU General Public License cover the whole combination.
00021 
00022 In addition, as a special exception, the copyright holders of this file
00023 give you permission to combine this file with free software programs or
00024 libraries that are released under the GNU LGPL and with code included in
00025 the standard release of ns-2 under the Apache 2.0 license or under
00026 otherwise-compatible licenses with advertising requirements (or modified
00027 versions of such code, with unchanged license).  You may copy and
00028 distribute such a system following the terms of the GNU GPL for this
00029 file and the licenses of the other code concerned, provided that you
00030 include the source code of that other code when and as the GNU GPL
00031 requires distribution of source code.
00032 
00033 Note that people who make modified versions of this file are not
00034 obligated to grant this special exception for their modified versions;
00035 it is their choice whether to do so.  The GNU General Public License
00036 gives permission to release a modified version without this exception;
00037 this exception also makes it possible to release a modified version
00038 which carries forward this exception.
00039 */
00040 
00041 
00042 #ifndef _intVec_h
00043 #ifdef __GNUG__
00044 #pragma interface
00045 #endif
00046 #define _intVec_h 1
00047 
00048 #include "builtin.h"
00049 #include "int.defs.h"
00050 
00051 #ifndef _int_typedefs
00052 #define _int_typedefs 1
00053 typedef void (*intProcedure)(int );
00054 typedef int  (*intMapper)(int );
00055 typedef int  (*intCombiner)(int , int );
00056 typedef int  (*intPredicate)(int );
00057 typedef int  (*intComparator)(int , int );
00058 #endif
00059 
00060 
00061 class intVec 
00062 {
00063 protected:      
00064   int                   len;
00065   int                   *s;                  
00066 
00067                         intVec(int l, int* d);
00068 public:
00069                         intVec ();
00070                         intVec (int l);
00071                         intVec (int l, int  fill_value);
00072                         intVec (const intVec&);
00073                         ~intVec ();
00074 
00075   intVec &              operator = (const intVec & a);
00076   intVec                at(int from = 0, int n = -1);
00077 
00078   int                   capacity() const;
00079   void                  resize(int newlen);                        
00080 
00081   int&                  operator [] (int n);
00082   int&                  elem(int n);
00083 
00084   friend intVec         concat(intVec & a, intVec & b);
00085   friend intVec         map(intMapper f, intVec & a);
00086   friend intVec         merge(intVec & a, intVec & b, intComparator f);
00087   friend intVec         combine(intCombiner f, intVec & a, intVec & b);
00088   friend intVec         reverse(intVec & a);
00089 
00090   void                  reverse();
00091   void                  sort(intComparator f);
00092   void                  fill(int  val, int from = 0, int n = -1);
00093 
00094   void                  apply(intProcedure f);
00095   int                   reduce(intCombiner f, int  base);
00096   int                   index(int  targ);
00097 
00098   friend int            operator == (intVec& a, intVec& b);
00099   friend int            operator != (intVec& a, intVec& b);
00100 
00101   void                  error(const char* msg);
00102   void                  range_error();
00103 };
00104 
00105 extern void default_intVec_error_handler(const char*);
00106 extern one_arg_error_handler_t intVec_error_handler;
00107 
00108 extern one_arg_error_handler_t 
00109         set_intVec_error_handler(one_arg_error_handler_t f);
00110 
00111 
00112 inline intVec::intVec()
00113 {
00114   len = 0; s = 0;
00115 }
00116 
00117 inline intVec::intVec(int l)
00118 {
00119   s = new int [len = l];
00120 }
00121 
00122 
00123 inline intVec::intVec(int l, int* d) :len(l), s(d) {}
00124 
00125 
00126 inline intVec::~intVec()
00127 {
00128   delete [] s;
00129 }
00130 
00131 
00132 inline int& intVec::operator [] (int n)
00133 {
00134   if ((unsigned)n >= (unsigned)len)
00135     range_error();
00136   return s[n];
00137 }
00138 
00139 inline int& intVec::elem(int n)
00140 {
00141   return s[n];
00142 }
00143 
00144 
00145 inline int intVec::capacity() const
00146 {
00147   return len;
00148 }
00149 
00150 
00151 
00152 inline int operator != (intVec& a, intVec& b)
00153 {
00154   return !(a == b);
00155 }
00156 
00157 #endif

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