Mercurial > hg > octave-lyh
comparison src/oct-stream.cc @ 5659:960f4b9a26af
[project @ 2006-03-10 15:35:20 by jwe]
author | jwe |
---|---|
date | Fri, 10 Mar 2006 15:35:21 +0000 |
parents | d24b97246b9b |
children | 8d7162924bd3 |
comparison
equal
deleted
inserted
replaced
5658:7b45fda21557 | 5659:960f4b9a26af |
---|---|
2789 int | 2789 int |
2790 octave_stream::flush (void) | 2790 octave_stream::flush (void) |
2791 { | 2791 { |
2792 int retval = -1; | 2792 int retval = -1; |
2793 | 2793 |
2794 if (stream_ok ("fflush")) | 2794 if (stream_ok ()) |
2795 retval = rep->flush (); | 2795 retval = rep->flush (); |
2796 | 2796 |
2797 return retval; | 2797 return retval; |
2798 } | 2798 } |
2799 | 2799 |
2800 std::string | 2800 std::string |
2801 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who) | 2801 octave_stream::getl (octave_idx_type max_len, bool& err, const std::string& who) |
2802 { | 2802 { |
2803 std::string retval; | 2803 std::string retval; |
2804 | 2804 |
2805 if (stream_ok (who)) | 2805 if (stream_ok ()) |
2806 retval = rep->getl (max_len, err, who); | 2806 retval = rep->getl (max_len, err, who); |
2807 | 2807 |
2808 return retval; | 2808 return retval; |
2809 } | 2809 } |
2810 | 2810 |
2834 std::string | 2834 std::string |
2835 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who) | 2835 octave_stream::gets (octave_idx_type max_len, bool& err, const std::string& who) |
2836 { | 2836 { |
2837 std::string retval; | 2837 std::string retval; |
2838 | 2838 |
2839 if (stream_ok (who)) | 2839 if (stream_ok ()) |
2840 retval = rep->gets (max_len, err, who); | 2840 retval = rep->gets (max_len, err, who); |
2841 | 2841 |
2842 return retval; | 2842 return retval; |
2843 } | 2843 } |
2844 | 2844 |
2868 int | 2868 int |
2869 octave_stream::seek (long offset, int origin) | 2869 octave_stream::seek (long offset, int origin) |
2870 { | 2870 { |
2871 int status = -1; | 2871 int status = -1; |
2872 | 2872 |
2873 if (stream_ok ("fseek")) | 2873 if (stream_ok ()) |
2874 { | 2874 { |
2875 clearerr (); | 2875 clearerr (); |
2876 | 2876 |
2877 long orig_pos = rep->tell (); | 2877 long orig_pos = rep->tell (); |
2878 | 2878 |
2975 long | 2975 long |
2976 octave_stream::tell (void) | 2976 octave_stream::tell (void) |
2977 { | 2977 { |
2978 long retval = -1; | 2978 long retval = -1; |
2979 | 2979 |
2980 if (stream_ok ("tell")) | 2980 if (stream_ok ()) |
2981 retval = rep->tell (); | 2981 retval = rep->tell (); |
2982 | 2982 |
2983 return retval; | 2983 return retval; |
2984 } | 2984 } |
2985 | 2985 |
2986 int | 2986 int |
2987 octave_stream::rewind (void) | 2987 octave_stream::rewind (void) |
2988 { | 2988 { |
2989 int retval = -1; | 2989 int retval = -1; |
2990 | 2990 |
2991 if (stream_ok ("frewind")) | 2991 if (stream_ok ()) |
2992 retval = rep->rewind (); | 2992 retval = rep->rewind (); |
2993 | 2993 |
2994 return retval; | 2994 return retval; |
2995 } | 2995 } |
2996 | 2996 |
2997 bool | 2997 bool |
2998 octave_stream::is_open (void) const | 2998 octave_stream::is_open (void) const |
2999 { | 2999 { |
3000 bool retval = false; | 3000 bool retval = false; |
3001 | 3001 |
3002 if (stream_ok ("is_open")) | 3002 if (stream_ok ()) |
3003 retval = rep->is_open (); | 3003 retval = rep->is_open (); |
3004 | 3004 |
3005 return retval; | 3005 return retval; |
3006 } | 3006 } |
3007 | 3007 |
3008 void | 3008 void |
3009 octave_stream::close (void) | 3009 octave_stream::close (void) |
3010 { | 3010 { |
3011 if (stream_ok ("close")) | 3011 if (stream_ok ()) |
3012 rep->close (); | 3012 rep->close (); |
3013 } | 3013 } |
3014 | 3014 |
3015 template <class RET_T, class READ_T> | 3015 template <class RET_T, class READ_T> |
3016 octave_value | 3016 octave_value |
3264 initialized = true; | 3264 initialized = true; |
3265 } | 3265 } |
3266 | 3266 |
3267 octave_value retval; | 3267 octave_value retval; |
3268 | 3268 |
3269 if (stream_ok ("fread")) | 3269 if (stream_ok ()) |
3270 { | 3270 { |
3271 // XXX FIXME XXX -- we may eventually want to make this extensible. | 3271 // XXX FIXME XXX -- we may eventually want to make this extensible. |
3272 | 3272 |
3273 // XXX FIXME XXX -- we need a better way to ensure that this | 3273 // XXX FIXME XXX -- we need a better way to ensure that this |
3274 // numbering stays consistent with the order of the elements in the | 3274 // numbering stays consistent with the order of the elements in the |
3327 oct_data_conv::data_type output_type, octave_idx_type skip, | 3327 oct_data_conv::data_type output_type, octave_idx_type skip, |
3328 oct_mach_info::float_format flt_fmt) | 3328 oct_mach_info::float_format flt_fmt) |
3329 { | 3329 { |
3330 octave_idx_type retval = -1; | 3330 octave_idx_type retval = -1; |
3331 | 3331 |
3332 if (stream_ok ("fwrite")) | 3332 if (stream_ok ()) |
3333 { | 3333 { |
3334 if (! error_state) | 3334 if (! error_state) |
3335 { | 3335 { |
3336 if (flt_fmt == oct_mach_info::flt_fmt_unknown) | 3336 if (flt_fmt == oct_mach_info::flt_fmt_unknown) |
3337 flt_fmt = float_format (); | 3337 flt_fmt = float_format (); |
3602 octave_stream::scanf (const std::string& fmt, const Array<double>& size, | 3602 octave_stream::scanf (const std::string& fmt, const Array<double>& size, |
3603 octave_idx_type& count, const std::string& who) | 3603 octave_idx_type& count, const std::string& who) |
3604 { | 3604 { |
3605 octave_value retval; | 3605 octave_value retval; |
3606 | 3606 |
3607 if (stream_ok (who)) | 3607 if (stream_ok ()) |
3608 retval = rep->scanf (fmt, size, count, who); | 3608 retval = rep->scanf (fmt, size, count, who); |
3609 | 3609 |
3610 return retval; | 3610 return retval; |
3611 } | 3611 } |
3612 | 3612 |
3638 octave_value_list | 3638 octave_value_list |
3639 octave_stream::oscanf (const std::string& fmt, const std::string& who) | 3639 octave_stream::oscanf (const std::string& fmt, const std::string& who) |
3640 { | 3640 { |
3641 octave_value_list retval; | 3641 octave_value_list retval; |
3642 | 3642 |
3643 if (stream_ok (who)) | 3643 if (stream_ok ()) |
3644 retval = rep->oscanf (fmt, who); | 3644 retval = rep->oscanf (fmt, who); |
3645 | 3645 |
3646 return retval; | 3646 return retval; |
3647 } | 3647 } |
3648 | 3648 |
3674 octave_stream::printf (const std::string& fmt, const octave_value_list& args, | 3674 octave_stream::printf (const std::string& fmt, const octave_value_list& args, |
3675 const std::string& who) | 3675 const std::string& who) |
3676 { | 3676 { |
3677 int retval = -1; | 3677 int retval = -1; |
3678 | 3678 |
3679 if (stream_ok (who)) | 3679 if (stream_ok ()) |
3680 retval = rep->printf (fmt, args, who); | 3680 retval = rep->printf (fmt, args, who); |
3681 | 3681 |
3682 return retval; | 3682 return retval; |
3683 } | 3683 } |
3684 | 3684 |
3710 int | 3710 int |
3711 octave_stream::puts (const std::string& s, const std::string& who) | 3711 octave_stream::puts (const std::string& s, const std::string& who) |
3712 { | 3712 { |
3713 int retval = -1; | 3713 int retval = -1; |
3714 | 3714 |
3715 if (stream_ok (who)) | 3715 if (stream_ok ()) |
3716 retval = rep->puts (s, who); | 3716 retval = rep->puts (s, who); |
3717 | 3717 |
3718 return retval; | 3718 return retval; |
3719 } | 3719 } |
3720 | 3720 |
3743 bool | 3743 bool |
3744 octave_stream::eof (void) const | 3744 octave_stream::eof (void) const |
3745 { | 3745 { |
3746 int retval = -1; | 3746 int retval = -1; |
3747 | 3747 |
3748 if (stream_ok ("feof")) | 3748 if (stream_ok ()) |
3749 retval = rep->eof (); | 3749 retval = rep->eof (); |
3750 | 3750 |
3751 return retval; | 3751 return retval; |
3752 } | 3752 } |
3753 | 3753 |
3754 std::string | 3754 std::string |
3755 octave_stream::error (bool clear, int& err_num) | 3755 octave_stream::error (bool clear, int& err_num) |
3756 { | 3756 { |
3757 std::string retval = "invalid stream object"; | 3757 std::string retval = "invalid stream object"; |
3758 | 3758 |
3759 if (stream_ok ("ferror", false, false)) | 3759 if (stream_ok (false)) |
3760 retval = rep->error (clear, err_num); | 3760 retval = rep->error (clear, err_num); |
3761 | 3761 |
3762 return retval; | 3762 return retval; |
3763 } | 3763 } |
3764 | 3764 |
3765 std::string | 3765 std::string |
3766 octave_stream::name (void) const | 3766 octave_stream::name (void) const |
3767 { | 3767 { |
3768 std::string retval; | 3768 std::string retval; |
3769 | 3769 |
3770 if (stream_ok ("name")) | 3770 if (stream_ok ()) |
3771 retval = rep->name (); | 3771 retval = rep->name (); |
3772 | 3772 |
3773 return retval; | 3773 return retval; |
3774 } | 3774 } |
3775 | 3775 |
3776 int | 3776 int |
3777 octave_stream::mode (void) const | 3777 octave_stream::mode (void) const |
3778 { | 3778 { |
3779 int retval = 0; | 3779 int retval = 0; |
3780 | 3780 |
3781 if (stream_ok ("mode")) | 3781 if (stream_ok ()) |
3782 retval = rep->mode (); | 3782 retval = rep->mode (); |
3783 | 3783 |
3784 return retval; | 3784 return retval; |
3785 } | 3785 } |
3786 | 3786 |
3787 oct_mach_info::float_format | 3787 oct_mach_info::float_format |
3788 octave_stream::float_format (void) const | 3788 octave_stream::float_format (void) const |
3789 { | 3789 { |
3790 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; | 3790 oct_mach_info::float_format retval = oct_mach_info::flt_fmt_unknown; |
3791 | 3791 |
3792 if (stream_ok ("float_format")) | 3792 if (stream_ok ()) |
3793 retval = rep->float_format (); | 3793 retval = rep->float_format (); |
3794 | 3794 |
3795 return retval; | 3795 return retval; |
3796 } | 3796 } |
3797 | 3797 |
3831 retval = "a+b"; | 3831 retval = "a+b"; |
3832 | 3832 |
3833 return retval; | 3833 return retval; |
3834 } | 3834 } |
3835 | 3835 |
3836 bool | |
3837 octave_stream::stream_ok (const std::string& who, bool clear, bool warn) const | |
3838 { | |
3839 bool retval = true; | |
3840 | |
3841 if (rep) | |
3842 { | |
3843 if (clear) | |
3844 rep->clear (); | |
3845 } | |
3846 else | |
3847 { | |
3848 if (warn) | |
3849 ::warning ("%s: attempt to use invalid I/O stream", who.c_str ()); | |
3850 | |
3851 retval = false; | |
3852 } | |
3853 | |
3854 return retval; | |
3855 } | |
3856 | |
3857 octave_stream_list *octave_stream_list::instance = 0; | 3836 octave_stream_list *octave_stream_list::instance = 0; |
3858 | 3837 |
3859 bool | 3838 bool |
3860 octave_stream_list::instance_ok (void) | 3839 octave_stream_list::instance_ok (void) |
3861 { | 3840 { |