home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / octave-1.1.1p1-base.tgz / octave-1.1.1p1-base.tar / fsf / octave / src / idx-vector.h < prev    next >
C/C++ Source or Header  |  1995-02-23  |  3KB  |  131 lines

  1. // idx-vector.h                                        -*- C++ -*-
  2. /*
  3.  
  4. Copyright (C) 1992, 1993, 1994, 1995 John W. Eaton
  5.  
  6. This file is part of Octave.
  7.  
  8. Octave is free software; you can redistribute it and/or modify it
  9. under the terms of the GNU General Public License as published by the
  10. Free Software Foundation; either version 2, or (at your option) any
  11. later version.
  12.  
  13. Octave is distributed in the hope that it will be useful, but WITHOUT
  14. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  15. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  16. for more details.
  17.  
  18. You should have received a copy of the GNU General Public License
  19. along with Octave; see the file COPYING.  If not, write to the Free
  20. Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22. */
  23.  
  24. #if !defined (octave_idx_vector_h)
  25. #define octave_idx_vector_h 1
  26.  
  27. class ostream;
  28. class Matrix;
  29. class Range;
  30.  
  31. class
  32. idx_vector
  33. {
  34. public:
  35.   idx_vector (void);
  36.   idx_vector (const idx_vector& a);
  37.  
  38.   idx_vector (const Matrix& m, int do_ftn_idx,
  39.           const char *rc = 0, int z_len = 0);
  40.  
  41.   idx_vector (const Range& r);
  42.  
  43.  ~idx_vector (void);
  44.  
  45.   idx_vector& operator = (const idx_vector& a);
  46.  
  47.   operator void * () const;
  48.  
  49.   int capacity (void) const;
  50.   int length (void) const;
  51.  
  52.   int elem (int n) const;
  53.   int checkelem (int n) const;
  54.   int operator () (int n) const;
  55.  
  56. // other stuff
  57.  
  58.   int max (void) const;
  59.   int min (void) const;
  60.  
  61.   int one_zero_only (void) const;
  62.   int zeros_count (void) const;
  63.   int ones_count (void) const;
  64.  
  65.   void sort (void);
  66.   void sort_uniq (void);
  67.  
  68.   void shorten (int n); // Unsafe.  Avoid at all cost.
  69.  
  70. // i/o
  71.  
  72.   friend ostream& operator << (ostream& os, const idx_vector& a);
  73.  
  74. private:
  75.  
  76.   int len;
  77.   int one_zero;
  78.   int num_zeros;
  79.   int num_ones;
  80.   int max_val;
  81.   int min_val;
  82.   int initialized;
  83.   int *data;
  84.  
  85.   void init_state (const char *rc = 0, int z_len = 0);
  86.   void convert_one_zero_to_idx (void);
  87. };
  88.  
  89. inline idx_vector::idx_vector (void)
  90. {
  91.   len = 0;
  92.   data = 0;
  93.   num_zeros = 0;
  94.   num_ones = 0;
  95.   one_zero = 0;
  96.   initialized = 0;
  97. }
  98.  
  99. inline idx_vector::~idx_vector (void)
  100. {
  101.   delete [] data;
  102. }
  103.  
  104. inline idx_vector::operator void * () const
  105. {
  106.   return initialized ? (void *) 1 : (void *) 0;
  107. }
  108.  
  109. inline int idx_vector::capacity (void) const { return len; }
  110. inline int idx_vector::length (void) const { return len; }
  111.  
  112. inline int idx_vector::elem (int n) const { return data[n]; }
  113.  
  114. inline int idx_vector::operator () (int n) const { return checkelem (n); }
  115.  
  116. inline int idx_vector::max (void) const { return max_val; }
  117. inline int idx_vector::min (void) const { return min_val; }
  118.  
  119. inline int idx_vector::one_zero_only (void) const { return one_zero; }
  120. inline int idx_vector::zeros_count (void) const { return num_zeros; }
  121. inline int idx_vector::ones_count (void) const { return num_ones; }
  122.  
  123. #endif
  124.  
  125. /*
  126. ;;; Local Variables: ***
  127. ;;; mode: C++ ***
  128. ;;; page-delimiter: "^/\\*" ***
  129. ;;; End: ***
  130. */
  131.