AERA
All Classes Functions Pages
view.inline.cpp
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2025 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2025 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2025 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel
12 //_/_/ Center for Analysis and Design of Intelligent Agents
13 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
14 //_/_/ http://cadia.ru.is
15 //_/_/
16 //_/_/ Part of this software was developed by Eric Nivel
17 //_/_/ in the HUMANOBS EU research project, which included
18 //_/_/ the following parties:
19 //_/_/
20 //_/_/ Autonomous Systems Laboratory
21 //_/_/ Technical University of Madrid, Spain
22 //_/_/ http://www.aslab.org/
23 //_/_/
24 //_/_/ Communicative Machines
25 //_/_/ Edinburgh, United Kingdom
26 //_/_/ http://www.cmlabs.com/
27 //_/_/
28 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
29 //_/_/ University of Lugano and SUPSI, Switzerland
30 //_/_/ http://www.idsia.ch/
31 //_/_/
32 //_/_/ Institute of Cognitive Sciences and Technologies
33 //_/_/ Consiglio Nazionale delle Ricerche, Italy
34 //_/_/ http://www.istc.cnr.it/
35 //_/_/
36 //_/_/ Dipartimento di Ingegneria Informatica
37 //_/_/ University of Palermo, Italy
38 //_/_/ http://diid.unipa.it/roboticslab/
39 //_/_/
40 //_/_/
41 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
42 //_/_/
43 //_/_/ Redistribution and use in source and binary forms, with or without
44 //_/_/ modification, is permitted provided that the following conditions
45 //_/_/ are met:
46 //_/_/ - Redistributions of source code must retain the above copyright
47 //_/_/ and collaboration notice, this list of conditions and the
48 //_/_/ following disclaimer.
49 //_/_/ - Redistributions in binary form must reproduce the above copyright
50 //_/_/ notice, this list of conditions and the following disclaimer
51 //_/_/ in the documentation and/or other materials provided with
52 //_/_/ the distribution.
53 //_/_/
54 //_/_/ - Neither the name of its copyright holders nor the names of its
55 //_/_/ contributors may be used to endorse or promote products
56 //_/_/ derived from this software without specific prior
57 //_/_/ written permission.
58 //_/_/
59 //_/_/ - CADIA Clause: The license granted in and to the software
60 //_/_/ under this agreement is a limited-use license.
61 //_/_/ The software may not be used in furtherance of:
62 //_/_/ (i) intentionally causing bodily injury or severe emotional
63 //_/_/ distress to any person;
64 //_/_/ (ii) invading the personal privacy or violating the human
65 //_/_/ rights of any person; or
66 //_/_/ (iii) committing or preparing for any act of war.
67 //_/_/
68 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
69 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
70 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
71 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
73 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
75 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
76 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
77 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
78 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
79 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
80 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
81 //_/_/ OF SUCH DAMAGE.
82 //_/_/
83 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
84 
85 #include "../r_code/utils.h"
86 #include "opcodes.h"
87 
88 
89 namespace r_exec {
90 
91 using r_code::Atom;
92 
93 inline View::View() : r_code::_View(), controller_(NULL) {
94 
95  code_[VIEW_OID].atom_ = GetOID();
96  reset_ctrl_values();
97 }
98 
99 inline View::View(r_code::SysView *source, r_code::Code *object) : r_code::_View(source, object), controller_(NULL) {
100 
101  code_[VIEW_OID].atom_ = GetOID();
102  reset();
103 }
104 
105 inline View::View(const View *view, bool new_OID) : r_code::_View(), controller_(NULL) {
106 
107  object_ = view->object_;
108  memcpy(code_, view->code_, VIEW_CODE_MAX_SIZE * sizeof(Atom) + 2 * sizeof(r_code::Code *)); // reference_set is contiguous to code; memcpy in one go.
109  if (new_OID)
110  code_[VIEW_OID].atom_ = GetOID();
111  controller_ = NULL; // deprecated: controller=view->controller;
112  reset();
113 }
114 
115 inline View::View(SyncMode sync,
116  Timestamp ijt,
117  float32 sln,
118  int32 res,
119  r_code::Code *destination,
120  r_code::Code *origin,
121  r_code::Code *object) : r_code::_View(), controller_(NULL) {
122 
123  code(VIEW_OPCODE) = Atom::SSet(Opcodes::View, VIEW_ARITY);
124  init(sync, ijt, sln, res, destination, origin, object);
125 }
126 
127 inline View::View(SyncMode sync,
128  Timestamp ijt,
129  float32 sln,
130  int32 res,
131  r_code::Code *destination,
132  r_code::Code *origin,
133  r_code::Code *object,
134  float32 act) : r_code::_View(), controller_(NULL) {
135 
136  code(VIEW_OPCODE) = Atom::SSet(Opcodes::PgmView, PGM_VIEW_ARITY);
137  init(sync, ijt, sln, res, destination, origin, object);
138  code(VIEW_ACT) = Atom::Float(act);
139 }
140 
141 inline void View::init(SyncMode sync,
142  Timestamp ijt,
143  float32 sln,
144  int32 res,
145  r_code::Code *destination,
146  r_code::Code *origin,
147  r_code::Code *object) {
148 
149  code_[VIEW_OID].atom_ = GetOID();
150  reset_ctrl_values();
151 
152  code(VIEW_SYNC) = Atom::Float((float32)sync);
153  code(VIEW_IJT) = Atom::IPointer(code(VIEW_OPCODE).getAtomCount() + 1);
154  r_code::Utils::SetTimestamp<View>(this, VIEW_IJT, ijt);
155  code(VIEW_SLN) = Atom::Float(sln);
156  code(VIEW_RES) = res < 0 ? Atom::PlusInfinity() : Atom::Float((float32)res);
157  code(VIEW_HOST) = Atom::RPointer(0);
158  code(VIEW_ORG) = origin ? Atom::RPointer(1) : Atom::Nil();
159 
160  references_[0] = destination;
161  references_[1] = origin;
162 
163  set_object(object);
164 }
165 
166 inline void View::reset() {
167 
168  reset_ctrl_values();
169  reset_init_sln();
170  reset_init_act();
171 }
172 
173 inline uint32 View::get_oid() const {
174 
175  return code_[VIEW_OID].atom_;
176 }
177 
178 inline bool View::is_notification() const {
179 
180  return false;
181 }
182 
183 inline Group *View::get_host() {
184 
185  uint32 host_reference = code(VIEW_HOST).asIndex();
186  return (Group *)references_[host_reference];
187 }
188 
189 inline View::SyncMode View::get_sync() {
190 
191  return (SyncMode)(uint32)code(VIEW_SYNC).asFloat();
192 }
193 
194 inline float32 View::get_res() {
195 
196  return code(VIEW_RES).asFloat();
197 }
198 
199 inline float32 View::get_sln() {
200 
201  return code(VIEW_SLN).asFloat();
202 }
203 
204 inline float32 View::get_act() {
205 
206  return code(VIEW_ACT).asFloat();
207 }
208 
209 inline float32 View::get_vis() {
210 
211  return code(GRP_VIEW_VIS).asFloat();
212 }
213 
214 inline bool View::get_cov() {
215 
216  if (object_->code(0).getDescriptor() == Atom::GROUP)
217  return code(GRP_VIEW_COV).asBoolean();
218  return false;
219 }
220 
221 inline void View::mod_res(float32 value) {
222 
223  if (code(VIEW_RES) == Atom::PlusInfinity())
224  return;
225  acc_res_ += value;
226  ++res_changes_;
227 }
228 
229 inline void View::set_res(float32 value) {
230 
231  if (code(VIEW_RES) == Atom::PlusInfinity())
232  return;
233  acc_res_ += value - get_res();
234  ++res_changes_;
235 }
236 
237 inline void View::mod_sln(float32 value) {
238 
239  acc_sln_ += value;
240  ++sln_changes_;
241 }
242 
243 inline void View::set_sln(float32 value) {
244 
245  acc_sln_ += value - get_sln();
246  ++sln_changes_;
247 }
248 
249 inline void View::mod_act(float32 value) {
250 
251  acc_act_ += value;
252  ++act_changes_;
253 }
254 
255 inline void View::set_act(float32 value) {
256 
257  acc_act_ += value - get_act();
258  ++act_changes_;
259 }
260 
261 inline void View::mod_vis(float32 value) {
262 
263  acc_vis_ += value;
264  ++vis_changes_;
265 }
266 
267 inline void View::set_vis(float32 value) {
268 
269  acc_vis_ += value - get_vis();
270  ++vis_changes_;
271 }
272 
273 inline float32 View::update_sln_delta() {
274 
275  float32 delta = get_sln() - initial_sln_;
276  initial_sln_ = get_sln();
277  return delta;
278 }
279 
280 inline float32 View::update_act_delta() {
281 
282  float32 act = get_act();
283  float32 delta = act - initial_act_;
284  initial_act_ = act;
285  return delta;
286 }
287 
288 inline void View::force_res(float32 value) {
289 
290  code(VIEW_RES) = Atom::Float(value);
291 }
292 
293 inline void View::mod(uint16 member_index, float32 value) {
294 
295  switch (member_index) {
296  case VIEW_SLN:
297  mod_sln(value);
298  break;
299  case VIEW_RES:
300  mod_res(value);
301  break;
302  case VIEW_ACT:
303  mod_act(value);
304  break;
305  case GRP_VIEW_VIS:
306  mod_vis(value);
307  break;
308  }
309 }
310 
311 inline void View::set(uint16 member_index, float32 value) {
312 
313  switch (member_index) {
314  case VIEW_SLN:
315  set_sln(value);
316  break;
317  case VIEW_RES:
318  set_res(value);
319  break;
320  case VIEW_ACT:
321  set_act(value);
322  break;
323  case GRP_VIEW_VIS:
324  set_vis(value);
325  break;
326  }
327 }
328 
330 
331 inline bool NotificationView::is_notification() const {
332 
333  return true;
334 }
335 }
r_code::Atom
Definition: atom.h:104
r_code::SysView
Definition: r_code/object.h:119
r_code::Code
Definition: r_code/object.h:224