Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Compound Members | File Members

int.Vec.h

Go to the documentation of this file.
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 
00019 
00020 #ifndef _intVec_h
00021 #ifdef __GNUG__
00022 #pragma interface
00023 #endif
00024 #define _intVec_h 1
00025 
00026 #include "builtin.h"
00027 #include "int.defs.h"
00028 
00029 #ifndef _int_typedefs
00030 #define _int_typedefs 1
00031 typedef void (*intProcedure)(int );
00032 typedef int  (*intMapper)(int );
00033 typedef int  (*intCombiner)(int , int );
00034 typedef int  (*intPredicate)(int );
00035 typedef int  (*intComparator)(int , int );
00036 #endif
00037 
00038 
00039 class intVec 
00040 {
00041 protected:      
00042   int                   len;
00043   int                   *s;                  
00044 
00045                         intVec(int l, int* d);
00046 public:
00047                         intVec ();
00048                         intVec (int l);
00049                         intVec (int l, int  fill_value);
00050                         intVec (const intVec&);
00051                         ~intVec ();
00052 
00053   intVec &              operator = (const intVec & a);
00054   intVec                at(int from = 0, int n = -1);
00055 
00056   int                   capacity() const;
00057   void                  resize(int newlen);                        
00058 
00059   int&                  operator [] (int n);
00060   int&                  elem(int n);
00061 
00062   friend intVec         concat(intVec & a, intVec & b);
00063   friend intVec         map(intMapper f, intVec & a);
00064   friend intVec         merge(intVec & a, intVec & b, intComparator f);
00065   friend intVec         combine(intCombiner f, intVec & a, intVec & b);
00066   friend intVec         reverse(intVec & a);
00067 
00068   void                  reverse();
00069   void                  sort(intComparator f);
00070   void                  fill(int  val, int from = 0, int n = -1);
00071 
00072   void                  apply(intProcedure f);
00073   int                   reduce(intCombiner f, int  base);
00074   int                   index(int  targ);
00075 
00076   friend int            operator == (intVec& a, intVec& b);
00077   friend int            operator != (intVec& a, intVec& b);
00078 
00079   void                  error(const char* msg);
00080   void                  range_error();
00081 };
00082 
00083 extern void default_intVec_error_handler(const char*);
00084 extern one_arg_error_handler_t intVec_error_handler;
00085 
00086 extern one_arg_error_handler_t 
00087         set_intVec_error_handler(one_arg_error_handler_t f);
00088 
00089 
00090 inline intVec::intVec()
00091 {
00092   len = 0; s = 0;
00093 }
00094 
00095 inline intVec::intVec(int l)
00096 {
00097   s = new int [len = l];
00098 }
00099 
00100 
00101 inline intVec::intVec(int l, int* d) :len(l), s(d) {}
00102 
00103 
00104 inline intVec::~intVec()
00105 {
00106   delete [] s;
00107 }
00108 
00109 
00110 inline int& intVec::operator [] (int n)
00111 {
00112   if ((unsigned)n >= (unsigned)len)
00113     range_error();
00114   return s[n];
00115 }
00116 
00117 inline int& intVec::elem(int n)
00118 {
00119   return s[n];
00120 }
00121 
00122 
00123 inline int intVec::capacity() const
00124 {
00125   return len;
00126 }
00127 
00128 
00129 
00130 inline int operator != (intVec& a, intVec& b)
00131 {
00132   return !(a == b);
00133 }
00134 
00135 #endif

Generated on Tue Apr 20 12:14:20 2004 for NS2.26SourcesOriginal by doxygen 1.3.3