AERA
image.h
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2023 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2023 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2023 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel
12 //_/_/ Copyright (c) 2010 Nathaniel Thurston
13 //_/_/ Center for Analysis and Design of Intelligent Agents
14 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
15 //_/_/ http://cadia.ru.is
16 //_/_/
17 //_/_/ Part of this software was developed by Eric Nivel
18 //_/_/ in the HUMANOBS EU research project, which included
19 //_/_/ the following parties:
20 //_/_/
21 //_/_/ Autonomous Systems Laboratory
22 //_/_/ Technical University of Madrid, Spain
23 //_/_/ http://www.aslab.org/
24 //_/_/
25 //_/_/ Communicative Machines
26 //_/_/ Edinburgh, United Kingdom
27 //_/_/ http://www.cmlabs.com/
28 //_/_/
29 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
30 //_/_/ University of Lugano and SUPSI, Switzerland
31 //_/_/ http://www.idsia.ch/
32 //_/_/
33 //_/_/ Institute of Cognitive Sciences and Technologies
34 //_/_/ Consiglio Nazionale delle Ricerche, Italy
35 //_/_/ http://www.istc.cnr.it/
36 //_/_/
37 //_/_/ Dipartimento di Ingegneria Informatica
38 //_/_/ University of Palermo, Italy
39 //_/_/ http://diid.unipa.it/roboticslab/
40 //_/_/
41 //_/_/
42 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
43 //_/_/
44 //_/_/ Redistribution and use in source and binary forms, with or without
45 //_/_/ modification, is permitted provided that the following conditions
46 //_/_/ are met:
47 //_/_/ - Redistributions of source code must retain the above copyright
48 //_/_/ and collaboration notice, this list of conditions and the
49 //_/_/ following disclaimer.
50 //_/_/ - Redistributions in binary form must reproduce the above copyright
51 //_/_/ notice, this list of conditions and the following disclaimer
52 //_/_/ in the documentation and/or other materials provided with
53 //_/_/ the distribution.
54 //_/_/
55 //_/_/ - Neither the name of its copyright holders nor the names of its
56 //_/_/ contributors may be used to endorse or promote products
57 //_/_/ derived from this software without specific prior
58 //_/_/ written permission.
59 //_/_/
60 //_/_/ - CADIA Clause: The license granted in and to the software
61 //_/_/ under this agreement is a limited-use license.
62 //_/_/ The software may not be used in furtherance of:
63 //_/_/ (i) intentionally causing bodily injury or severe emotional
64 //_/_/ distress to any person;
65 //_/_/ (ii) invading the personal privacy or violating the human
66 //_/_/ rights of any person; or
67 //_/_/ (iii) committing or preparing for any act of war.
68 //_/_/
69 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
70 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
71 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
72 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
73 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
74 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
75 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
76 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
77 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
78 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
79 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
80 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
81 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
82 //_/_/ OF SUCH DAMAGE.
83 //_/_/
84 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
85 
86 #ifndef r_code_image_h
87 #define r_code_image_h
88 
89 #include "../submodules/CoreLibrary/CoreLibrary/types.h"
90 
91 #include <fstream>
92 
93 
94 using namespace core;
95 
96 namespace r_comp {
97 class Image;
98 }
99 
100 namespace r_code {
101 
102 // An image contains the following:
103 // - sizes of what follows
104 // - object map: list of indexes (4 bytes) of objects in the code segment
105 // - code segment: list of objects
106 // - object:
107 // - size of the code (number of atoms)
108 // - size of the reference set (number of pointers)
109 // - size of the marker set (number of pointers)
110 // - size of the view set (number of views)
111 // - code: indexes in internal pointers are relative to the beginning of the object, indexes in reference pointers are relative to the beginning of the reference set
112 // - reference set:
113 // - number of pointers
114 // - pointers to the relocation segment, i.e. indexes of relocation entries
115 // - marker set:
116 // - number of pointers
117 // - pointers to the relocation segment, i.e. indexes of relocation entries
118 // - view set: list of views
119 // - view:
120 // - size of the code (number of atoms)
121 // - size of the reference set (number of pointers)
122 // - list of atoms
123 // - reference set:
124 // - pointers to the relocation segment, i.e. indexes of relocation entries
125 //
126 // RAM layout of Image::data [sizes in word32]:
127 //
128 // data[0]: index of first object in data (i.e. def_size+map_size) [1]
129 // ... ...
130 // data[map_size-1]: index of last object in data [1]
131 // data[map_size]: first word32 of code segment [1]
132 // ... ...
133 // data[map_size+code_size-1]: last word32 of code segment [1]
134 //
135 // I is the implementation class; prototype:
136 // class ImageImpl{
137 // protected:
138 // uin64 get_timestamp() const;
139 // uint32 map_size() const;
140 // uint32 code_size() const;
141 // word32 *data(); // [object map|code segment|reloc segment]
142 // public:
143 // void *operator new(size_t,uint32 data_size);
144 // ImageImpl(uint32 map_size,uint32 code_size);
145 // ~ImageImpl();
146 // };
147 
148 template<class I> class Image :
149  public I {
150  friend class r_comp::Image;
151 public:
152  static Image<I> *Build(Timestamp timestamp, uint32 map_size, uint32 code_size, uint32 names_size);
153  // file IO
154  static Image<I> *Read(std::ifstream &stream);
155  static void Write(Image<I> *image, std::ofstream &stream);
156 
157  Image();
158  ~Image();
159 
160  uint32 get_size() const; // size of data in word32
161  uint32 getObjectCount() const;
162  word32 *get_object(uint32 i); // points to the code size of the object; the first atom is at get_object()+2
163  word32 *getCodeSegment(); // equals get_object(0)
164  uint32 getCodeSegmentSize() const;
165 
166  void trace() const;
167 };
168 
169 // utilities
170 uint32 dll_export GetSize(const std::string &s); // returns the number of word32 needed to encode the string
171 void dll_export Write(word32 *data, const std::string &s);
172 void dll_export Read(word32 *data, std::string &s);
173 }
174 
175 
176 #include "image.tpl.cpp"
177 
178 
179 #endif
r_comp::Image
Definition: segments.h:177
r_code::Image
Definition: image.h:149