Mercurial > octave-nkf
comparison libinterp/octave-value/ov-class.cc @ 20615:729a85dafba8
use new string_value method to handle value extraction errors
* ov-class.cc, ov-classdef.cc, ov-fcn-handle.cc, ov-fcn-inline.cc,
ov.cc, pt-idx.cc: Use new string_value method.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 08 Oct 2015 17:55:57 -0400 |
parents | c41595061186 |
children | eef93a493ce3 |
comparison
equal
deleted
inserted
replaced
20614:10ec79b47808 | 20615:729a85dafba8 |
---|---|
1854 else | 1854 else |
1855 { | 1855 { |
1856 // Called as class constructor | 1856 // Called as class constructor |
1857 octave_function *fcn = octave_call_stack::caller (); | 1857 octave_function *fcn = octave_call_stack::caller (); |
1858 | 1858 |
1859 if (args(1).is_string ()) | 1859 std::string id = args(1).string_value ("class: ID (class name) must be a string"); |
1860 { | 1860 |
1861 std::string id = args(1).string_value (); | 1861 if (fcn) |
1862 | 1862 { |
1863 if (fcn) | 1863 if (fcn->is_class_constructor (id) || fcn->is_class_method (id)) |
1864 { | 1864 { |
1865 if (fcn->is_class_constructor (id) || fcn->is_class_method (id)) | 1865 octave_map m = args(0).map_value (); |
1866 | |
1867 if (! error_state) | |
1866 { | 1868 { |
1867 octave_map m = args(0).map_value (); | 1869 if (nargin == 2) |
1868 | 1870 retval |
1869 if (! error_state) | 1871 = octave_value (new octave_class |
1872 (m, id, std::list<std::string> ())); | |
1873 else | |
1870 { | 1874 { |
1871 if (nargin == 2) | 1875 octave_value_list parents = args.slice (2, nargin-2); |
1872 retval | 1876 |
1873 = octave_value (new octave_class | 1877 retval |
1874 (m, id, std::list<std::string> ())); | 1878 = octave_value (new octave_class (m, id, parents)); |
1875 else | |
1876 { | |
1877 octave_value_list parents = args.slice (2, nargin-2); | |
1878 | |
1879 retval | |
1880 = octave_value (new octave_class (m, id, parents)); | |
1881 } | |
1882 | |
1883 octave_class::exemplar_const_iterator it | |
1884 = octave_class::exemplar_map.find (id); | |
1885 | |
1886 if (it == octave_class::exemplar_map.end ()) | |
1887 octave_class::exemplar_map[id] | |
1888 = octave_class::exemplar_info (retval); | |
1889 else if (! it->second.compare (retval)) | |
1890 error ("class: object of class '%s' does not match previously constructed objects", | |
1891 id.c_str ()); | |
1892 } | 1879 } |
1893 else | 1880 |
1894 error ("class: expecting structure S as first argument"); | 1881 octave_class::exemplar_const_iterator it |
1882 = octave_class::exemplar_map.find (id); | |
1883 | |
1884 if (it == octave_class::exemplar_map.end ()) | |
1885 octave_class::exemplar_map[id] | |
1886 = octave_class::exemplar_info (retval); | |
1887 else if (! it->second.compare (retval)) | |
1888 error ("class: object of class '%s' does not match previously constructed objects", | |
1889 id.c_str ()); | |
1895 } | 1890 } |
1896 else | 1891 else |
1897 error ("class: '%s' is invalid as a class name in this context", | 1892 error ("class: expecting structure S as first argument"); |
1898 id.c_str ()); | |
1899 } | 1893 } |
1900 else | 1894 else |
1901 error ("class: invalid call from outside class constructor or method"); | 1895 error ("class: '%s' is invalid as a class name in this context", |
1896 id.c_str ()); | |
1902 } | 1897 } |
1903 else | 1898 else |
1904 error ("class: ID (class name) must be a string"); | 1899 error ("class: invalid call from outside class constructor or method"); |
1905 } | 1900 } |
1906 | 1901 |
1907 return retval; | 1902 return retval; |
1908 } | 1903 } |
1909 | 1904 |
2185 return retval; | 2180 return retval; |
2186 } | 2181 } |
2187 | 2182 |
2188 for (int i = 0; i < args.length (); i++) | 2183 for (int i = 0; i < args.length (); i++) |
2189 { | 2184 { |
2190 std::string inf_class = args(i).string_value (); | 2185 std::string inf_class = args(i).string_value ("superiorto: expecting argument to be class name"); |
2191 if (error_state) | |
2192 { | |
2193 error ("superiorto: expecting argument to be class name"); | |
2194 break; | |
2195 } | |
2196 | 2186 |
2197 // User defined classes always have higher precedence | 2187 // User defined classes always have higher precedence |
2198 // than built-in classes | 2188 // than built-in classes |
2199 if (is_built_in_class (inf_class)) | 2189 if (is_built_in_class (inf_class)) |
2200 break; | 2190 break; |
2231 return retval; | 2221 return retval; |
2232 } | 2222 } |
2233 | 2223 |
2234 for (int i = 0; i < args.length (); i++) | 2224 for (int i = 0; i < args.length (); i++) |
2235 { | 2225 { |
2236 std::string sup_class = args(i).string_value (); | 2226 std::string sup_class = args(i).string_value ("inferiorto: expecting argument to be class name"); |
2237 if (error_state) | |
2238 { | |
2239 error ("inferiorto: expecting argument to be class name"); | |
2240 break; | |
2241 } | |
2242 | 2227 |
2243 if (is_built_in_class (sup_class)) | 2228 if (is_built_in_class (sup_class)) |
2244 { | 2229 { |
2245 error ("inferiorto: cannot give user-defined class lower " | 2230 error ("inferiorto: cannot give user-defined class lower " |
2246 "precedence than built-in class"); | 2231 "precedence than built-in class"); |