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 |
4192
|
26 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION) |
2901
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <cstdlib> |
|
31 |
3503
|
32 #include <iostream> |
2901
|
33 #include <string> |
|
34 |
|
35 #include "oct-alloc.h" |
3340
|
36 #include "oct-stream.h" |
2901
|
37 #include "ov-base.h" |
4376
|
38 #include "ov-scalar.h" |
2901
|
39 #include "ov-typeinfo.h" |
|
40 |
|
41 class tree_walker; |
|
42 class octave_stream; |
|
43 class octave_value; |
|
44 class octave_value_list; |
|
45 |
|
46 // Lists. |
|
47 |
|
48 class |
|
49 octave_file : public octave_base_value |
|
50 { |
|
51 public: |
|
52 |
|
53 octave_file (void) |
3340
|
54 : octave_base_value (), stream (), number (-1) { } |
2901
|
55 |
3340
|
56 octave_file (const octave_stream& s, int n) |
2901
|
57 : octave_base_value (), stream (s), number (n) { } |
|
58 |
|
59 octave_file (const octave_file& f) |
|
60 : octave_base_value (), stream (f.stream), number (f.number) { } |
|
61 |
|
62 ~octave_file (void) { } |
|
63 |
3933
|
64 octave_value *clone (void) const { return new octave_file (*this); } |
4376
|
65 |
|
66 // For compatibility, a file object should appear as if it is a |
|
67 // scalar object, in contexts where that is needed. |
|
68 octave_value *empty_clone (void) const { return new octave_scalar (); } |
2901
|
69 |
|
70 type_conv_fcn numeric_conversion_function (void) const; |
|
71 |
4254
|
72 double double_value (bool) const { return number; } |
2916
|
73 |
4254
|
74 double scalar_value (bool) const { return number; } |
2901
|
75 |
3340
|
76 octave_stream stream_value (void) const { return stream; } |
2901
|
77 |
|
78 int stream_number (void) const { return number; } |
|
79 |
|
80 bool is_defined (void) const { return true; } |
|
81 |
3340
|
82 bool is_stream (void) const { return true; } |
2901
|
83 |
4608
|
84 // Pretend we are a real scalar for better compatibility, maybe. |
|
85 |
|
86 bool is_real_scalar (void) const { return true; } |
|
87 |
|
88 bool is_real_type (void) const { return true; } |
|
89 |
|
90 dim_vector dims (void) const { static dim_vector dv (1, 1); return dv; } |
|
91 |
|
92 octave_value all (int = 0) const { return (number != 0.0); } |
|
93 |
|
94 octave_value any (int = 0) const { return (number != 0.0); } |
|
95 |
3523
|
96 void print (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
97 |
3523
|
98 void print_raw (std::ostream& os, bool pr_as_read_syntax = false) const; |
2901
|
99 |
3523
|
100 bool print_name_tag (std::ostream& os, const std::string& name) const; |
2901
|
101 |
|
102 private: |
|
103 |
|
104 // The stream object. |
3340
|
105 octave_stream stream; |
2901
|
106 |
|
107 // The number of the beast. |
|
108 int number; |
|
109 |
4612
|
110 DECLARE_OCTAVE_ALLOCATOR |
2901
|
111 |
4612
|
112 DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA |
2901
|
113 }; |
|
114 |
|
115 #endif |
|
116 |
|
117 /* |
|
118 ;;; Local Variables: *** |
|
119 ;;; mode: C++ *** |
|
120 ;;; End: *** |
|
121 */ |