GNU Octave  8.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-2023 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 
43 class
44 OCTINTERP_API
46 {
47  friend class cdef_class;
48 
49 private:
50 
51  class
53  {
54  public:
55 
57 
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 
118  cdef_property (const cdef_property& prop) : cdef_meta_object (prop) { }
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 
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 
185 
186 #endif
OCTAVE_END_NAMESPACE(octave)
std::string get_name(void) const
Definition: cdef-class.h:76
void set_name(const std::string &nm)
Definition: cdef-class.h:79
cdef_class_rep * get_rep(void)
Definition: cdef-class.h:420
cdef_class & operator=(const cdef_class &cls)
Definition: cdef-class.h:260
bool is_property(void) const
Definition: cdef-object.h:682
cdef_object & operator=(const cdef_object &obj)
Definition: cdef-object.h:217
void put(const std::string &pname, const octave_value &val)
Definition: cdef-object.h:263
const cdef_object_rep * get_rep(void) const
Definition: cdef-object.h:310
std::string class_name(void) const
Definition: cdef-object.h:234
octave_value get(const std::string &pname) const
Definition: cdef-object.h:268
std::string get_name(void) const
Definition: cdef-property.h:69
cdef_object_rep * copy(void) const
Definition: cdef-property.h:62
cdef_property_rep(const cdef_property_rep &p)
Definition: cdef-property.h:91
void set_name(const std::string &nm)
Definition: cdef-property.h:71
const cdef_property_rep * get_rep(void) 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(void) const
cdef_property(const cdef_object &obj)
cdef_property(const cdef_property &prop)
~cdef_property(void)=default
bool is_constant(void) const
octave_value get_value(const cdef_object &obj, bool do_check_access=true, const std::string &who="") const
bool check_get_access(void) const
cdef_property(const std::string &nm)
bool check_set_access(void) const
cdef_property_rep * get_rep(void)
bool bool_value(bool warn=false) const
Definition: ov.h:930
std::string string_value(bool force=false) const
Definition: ov.h:1019
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
void error(const char *fmt,...)
Definition: error.cc:979