~ubuntu-branches/debian/sid/octave3.0/sid

« back to all changes in this revision

Viewing changes to src/oct-obj.h

  • Committer: Bazaar Package Importer
  • Author(s): Rafael Laboissiere
  • Date: 2007-12-23 16:04:15 UTC
  • Revision ID: james.westby@ubuntu.com-20071223160415-n4gk468dihy22e9v
Tags: upstream-3.0.0
ImportĀ upstreamĀ versionĀ 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (C) 1994, 1995, 1996, 1997, 1998, 2000, 2002, 2003, 2004,
 
4
              2005, 2006, 2007 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 3 of the License, or (at your
 
11
option) any 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, see
 
20
<http://www.gnu.org/licenses/>.
 
21
 
 
22
*/
 
23
 
 
24
#if !defined (octave_oct_obj_h)
 
25
#define octave_oct_obj_h 1
 
26
 
 
27
#include <string>
 
28
#include <vector>
 
29
 
 
30
#include "oct-alloc.h"
 
31
#include "str-vec.h"
 
32
 
 
33
#include "ov.h"
 
34
 
 
35
class
 
36
OCTINTERP_API
 
37
octave_value_list
 
38
{
 
39
public:
 
40
 
 
41
  octave_value_list (void)
 
42
    : data () { }
 
43
 
 
44
  octave_value_list (octave_idx_type n, const octave_value& val)
 
45
    : data (n, val) { }
 
46
 
 
47
  octave_value_list (const octave_value& tc)
 
48
    : data (1, tc) { }
 
49
 
 
50
  octave_value_list (const octave_value_list& obj)
 
51
    : data (obj.data), names (obj.names) { }
 
52
 
 
53
  ~octave_value_list (void) { }
 
54
 
 
55
  void *operator new (size_t size)
 
56
    { return allocator.alloc (size); }
 
57
 
 
58
  void operator delete (void *p, size_t size)
 
59
    { allocator.free (p, size); }
 
60
 
 
61
  // FIXME -- without this, I have errors with the stack of
 
62
  // octave_value_list objects in ov-usr-fcn.h.  Why?
 
63
  void *operator new (size_t size, void *p)
 
64
    { return ::operator new (size, p); }
 
65
 
 
66
  void operator delete (void *p, void *)
 
67
    {
 
68
#if defined (HAVE_PLACEMENT_DELETE)
 
69
      ::operator delete (p, static_cast<void *> (0));
 
70
#else
 
71
      ::operator delete (p);
 
72
#endif
 
73
    }
 
74
 
 
75
  octave_value_list& operator = (const octave_value_list& obj)
 
76
    {
 
77
      if (this != &obj)
 
78
        {
 
79
          data = obj.data;
 
80
          names = obj.names;
 
81
        }
 
82
 
 
83
      return *this;
 
84
    }
 
85
 
 
86
  bool valid_scalar_indices (void) const;
 
87
 
 
88
  // Assignment will resize on range errors.
 
89
 
 
90
  octave_value& operator () (octave_idx_type n) { return elem (n); }
 
91
 
 
92
  octave_value operator () (octave_idx_type n) const { return elem (n); }
 
93
 
 
94
  octave_idx_type length (void) const { return data.size (); }
 
95
 
 
96
  bool empty (void) const { return length () == 0; }
 
97
 
 
98
  void resize (octave_idx_type n) { data.resize (n); }
 
99
 
 
100
  void resize (octave_idx_type n, const octave_value& val);
 
101
 
 
102
  octave_value_list& prepend (const octave_value& val);
 
103
 
 
104
  octave_value_list& append (const octave_value& val);
 
105
 
 
106
  octave_value_list& append (const octave_value_list& lst);
 
107
 
 
108
  octave_value_list& reverse (void);
 
109
 
 
110
  octave_value_list
 
111
  splice (octave_idx_type offset, octave_idx_type len,
 
112
          const octave_value_list& lst = octave_value_list ()) const;
 
113
 
 
114
  bool all_strings_p (void) const;
 
115
 
 
116
  bool has_magic_colon (void) const;
 
117
 
 
118
  string_vector make_argv (const std::string&) const;
 
119
 
 
120
  void stash_name_tags (const string_vector& nm) { names = nm; }
 
121
 
 
122
  string_vector name_tags (void) const { return names; }
 
123
 
 
124
private:
 
125
 
 
126
  static octave_allocator allocator;
 
127
 
 
128
  std::vector<octave_value> data;
 
129
 
 
130
  // This list of strings can be used to tag each element of data with
 
131
  // a name.  By default, it is empty.
 
132
  string_vector names;
 
133
 
 
134
  // This constructor is private with no definition to keep statements
 
135
  // like
 
136
  //
 
137
  //   octave_value_list foo = 5;
 
138
  //   octave_value_list foo = 5.0;
 
139
  //
 
140
  // from doing different things.  Instead, you have to use the
 
141
  // constructor
 
142
  //
 
143
  //   octave_value_list (n, val);
 
144
  //
 
145
  // and supply a default value to create a vector-valued
 
146
  // octave_value_list.
 
147
 
 
148
  octave_value_list (octave_idx_type n);
 
149
 
 
150
  octave_value_list (const Array<octave_value>& d);
 
151
 
 
152
  octave_value& elem (octave_idx_type n)
 
153
    {
 
154
      static Matrix empty_matrix;
 
155
 
 
156
      if (n >= length ())
 
157
        resize (n+1, empty_matrix);
 
158
 
 
159
      return data[n];
 
160
    }
 
161
 
 
162
  octave_value elem (octave_idx_type n) const
 
163
    {
 
164
#if defined (BOUNDS_CHECKING)
 
165
      return data.at (n);
 
166
#else
 
167
      return data[n];
 
168
#endif
 
169
    }
 
170
};
 
171
 
 
172
#endif
 
173
 
 
174
/*
 
175
;;; Local Variables: ***
 
176
;;; mode: C++ ***
 
177
;;; End: ***
 
178
*/