GNU Octave 10.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
cdef-property.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2025 The Octave Project Developers
4//
5// See the file COPYRIGHT.md in the top-level directory of this
6// distribution or <https://octave.org/copyright/>.
7//
8// This file is part of Octave.
9//
10// Octave is free software: you can redistribute it and/or modify it
11// under the terms of the GNU General Public License as published by
12// the Free Software Foundation, either version 3 of the License, or
13// (at your option) any later version.
14//
15// Octave is distributed in the hope that it will be useful, but
16// WITHOUT ANY WARRANTY; without even the implied warranty of
17// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18// GNU General Public License for more details.
19//
20// You should have received a copy of the GNU General Public License
21// along with Octave; see the file COPYING. If not, see
22// <https://www.gnu.org/licenses/>.
23//
24////////////////////////////////////////////////////////////////////////
25
26#if ! defined (octave_cdef_property_h)
27#define octave_cdef_property_h 1
28
29#include "octave-config.h"
30
31#include <map>
32#include <set>
33#include <string>
34
35#include "oct-refcount.h"
36
37#include "cdef-object.h"
38#include "error.h"
39#include "ov.h"
40
42
43class OCTINTERP_API cdef_property : public cdef_meta_object
44{
45 friend class cdef_class;
46
47private:
48
49 class cdef_property_rep : public cdef_meta_object_rep
50 {
51 public:
52
53 cdef_property_rep () : cdef_meta_object_rep () { }
54
55 cdef_property_rep& operator = (const cdef_property_rep& p) = delete;
56
57 ~cdef_property_rep () = default;
58
59 cdef_object_rep * copy () const
60 {
61 return new cdef_property_rep (*this);
62 }
63
64 bool is_property () const { return true; }
65
66 std::string get_name () const { return get("Name").string_value (); }
67
68 void set_name (const std::string& nm) { put ("Name", nm); }
69
70 bool is_constant () const { return get("Constant").bool_value (); }
71
72 octave_value get_value (bool do_check_access = true,
73 const std::string& who = "") const;
74
75 octave_value get_value (const cdef_object& obj,
76 bool do_check_access = true,
77 const std::string& who = "") const;
78
79 void set_value (cdef_object& obj, const octave_value& val,
80 bool do_check_access = true,
81 const std::string& who = "");
82
83 OCTINTERP_API bool check_get_access () const;
84
85 OCTINTERP_API bool check_set_access () const;
86
87 private:
88 cdef_property_rep (const cdef_property_rep& p)
90 { }
91
92 OCTINTERP_API bool is_recursive_set (const cdef_object& obj) const;
93
94 cdef_property wrap ()
95 {
96 m_count++;
97 return cdef_property (this);
98 }
99
100 OCTINTERP_API OCTAVE_NORETURN
101 void err_property_access (const std::string& from,
102 bool is_set = false) const;
103 };
104
105public:
106
108
109 cdef_property (const std::string& nm)
110 : cdef_meta_object (new cdef_property_rep ())
111 {
112 get_rep ()->set_name (nm);
113 }
114
116
118 : cdef_meta_object (obj)
119 {
120 // This should never happen...
121 if (! is_property ())
122 error ("internal error: invalid assignment from %s to meta.property object",
123 class_name ().c_str ());
124 }
125
126 cdef_property& operator = (const cdef_property& prop)
127 {
129
130 return *this;
131 }
132
133 ~cdef_property () = default;
134
135 octave_value get_value (const cdef_object& obj, bool do_check_access = true,
136 const std::string& who = "") const
137 {
138 return get_rep ()->get_value (obj, do_check_access, who);
139 }
140
141 octave_value get_value (bool do_check_access = true,
142 const std::string& who = "") const
143 {
144 return get_rep ()->get_value (do_check_access, who);
145 }
146
147 void set_value (cdef_object& obj, const octave_value& val,
148 bool do_check_access = true,
149 const std::string& who = "")
150 {
151 get_rep ()->set_value (obj, val, do_check_access, who);
152 }
153
154 bool check_get_access () const
155 {
156 return get_rep ()->check_get_access ();
157 }
158
159 bool check_set_access () const
160 {
161 return get_rep ()->check_set_access ();
162 }
163
164 std::string get_name () const { return get_rep ()->get_name (); }
165
166 bool is_constant () const { return get_rep ()->is_constant (); }
167
168private:
169
170 cdef_property_rep * get_rep ()
171 {
172 return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ());
173 }
174
175 const cdef_property_rep * get_rep () const
176 {
177 return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ());
178 }
179};
180
181OCTAVE_END_NAMESPACE(octave)
182
183#endif
cdef_meta_object_rep & operator=(const cdef_meta_object_rep &)=delete
cdef_object & operator=(const cdef_object &obj)
const cdef_object_rep * get_rep() const
octave_value get_value(bool do_check_access=true, const std::string &who="") const
void set_value(cdef_object &obj, const octave_value &val, bool do_check_access=true, const std::string &who="")
std::string get_name() const
bool is_constant() const
cdef_property(const cdef_object &obj)
cdef_property(const cdef_property &prop)
bool check_set_access() const
~cdef_property()=default
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
cdef_property(const std::string &nm)
bool check_get_access() const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition error.cc:1003