2901
|
1 /* |
|
2 |
|
3 Copyright (C) 1996, 1997 John W. Eaton |
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_file_h) |
|
24 #define octave_file_h 1 |
|
25 |
|
26 #include <cstdlib> |
|
27 |
3503
|
28 #include <iostream> |
2901
|
29 #include <string> |
|
30 |
|
31 #include "oct-alloc.h" |
3340
|
32 #include "oct-stream.h" |
2901
|
33 #include "ov-base.h" |
4376
|
34 #include "ov-scalar.h" |
2901
|
35 #include "ov-typeinfo.h" |
|
36 |
|
37 class tree_walker; |
|
38 class octave_stream; |
|
39 class octave_value; |
|
40 class octave_value_list; |
|
41 |
|
42 // Lists. |
|
43 |
|
44 class |
|
45 octave_file : public octave_base_value |
|
46 { |
|
47 public: |
|
48 |
|
49 octave_file (void) |
3340
|
50 : octave_base_value (), stream (), number (-1) { } |
2901
|
51 |
3340
|
52 octave_file (const octave_stream& s, int n) |
2901
|
53 : octave_base_value (), stream (s), number (n) { } |
|
54 |
|
55 octave_file (const octave_file& f) |
|
56 : octave_base_value (), stream (f.stream), number (f.number) { } |
|
57 |
|
58 ~octave_file (void) { } |
|
59 |
3933
|
60 octave_value *clone (void) const { return new octave_file (*this); } |
4376
|
61 |
|
62 // For compatibility, a file object should appear as if it is a |
|
63 // scalar object, in contexts where that is needed. |
|
64 octave_value *empty_clone (void) const { return new octave_scalar (); } |
2901
|
65 |
|
66 type_conv_fcn numeric_conversion_function (void) const; |
|
67 |
4254
|
68 double double_value (bool) const { return number; } |
2916
|
69 |
4254
|
70 double scalar_value (bool) const { return number; } |
2901
|
71 |
3340
|
72 octave_stream stream_value (void) const { return stream; } |
2901
|
73 |
|
74 int stream_number (void) const { return number; } |
|
75 |
|
76 bool is_defined (void) const { return true; } |
|
77 |
3340
|
78 bool is_stream (void) const { return true; } |
2901
|
79 |
4608
|
80 // Pretend we are a real scalar for better compatibility, maybe. |
|
81 |
|
82 bool is_real_scalar (void) const { return true; } |
|
83 |
|
84 bool is_real_type (void) const { return true; } |
|
85 |
|
86 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
|
87 |
|
88 octave_value all (int = 0) const { return (number != 0.0); } |
|
89 |
|
90 octave_value any (int = 0) const { return (number != 0.0); } |
|
91 |
3523
|
92 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
93 |
3523
|
94 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
95 |
3523
|
96 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2901
|
97 |
|
98 private: |
|
99 |
|
100 // The stream object. |
3340
|
101 octave_stream stream; |
2901
|
102 |
|
103 // The number of the beast. |
|
104 int number; |
|
105 |
4612
|
106 DECLARE_OCTAVE_ALLOCATOR |
2901
|
107 |
4612
|
108 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2901
|
109 }; |
|
110 |
|
111 #endif |
|
112 |
|
113 /* |
|
114 ;;; Local Variables: *** |
|
115 ;;; mode: C++ *** |
|
116 ;;; End: *** |
|
117 */ |