comparison src/function.h @ 268:61830a4f9ab9

Improve formatting
author Eugenio Gianniti <eugenio.gianniti@mail.polimi.it>
date Thu, 14 Aug 2014 12:26:55 +0200
parents 5e9b5bbdc56b
children
comparison
equal deleted inserted replaced
267:53039ac90368 268:61830a4f9ab9
26 #include "dolfin_compat.h" 26 #include "dolfin_compat.h"
27 27
28 class function : public octave_base_value 28 class function : public octave_base_value
29 { 29 {
30 30
31 public: 31 public:
32 32
33 function () 33 function ()
34 : octave_base_value (), fun () {} 34 : octave_base_value (), fun () {}
35 35
36 function (std::string & _str, 36 function (std::string & _str,
37 SHARED_PTR <const dolfin::Function> _fun) 37 SHARED_PTR <const dolfin::Function> _fun)
38 : octave_base_value (), str(_str), fun (_fun) {} 38 : octave_base_value (), str (_str), fun (_fun) {}
39 39
40 function (function const& _func) 40 function (function const & _func)
41 : octave_base_value (), str (_func.get_str ()), fun (_func.get_pfun ()) {} 41 : octave_base_value (), str (_func.get_str ()), fun (_func.get_pfun ()) {}
42 42
43 void 43 void
44 print (std::ostream& os, 44 print (std::ostream & os,
45 bool pr_as_read_syntax = false) const 45 bool pr_as_read_syntax = false) const
46 { os << "Function " << str << ": " << fun->str (true) << std::endl; } 46 { os << "Function " << str << ": " << fun->str (true) << std::endl; }
47 47
48 ~function(void) {} 48 ~function (void) {}
49 49
50 bool 50 bool
51 is_defined (void) const 51 is_defined (void) const
52 { return true; } 52 { return true; }
53 53
54 const dolfin::Function & 54 const dolfin::Function &
55 get_fun (void) const 55 get_fun (void) const
56 { return (*fun); } 56 { return (*fun); }
57 57
58 const SHARED_PTR <const dolfin::Function> & 58 const SHARED_PTR <const dolfin::Function> &
59 get_pfun (void) const 59 get_pfun (void) const
60 { return fun; } 60 { return fun; }
61 61
62 void 62 void
63 set_fun (dolfin::Function & _fun) 63 set_fun (dolfin::Function & _fun)
64 { 64 {
65 dolfin::Function * p = new dolfin::Function (_fun); 65 dolfin::Function * p = new dolfin::Function (_fun);
66 fun = SHARED_PTR <const dolfin::Function> (p); 66 fun = SHARED_PTR <const dolfin::Function> (p);
67 } 67 }
68 68
69 const std::string & 69 const std::string &
70 get_str (void) const 70 get_str (void) const
71 { return str; } 71 { return str; }
72 72
73 octave_value 73 octave_value
74 subsref (const std::string& type, 74 subsref (const std::string & type,
75 const std::list<octave_value_list>& idx) 75 const std::list<octave_value_list> & idx)
76 { 76 {
77 octave_value retval; 77 octave_value retval;
78 retval = subsref (type, idx, 1); 78 retval = subsref (type, idx, 1);
79 return retval; 79 return retval;
80 } 80 }
81 81
82 octave_value_list 82 octave_value_list
83 subsref (const std::string& type, 83 subsref (const std::string & type,
84 const std::list<octave_value_list>& idx, 84 const std::list<octave_value_list> & idx,
85 int nargout) 85 int nargout)
86 { 86 {
87 octave_value_list retval; 87 octave_value_list retval;
88 88
89 switch (type[0]) 89 switch (type[0])
90 {
91 case '(':
90 { 92 {
91 case '(': 93 retval = do_multi_index_op (nargout, idx.front ());
92 { 94 }
93 retval = do_multi_index_op (nargout, idx.front ()); 95 break;
94 }
95 break;
96 96
97 case '{': 97 case '{':
98 case '.': 98 case '.':
99 { 99 {
100 std::string nm = type_name (); 100 std::string nm = type_name ();
101 error ("%s cannot be indexed with %c", nm.c_str (), type[0]); 101 error ("%s cannot be indexed with %c", nm.c_str (), type[0]);
102 } 102 }
103 break; 103 break;
104 104
105 default: 105 default:
106 panic_impossible (); 106 { panic_impossible (); }
107 } 107 }
108 108
109 return retval; 109 return retval;
110 } 110 }
111 111
112 octave_value_list 112 octave_value_list
113 do_multi_index_op (int nargout, const octave_value_list& idx) 113 do_multi_index_op (int nargout, const octave_value_list & idx)
114 { 114 {
115 octave_value_list retval; 115 octave_value_list retval;
116 std::list<octave_value_list> args (1, idx); 116 std::list<octave_value_list> args (1, idx);
117 args.push_front (octave_value (new function (*this))); 117 args.push_front (octave_value (new function (*this)));
118 retval = feval ("feval", args, nargout); 118 retval = feval ("feval", args, nargout);
119 return retval; 119 return retval;
120 } 120 }
121 121
122 private: 122 private:
123 123
124 std::string str; 124 std::string str;
125 SHARED_PTR <const dolfin::Function> fun; 125 SHARED_PTR <const dolfin::Function> fun;
126 126
127 DECLARE_OCTAVE_ALLOCATOR; 127 DECLARE_OCTAVE_ALLOCATOR;