GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
cdef-property.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 2012-2022 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
41namespace octave
42{
43 class
44 OCTINTERP_API
46 {
47 friend class cdef_class;
48
49 private:
50
51 class
53 {
54 public:
55
57
58 cdef_property_rep& operator = (const cdef_property_rep& p) = delete;
59
60 ~cdef_property_rep (void) = default;
61
62 cdef_object_rep * copy (void) const
63 {
64 return new cdef_property_rep (*this);
65 }
66
67 bool is_property (void) const { return true; }
68
69 std::string get_name (void) const { return get("Name").string_value (); }
70
71 void set_name (const std::string& nm) { put ("Name", nm); }
72
73 bool is_constant (void) const { return get("Constant").bool_value (); }
74
75 octave_value get_value (bool do_check_access = true,
76 const std::string& who = "") const;
77
78 octave_value get_value (const cdef_object& obj,
79 bool do_check_access = true,
80 const std::string& who = "") const;
81
82 void set_value (cdef_object& obj, const octave_value& val,
83 bool do_check_access = true,
84 const std::string& who = "");
85
86 OCTINTERP_API bool check_get_access (void) const;
87
88 OCTINTERP_API bool check_set_access (void) const;
89
90 private:
93 { }
94
95 OCTINTERP_API bool is_recursive_set (const cdef_object& obj) const;
96
98 {
99 m_count++;
100 return cdef_property (this);
101 }
102
103 OCTINTERP_API OCTAVE_NORETURN
104 void err_property_access (const std::string& from,
105 bool is_set = false) const;
106 };
107
108 public:
109
111
112 cdef_property (const std::string& nm)
114 {
115 get_rep ()->set_name (nm);
116 }
117
119
121 : cdef_meta_object (obj)
122 {
123 // This should never happen...
124 if (! is_property ())
125 error ("internal error: invalid assignment from %s to meta.property object",
126 class_name ().c_str ());
127 }
128
129 cdef_property& operator = (const cdef_property& prop)
130 {
132
133 return *this;
134 }
135
136 ~cdef_property (void) = default;
137
138 octave_value get_value (const cdef_object& obj, bool do_check_access = true,
139 const std::string& who = "") const
140 {
141 return get_rep ()->get_value (obj, do_check_access, who);
142 }
143
144 octave_value get_value (bool do_check_access = true,
145 const std::string& who = "") const
146 {
147 return get_rep ()->get_value (do_check_access, who);
148 }
149
150 void set_value (cdef_object& obj, const octave_value& val,
151 bool do_check_access = true,
152 const std::string& who = "")
153 {
154 get_rep ()->set_value (obj, val, do_check_access, who);
155 }
156
157 bool check_get_access (void) const
158 {
159 return get_rep ()->check_get_access ();
160 }
161
162 bool check_set_access (void) const
163 {
164 return get_rep ()->check_set_access ();
165 }
166
167 std::string get_name (void) const { return get_rep ()->get_name (); }
168
169 bool is_constant (void) const { return get_rep ()->is_constant (); }
170
171 private:
172
174 {
175 return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ());
176 }
177
178 const cdef_property_rep * get_rep (void) const
179 {
180 return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ());
181 }
182 };
183}
184
185#endif
cdef_object & operator=(const cdef_object &obj)
Definition: cdef-object.h:216
const cdef_object_rep * get_rep(void) const
Definition: cdef-object.h:308
cdef_property_rep(const cdef_property_rep &p)
Definition: cdef-property.h:91
cdef_object_rep * copy(void) const
Definition: cdef-property.h:62
void set_name(const std::string &nm)
Definition: cdef-property.h:71
bool check_get_access(void) const
void set_value(cdef_object &obj, const octave_value &val, bool do_check_access=true, const std::string &who="")
cdef_property(const std::string &nm)
cdef_property_rep * get_rep(void)
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
octave_value get_value(bool do_check_access=true, const std::string &who="") const
bool is_constant(void) const
cdef_property(const cdef_property &prop)
bool check_set_access(void) const
~cdef_property(void)=default
cdef_property(const cdef_object &obj)
const cdef_property_rep * get_rep(void) const
std::string get_name(void) const
void error(const char *fmt,...)
Definition: error.cc:980