AERA
usr_operators.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 "usr_operators.h"
86 
87 #include "../r_exec/init.h"
88 #include "auto_focus_callback.h"
89 
90 #include <iostream>
91 #include <cmath>
92 
93 
94 r_code::resized_vector<uint16> Init(OpcodeRetriever r) {
95 
96  r_code::resized_vector<uint16> val = Operators::Init(r);
97 
98  std::cout << "> usr operators initialized" << std::endl;
99 
100  return val;
101 }
102 
103 uint16 GetOperatorCount() {
104 
105  return 5;
106 }
107 
108 void GetOperatorName(char *op_name) {
109 
110  static uint16 op_index = 0;
111 
112  if (op_index == 0) {
113 
114  std::string s = "add";
115  memcpy(op_name, s.c_str(), s.length());
116  ++op_index;
117  return;
118  }
119 
120  if (op_index == 1) {
121 
122  std::string s = "sub";
123  memcpy(op_name, s.c_str(), s.length());
124  ++op_index;
125  return;
126  }
127 
128  if (op_index == 2) {
129 
130  std::string s = "mul";
131  memcpy(op_name, s.c_str(), s.length());
132  ++op_index;
133  return;
134  }
135 
136  if (op_index == 3) {
137 
138  std::string s = "div";
139  memcpy(op_name, s.c_str(), s.length());
140  ++op_index;
141  return;
142  }
143 
144  if (op_index == 4) {
145 
146  std::string s = "dis";
147  memcpy(op_name, s.c_str(), s.length());
148  ++op_index;
149  return;
150  }
151 }
152 
154 
155 uint16 GetProgramCount() {
156 
157  return 2;
158 }
159 
160 void GetProgramName(char *pgm_name) {
161 
162  static uint16 pgm_index = 0;
163 
164  if (pgm_index == 0) {
165 
166  std::string s = "test_program";
167  memcpy(pgm_name, s.c_str(), s.length());
168  ++pgm_index;
169  return;
170  }
171  /*
172  if(pgm_index==1){
173 
174  std::string s="correlator";
175  memcpy(pgm_name,s.c_str(),s.length());
176  ++pgm_index;
177  return;
178  }
179  */
180  if (pgm_index == 1) {
181 
182  std::string s = "auto_focus";
183  memcpy(pgm_name, s.c_str(), s.length());
184  ++pgm_index;
185  return;
186  }
187 }
188 
190 
191 uint16 GetCallbackCount() {
192 
193  return 1;
194 }
195 
196 void GetCallbackName(char *callback_name) {
197 
198  static uint16 callback_index = 0;
199 
200  if (callback_index == 0) {
201 
202  std::string s = "print";
203  memcpy(callback_name, s.c_str(), s.length());
204  ++callback_index;
205  return;
206  }
207 }
208 
209 void* GetUserOperatorFunction(const char* function_name) {
210  if (strcmp(function_name, "Init") == 0)
211  return (void*)&Init;
212  else if (strcmp(function_name, "GetOperatorCount") == 0)
213  return (void*)&GetOperatorCount;
214  else if (strcmp(function_name, "GetOperatorName") == 0)
215  return (void*)&GetOperatorName;
216  else if (strcmp(function_name, "add") == 0)
217  return (void*)&usr_operators::add;
218  else if (strcmp(function_name, "sub") == 0)
219  return (void*)&usr_operators::sub;
220  else if (strcmp(function_name, "mul") == 0)
221  return (void*)&usr_operators::mul;
222  else if (strcmp(function_name, "div") == 0)
223  return (void*)&usr_operators::div;
224  else if (strcmp(function_name, "dis") == 0)
225  return (void*)&usr_operators::dis;
226  else if (strcmp(function_name, "GetProgramCount") == 0)
227  return (void*)&GetProgramCount;
228  else if (strcmp(function_name, "GetProgramName") == 0)
229  return (void*)&GetProgramName;
230  else if (strcmp(function_name, "test_program") == 0)
231  return (void*)&test_program;
232  else if (strcmp(function_name, "auto_focus") == 0)
233  return (void*)&auto_focus;
234  else if (strcmp(function_name, "GetCallbackCount") == 0)
235  return (void*)&GetCallbackCount;
236  else if (strcmp(function_name, "GetCallbackName") == 0)
237  return (void*)&GetCallbackName;
238  else if (strcmp(function_name, "print") == 0)
239  return (void*)&usr_operators::print;
240  else
241  return NULL;
242 }
r_code::resized_vector< uint16 >