メインページ   クラス階層   構成   ファイル一覧   構成メンバ   ファイルメンバ  

idx-vector.h

解説を見る。
00001 /*
00002 
00003 Copyright (C) 1996, 1997 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 2, or (at your option) any
00010 later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, write to the Free
00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00020 
00021 */
00022 
00023 #if !defined (octave_idx_vector_h)
00024 #define octave_idx_vector_h 1
00025 
00026 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00027 #pragma interface
00028 #endif
00029 
00030 #include <iostream>
00031 
00032 #include "dim-vector.h"
00033 #include "oct-inttypes.h"
00034 #include "intNDArray.h"
00035 
00036 class ColumnVector;
00037 class boolNDArray;
00038 class NDArray;
00039 class Range;
00040 
00041 class
00042 idx_vector
00043 {
00044 private:
00045 
00046   class
00047   idx_vector_rep
00048   {
00049   public:
00050 
00051     idx_vector_rep (void)
00052       : data (0), len (0), num_zeros (0), num_ones (0), max_val (0),
00053         min_val (0), count (1), frozen_at_z_len (0), frozen_len (0),
00054         colon (0), one_zero (0), initialized (0), frozen (0),
00055         colon_equiv_checked (0), colon_equiv (0), orig_dims () { }
00056 
00057     idx_vector_rep (const ColumnVector& v);
00058 
00059     idx_vector_rep (const NDArray& nda);
00060 
00061     template <class U>
00062     idx_vector_rep (const intNDArray<U>& inda)
00063       : data (0), len (inda.length ()), num_zeros (0), num_ones (0),
00064         max_val (0), min_val (0), count (1), frozen_at_z_len (0),
00065         frozen_len (0), colon (0), one_zero (0), initialized (0),
00066         frozen (0), colon_equiv_checked (0), colon_equiv (0),
00067         orig_dims (inda.dims ())
00068     {
00069       if (len == 0)
00070         {
00071           initialized = 1;
00072           return;
00073         }
00074       else
00075         {
00076           data = new int [len];
00077 
00078           bool conversion_error = false;
00079 
00080           for (int i = 0; i < len; i++)
00081             data[i] = tree_to_mat_idx (inda.elem (i), conversion_error);
00082 
00083           if (conversion_error)
00084             return;
00085         }
00086 
00087       init_state ();
00088     }
00089 
00090     idx_vector_rep (const Range& r);
00091 
00092     idx_vector_rep (double d);
00093 
00094     idx_vector_rep (int i);
00095 
00096     idx_vector_rep (char c);
00097 
00098     idx_vector_rep (bool b);
00099 
00100     template <class U>
00101     idx_vector_rep (const octave_int<U>& i)
00102       : data (0), len (1), num_zeros (0), num_ones (0),
00103         max_val (0), min_val (0), count (1), frozen_at_z_len (0),
00104         frozen_len (0), colon (0), one_zero (0), initialized (0),
00105         frozen (0), colon_equiv_checked (0), colon_equiv (0),
00106         orig_dims (1, 1)
00107     {
00108       data = new int [len];
00109 
00110       data[0] = tree_to_mat_idx (i);
00111 
00112       init_state ();
00113     }
00114 
00115     idx_vector_rep (const boolNDArray& bnda);
00116 
00117     idx_vector_rep (const idx_vector_rep& a);
00118 
00119     ~idx_vector_rep (void) { delete [] data; }
00120 
00121     idx_vector_rep& operator = (const idx_vector_rep& a);
00122 
00123     int ok (void) { return initialized; }
00124 
00125     int capacity (void) const { return len; }
00126     int length (int colon_len) const { return colon ? colon_len : len; }
00127 
00128     int elem (int n) const { return colon ? n : data[n]; }
00129 
00130     int checkelem (int n) const;
00131     int operator () (int n) const { return checkelem (n); }
00132 
00133     int max (void) const { return max_val; }
00134     int min (void) const { return min_val; }
00135 
00136     int one_zero_only (void) const { return one_zero; }
00137     int zeros_count (void) const { return num_zeros; }
00138     int ones_count (void) const { return num_ones; }
00139 
00140     int is_colon (void) const { return colon; }
00141     int is_colon_equiv (int n, int sort_uniq);
00142 
00143     void sort (bool uniq);
00144 
00145     int orig_rows (void) const { return orig_dims(0); }
00146     int orig_columns (void) const { return orig_dims(1); }
00147 
00148     dim_vector orig_dimensions (void) const { return orig_dims; }
00149 
00150     // other stuff
00151 
00152     void shorten (int n); // Unsafe.  Avoid at all cost.
00153 
00154     int freeze (int z_len, const char *tag, bool resize_ok, bool warn_resize);
00155 
00156     // i/o
00157 
00158     std::ostream& print (std::ostream& os) const;
00159 
00160     int *data;
00161     int len;
00162     int num_zeros;
00163     int num_ones;
00164     int max_val;
00165     int min_val;
00166 
00167     int count;
00168     int frozen_at_z_len;
00169     int frozen_len;
00170 
00171     unsigned int colon : 1;
00172     unsigned int one_zero : 1;
00173     unsigned int initialized : 1;
00174     unsigned int frozen : 1;
00175     unsigned int colon_equiv_checked : 1;
00176     unsigned int colon_equiv : 1;
00177 
00178     dim_vector orig_dims;
00179  
00180     void init_state (void);
00181 
00182     void maybe_convert_one_zero_to_idx (int z_len);
00183 
00184     int tree_to_mat_idx (double x, bool& conversion_error);
00185 
00186     int tree_to_mat_idx (int i) { return i - 1; }
00187 
00188     template <class U> int tree_to_mat_idx (const octave_int<U>& i)
00189       { return i.value () - 1; }
00190   };
00191 
00192 public:
00193 
00194   idx_vector (void) : rep (new idx_vector_rep ()) { }
00195 
00196   idx_vector (const ColumnVector& v) : rep (new idx_vector_rep (v)) { }
00197 
00198   idx_vector (const NDArray& nda) : rep (new idx_vector_rep (nda)) { }
00199 
00200   template <class U>
00201   idx_vector (const intNDArray<U>& inda) : rep (new idx_vector_rep (inda)) { }
00202 
00203   idx_vector (const Range& r) : rep (new idx_vector_rep (r)) { }
00204 
00205   idx_vector (double d) : rep (new idx_vector_rep (d)) { }
00206 
00207   idx_vector (int i) : rep (new idx_vector_rep (i)) { }
00208 
00209   idx_vector (char c) : rep (new idx_vector_rep (c)) { }
00210 
00211   idx_vector (bool b) : rep (new idx_vector_rep (b)) { }
00212 
00213   template <class U>
00214   idx_vector (const octave_int<U>& i) : rep (new idx_vector_rep (i)) { }
00215 
00216   idx_vector (const boolNDArray& bnda) : rep (new idx_vector_rep (bnda)) { }
00217 
00218   idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; }
00219 
00220   ~idx_vector (void)
00221     {
00222       if (--rep->count <= 0)
00223         delete rep;
00224     }
00225 
00226   idx_vector& operator = (const idx_vector& a)
00227     {
00228       if (this != &a)
00229         {
00230           if (--rep->count <= 0)
00231             delete rep;
00232 
00233           rep = a.rep;
00234           rep->count++;
00235         }
00236       return *this;
00237     }
00238 
00239   operator bool () const { return rep->ok (); }
00240 
00241   int capacity (void) const { return rep->capacity (); }
00242   int length (int cl) const { return rep->length (cl); }
00243 
00244   int elem (int n) const { return rep->elem (n); }
00245   int checkelem (int n) const { return rep->checkelem (n); }
00246   int operator () (int n) const { return rep->operator () (n); }
00247 
00248   int max (void) const { return rep->max (); }
00249   int min (void) const { return rep->min (); }
00250 
00251   int one_zero_only (void) const { return rep->one_zero_only (); }
00252   int zeros_count (void) const { return rep->zeros_count (); }
00253   int ones_count (void) const { return rep->ones_count (); }
00254 
00255   int is_colon (void) const { return rep->is_colon (); }
00256   int is_colon_equiv (int n, int sort_uniq = 0) const
00257     { return rep->is_colon_equiv (n, sort_uniq); }
00258 
00259   void sort (bool uniq = false) { rep->sort (uniq); }
00260 
00261   int orig_rows (void) const { return rep->orig_rows (); }
00262   int orig_columns (void) const { return rep->orig_columns (); }
00263 
00264   dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); }
00265 
00266   int orig_empty (void) const
00267     { return (! is_colon () && orig_dimensions().any_zero ()); }
00268 
00269   // Unsafe.  Avoid at all cost.
00270   void shorten (int n) { rep->shorten (n); }
00271 
00272   // i/o
00273 
00274   int freeze (int z_len, const char *tag, bool resize_ok = false,
00275               bool warn_resize = false)
00276     { return rep->freeze (z_len, tag, resize_ok, warn_resize); }
00277 
00278   std::ostream& print (std::ostream& os) const { return rep->print (os); }
00279 
00280   friend std::ostream& operator << (std::ostream& os, const idx_vector& a)
00281     { return a.print (os); }
00282 
00283   void maybe_convert_one_zero_to_idx (int z_len)
00284     { rep->maybe_convert_one_zero_to_idx (z_len); }
00285 
00286 private:
00287 
00288   idx_vector_rep *rep;
00289 
00290   void init_state (void) { rep->init_state (); }
00291 };
00292 
00293 #endif
00294 
00295 /*
00296 ;;; Local Variables: ***
00297 ;;; mode: C++ ***
00298 ;;; End: ***
00299 */

Wed Dec 29 11:51:37 2004に生成されました。 doxygen1.2.18
SEO [PR] 爆速!無料ブログ 無料ホームページ開設 無料ライブ放送