GNU Octave  6.2.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-2021 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 
41 namespace octave
42 {
43  class
45  {
46  friend class cdef_class;
47 
48  private:
49 
50  class
52  {
53  public:
54 
56 
57  cdef_property_rep& operator = (const cdef_property_rep& p) = delete;
58 
59  ~cdef_property_rep (void) = default;
60 
61  cdef_object_rep * copy (void) const
62  {
63  return new cdef_property_rep (*this);
64  }
65 
66  bool is_property (void) const { return true; }
67 
68  std::string get_name (void) const { return get("Name").string_value (); }
69 
70  void set_name (const std::string& nm) { put ("Name", nm); }
71 
72  bool is_constant (void) const { return get("Constant").bool_value (); }
73 
74  octave_value get_value (bool do_check_access = true,
75  const std::string& who = "") const;
76 
77  octave_value get_value (const cdef_object& obj,
78  bool do_check_access = true,
79  const std::string& who = "") const;
80 
81  void set_value (cdef_object& obj, const octave_value& val,
82  bool do_check_access = true,
83  const std::string& who = "");
84 
85  bool check_get_access (void) const;
86 
87  bool check_set_access (void) const;
88 
89  private:
92  { }
93 
94  bool is_recursive_set (const cdef_object& obj) const;
95 
97  {
98  m_count++;
99  return cdef_property (this);
100  }
101 
102  OCTAVE_NORETURN
103  void err_property_access (const std::string& from,
104  bool is_set = false) const;
105  };
106 
107  public:
108 
110 
111  cdef_property (const std::string& nm)
113  {
114  get_rep ()->set_name (nm);
115  }
116 
117  cdef_property (const cdef_property& prop) : cdef_meta_object (prop) { }
118 
120  : cdef_meta_object (obj)
121  {
122  // This should never happen...
123  if (! is_property ())
124  error ("internal error: invalid assignment from %s to meta.property object",
125  class_name ().c_str ());
126  }
127 
128  cdef_property& operator = (const cdef_property& prop)
129  {
131 
132  return *this;
133  }
134 
135  ~cdef_property (void) = default;
136 
137  octave_value get_value (const cdef_object& obj, bool do_check_access = true,
138  const std::string& who = "") const
139  {
140  return get_rep ()->get_value (obj, do_check_access, who);
141  }
142 
143  octave_value get_value (bool do_check_access = true,
144  const std::string& who = "") const
145  {
146  return get_rep ()->get_value (do_check_access, who);
147  }
148 
149  void set_value (cdef_object& obj, const octave_value& val,
150  bool do_check_access = true,
151  const std::string& who = "")
152  {
153  get_rep ()->set_value (obj, val, do_check_access, who);
154  }
155 
156  bool check_get_access (void) const
157  {
158  return get_rep ()->check_get_access ();
159  }
160 
161  bool check_set_access (void) const
162  {
163  return get_rep ()->check_set_access ();
164  }
165 
166  std::string get_name (void) const { return get_rep ()->get_name (); }
167 
168  bool is_constant (void) const { return get_rep ()->is_constant (); }
169 
170  private:
171 
173  {
174  return dynamic_cast<cdef_property_rep *> (cdef_object::get_rep ());
175  }
176 
177  const cdef_property_rep * get_rep (void) const
178  {
179  return dynamic_cast<const cdef_property_rep *> (cdef_object::get_rep ());
180  }
181  };
182 }
183 
184 #endif
cdef_object & operator=(const cdef_object &obj)
Definition: cdef-object.h:211
const cdef_object_rep * get_rep(void) const
Definition: cdef-object.h:298
cdef_property_rep(const cdef_property_rep &p)
Definition: cdef-property.h:90
cdef_object_rep * copy(void) const
Definition: cdef-property.h:61
void set_name(const std::string &nm)
Definition: cdef-property.h:70
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)
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
const cdef_property_rep * get_rep(void) const
cdef_property(const cdef_property &prop)
bool check_set_access(void) const
~cdef_property(void)=default
cdef_property(const cdef_object &obj)
cdef_property_rep * get_rep(void)
std::string get_name(void) const
void error(const char *fmt,...)
Definition: error.cc:968