comparison src/ov.cc @ 4044:9678c5526190

[project @ 2002-08-15 16:54:55 by jwe]
author jwe
date Thu, 15 Aug 2002 16:54:56 +0000
parents 243f50d6f3d5
children 6e86256e9c54
comparison
equal deleted inserted replaced
4043:6fae69a1796e 4044:9678c5526190
905 } 905 }
906 906
907 return retval; 907 return retval;
908 } 908 }
909 909
910 Array<int>
911 octave_value::int_vector_value (bool force_string_conv, bool require_int,
912 bool force_vector_conversion) const
913 {
914 Array<int> retval;
915
916 Matrix m = matrix_value (force_string_conv);
917
918 if (error_state)
919 return retval;
920
921 int nr = m.rows ();
922 int nc = m.columns ();
923
924 if (nr == 1)
925 {
926 retval.resize (nc);
927 for (int i = 0; i < nc; i++)
928 {
929 double d = m (0, i);
930
931 if (require_int && D_NINT (d) != d)
932 {
933 error ("conversion to integer value failed");
934 return retval;
935 }
936
937 retval (i) = static_cast<int> (d);
938 }
939 }
940 else if (nc == 1)
941 {
942 retval.resize (nr);
943 for (int i = 0; i < nr; i++)
944 {
945 double d = m (i, 0);
946
947 if (require_int && D_NINT (d) != d)
948 {
949 error ("conversion to integer value failed");
950 return retval;
951 }
952
953 retval (i) = static_cast<int> (d);
954 }
955 }
956 else if (nr > 0 && nc > 0
957 && (Vdo_fortran_indexing || force_vector_conversion))
958 {
959 retval.resize (nr * nc);
960 int k = 0;
961 for (int j = 0; j < nc; j++)
962 {
963 for (int i = 0; i < nr; i++)
964 {
965 double d = m (i, j);
966
967 if (require_int && D_NINT (d) != d)
968 {
969 error ("conversion to integer value failed");
970 return retval;
971 }
972
973 retval (k++) = static_cast<int> (d);
974 }
975 }
976 }
977 else
978 {
979 std::string tn = type_name ();
980 gripe_invalid_conversion (tn.c_str (), "real vector");
981 }
982
983 return retval;
984 }
985
910 Array<Complex> 986 Array<Complex>
911 octave_value::complex_vector_value (bool force_string_conv, 987 octave_value::complex_vector_value (bool force_string_conv,
912 bool force_vector_conversion) const 988 bool force_vector_conversion) const
913 { 989 {
914 Array<Complex> retval; 990 Array<Complex> retval;