Mercurial > hg > what-is-octave
comparison FEMTEC2013/examples/myobject.cc @ 6:60233b0075a9
femtec presentation
author | Carlo de Falco <cdf@users.sourceforge.net> |
---|---|
date | Sun, 23 Jun 2013 23:37:41 +0200 |
parents | PoliMI2012/examples/myobject.cc@0a1567794b40 |
children |
comparison
equal
deleted
inserted
replaced
5:f8c352d9af2d | 6:60233b0075a9 |
---|---|
1 // Copyright (C) 2012 Carlo de Falco <carlo.defalco@gmail.com> | |
2 // | |
3 // This program is free software; you can redistribute it and/or modify it under | |
4 // the terms of the GNU General Public License as published by the Free Software | |
5 // Foundation; either version 3 of the License, or (at your option) any later | |
6 // version. | |
7 // | |
8 // This program is distributed in the hope that it will be useful, but WITHOUT | |
9 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
10 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | |
11 // details. | |
12 // | |
13 // You should have received a copy of the GNU General Public License along with | |
14 // this program; if not, see <http://www.gnu.org/licenses/>. | |
15 | |
16 #include <octave/oct.h> | |
17 #include <myobject.h> | |
18 | |
19 void load_myobject_type () | |
20 { | |
21 myobject::register_type (); | |
22 myobject_type_loaded = true; | |
23 mlock (); | |
24 std::cout << "myobject_type_loaded" << std::endl; | |
25 } | |
26 | |
27 const std::string & myobject::get_str () const | |
28 { return str; } | |
29 | |
30 | |
31 void myobject::set_str (std::string & _str) | |
32 { str = _str; } | |
33 | |
34 | |
35 // PKG_ADD: autoload ("myobject_get_str", "myobject.oct"); | |
36 DEFUN_DLD (myobject_get_str, args, , | |
37 "get the str field") | |
38 { | |
39 octave_value retval; | |
40 octave_idx_type nargin = args.length (); | |
41 if (nargin < 1 || nargin > 1) | |
42 print_usage (); | |
43 else | |
44 { | |
45 | |
46 if (! myobject_type_loaded) | |
47 load_myobject_type (); | |
48 | |
49 if (args(0).type_id () == myobject::static_type_id ()) | |
50 { | |
51 const myobject & mo = static_cast<const myobject&> (args(0).get_rep ()); | |
52 retval = octave_value (mo.get_str ()); | |
53 } | |
54 } | |
55 return retval; | |
56 } | |
57 | |
58 // PKG_ADD: autoload ("myobject_init", "myobject.oct"); | |
59 DEFUN_DLD (myobject_init, args, , "initialize a myobject") | |
60 { | |
61 octave_value retval = 0; | |
62 | |
63 octave_idx_type nargin = args.length (); | |
64 if (nargin != 3) | |
65 print_usage (); | |
66 else | |
67 { | |
68 if (! myobject_type_loaded) | |
69 load_myobject_type (); | |
70 | |
71 std::string str = args(0).string_value (); | |
72 int i = args(1).int_value (); | |
73 double dbl = args(2).double_value (); | |
74 | |
75 if (!error_state) | |
76 { | |
77 retval = new myobject (str, i, dbl); | |
78 } | |
79 } | |
80 return retval; | |
81 } | |
82 | |
83 | |
84 // PKG_ADD: autoload ("myobject_set_str", "myobject.oct"); | |
85 DEFUN_DLD (myobject_set_str, args, nargout, | |
86 "set the str field") | |
87 { | |
88 octave_value retval; | |
89 octave_idx_type nargin = args.length (); | |
90 if (nargin < 2 || nargin > 2) | |
91 print_usage (); | |
92 else | |
93 { | |
94 | |
95 if (! myobject_type_loaded) | |
96 load_myobject_type (); | |
97 | |
98 std::string str = args(1).string_value (); | |
99 if (args(0).type_id () == myobject::static_type_id ()) | |
100 { | |
101 const myobject mo (static_cast<const myobject&> (args(0).get_rep ())); | |
102 *(mo.p_str) = str; | |
103 } | |
104 } | |
105 return retval; | |
106 } |