oct-obj.h

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1994-2012 John W. Eaton
00004 Copyright (C) 2009 VZLU Prague
00005 
00006 This file is part of Octave.
00007 
00008 Octave is free software; you can redistribute it and/or modify it
00009 under the terms of the GNU General Public License as published by the
00010 Free Software Foundation; either version 3 of the License, or (at your
00011 option) any later version.
00012 
00013 Octave is distributed in the hope that it will be useful, but WITHOUT
00014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00015 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00016 for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Octave; see the file COPYING.  If not, see
00020 <http://www.gnu.org/licenses/>.
00021 
00022 */
00023 
00024 #if !defined (octave_oct_obj_h)
00025 #define octave_oct_obj_h 1
00026 
00027 #include <string>
00028 #include <vector>
00029 
00030 #include "oct-alloc.h"
00031 #include "str-vec.h"
00032 #include "Array.h"
00033 
00034 #include "ov.h"
00035 #include "Cell.h"
00036 
00037 class
00038 OCTINTERP_API
00039 octave_value_list
00040 {
00041 public:
00042 
00043   octave_value_list (void)
00044     : data (), names () { }
00045 
00046   explicit octave_value_list (octave_idx_type n)
00047     : data (dim_vector (1, n)), names () { }
00048 
00049   octave_value_list (octave_idx_type n, const octave_value& val)
00050     : data (dim_vector (1, n), val), names () { }
00051 
00052   octave_value_list (const octave_value& tc)
00053     : data (dim_vector (1, 1), tc), names () { }
00054 
00055   octave_value_list (const Array<octave_value>& d)
00056     : data (d.as_row ()), names () { }
00057 
00058   octave_value_list (const Cell& tc)
00059     : data (tc.as_row ()), names () { }
00060 
00061   octave_value_list (const octave_value_list& obj)
00062     : data (obj.data), names (obj.names) { }
00063 
00064   // Concatenation constructor.
00065   octave_value_list (const std::list<octave_value_list>&);
00066 
00067   ~octave_value_list (void) { }
00068 
00069   octave_value_list& operator = (const octave_value_list& obj)
00070     {
00071       if (this != &obj)
00072         {
00073           data = obj.data;
00074           names = obj.names;
00075         }
00076 
00077       return *this;
00078     }
00079 
00080   Array<octave_value> array_value (void) const { return data; }
00081 
00082   Cell cell_value (void) const { return array_value (); }
00083 
00084   // Assignment will resize on range errors.
00085 
00086   octave_value& operator () (octave_idx_type n) { return elem (n); }
00087 
00088   const octave_value& operator () (octave_idx_type n) const { return elem (n); }
00089 
00090   octave_idx_type length (void) const { return data.length (); }
00091 
00092   bool empty (void) const { return length () == 0; }
00093 
00094   void resize (octave_idx_type n, const octave_value& rfv
00095                = Array<octave_value>::resize_fill_value ())
00096   {
00097     data.resize (dim_vector (1, n), rfv);
00098   }
00099 
00100   octave_value_list& prepend (const octave_value& val);
00101 
00102   octave_value_list& append (const octave_value& val);
00103 
00104   octave_value_list& append (const octave_value_list& lst);
00105 
00106   octave_value_list& reverse (void);
00107 
00108   octave_value_list
00109   slice (octave_idx_type offset, octave_idx_type len, bool tags = false) const
00110     {
00111       octave_value_list retval (data.linear_slice (offset, offset + len));
00112       if (tags && len > 0 && names.length () > 0)
00113         retval.names = names.linear_slice (offset, std::min (len, names.length ()));
00114 
00115       return retval;
00116     }
00117 
00118   octave_value_list
00119   splice (octave_idx_type offset, octave_idx_type len,
00120           const octave_value_list& lst = octave_value_list ()) const;
00121 
00122   bool all_strings_p (void) const;
00123 
00124   bool all_scalars (void) const;
00125 
00126   bool any_cell (void) const;
00127 
00128   bool has_magic_colon (void) const;
00129 
00130   string_vector make_argv (const std::string& = std::string()) const;
00131 
00132   void stash_name_tags (const string_vector& nm) { names = nm; }
00133 
00134   string_vector name_tags (void) const { return names; }
00135 
00136   void make_storable_values (void);
00137 
00138   octave_value& xelem (octave_idx_type i)
00139     {
00140       return data.xelem (i);
00141     }
00142 
00143   void clear (void)
00144     {
00145       data.clear ();
00146     }
00147 
00148 private:
00149 
00150   Array<octave_value> data;
00151 
00152   // This list of strings can be used to tag each element of data with
00153   // a name.  By default, it is empty.
00154   string_vector names;
00155 
00156   octave_value& elem (octave_idx_type n)
00157     {
00158       if (n >= length ())
00159         resize (n + 1);
00160 
00161       return data(n);
00162     }
00163 
00164   const octave_value& elem (octave_idx_type n) const
00165     { return data(n); }
00166 
00167   DECLARE_OCTAVE_ALLOCATOR
00168 };
00169 
00170 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines