AERA
base.h
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ AERA
4 //_/_/ Autocatalytic Endogenous Reflective Architecture
5 //_/_/
6 //_/_/ Copyright (c) 2018-2021 Jeff Thompson
7 //_/_/ Copyright (c) 2018-2021 Kristinn R. Thorisson
8 //_/_/ Copyright (c) 2018-2021 Icelandic Institute for Intelligent Machines
9 //_/_/ http://www.iiim.is
10 //_/_/
11 //_/_/ Copyright (c) 2010-2012 Eric Nivel, Thor List
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 #ifndef core_base_h
86 #define core_base_h
87 
88 //#define WITH_DETAIL_OID // Enable get_detail_oid() in every object.
89 
90 #include <cstdlib>
91 
92 #include "types.h"
93 
94 namespace core {
95 
96 class _Object;
97 
98 // Smart pointer (ref counting, deallocates when ref count<=0).
99 // No circular refs (use std c++ ptrs).
100 // No passing in functions (cast P<C> into C*).
101 // Cannot be a value returned by a function (return C* instead).
102 template<class C> class P {
103 private:
104  _Object *object_;
105 public:
106  P();
107  P(C *o);
108  P(const P<C> &p);
109  ~P();
110  C *operator ->() const;
111  template<class D> operator D *() const {
112 
113  return static_cast<D *>((C *)object_);
114  }
115  bool operator ==(C *c) const;
116  bool operator !=(C *c) const;
117  bool operator !() const;
118  bool operator <(P<C> &p) const { return (size_t)object_ < (size_t)p.object_; }
119  bool operator <(const P<C> &p) const { return (size_t)object_ < (size_t)p.object_; }
120  template<class D> bool operator ==(P<D> &p) const;
121  template<class D> bool operator !=(P<D> &p) const;
122  P<C> &operator =(C *c);
123  P<C> &operator =(const P<C> &p);
124  template<class D> P<C> &operator =(const P<D> &p);
125 };
126 
128 
129 // Root smart-pointable object class.
130 class core_dll _Object {
131  template<class C> friend class P;
132  friend class _P;
133 protected:
134 #ifdef ARCH_32
135  uint32 __vfptr_padding_Object_;
136 #endif
137  int32 volatile refCount_;
138  _Object();
139 #ifdef WITH_DETAIL_OID
140  uint64 detail_oid_;
141 #endif
142 public:
143  virtual ~_Object();
144  void incRef();
145  virtual void decRef();
146 #ifdef WITH_DETAIL_OID
147  uint64 get_detail_oid() const { return detail_oid_; }
148 
154  void set_detail_oid(uint64 detail_oid);
155 #endif
156 };
157 
158 // Template version of the well-known DP. Adapts C to _Object.
159 template<class C> class _ObjectAdapter :
160  public C,
161  public _Object {
162 protected:
163  _ObjectAdapter();
164 };
165 }
166 
167 
168 #include "base.tpl.cpp"
169 
170 
171 #endif
core::P
Definition: base.h:102
core::_Object
Definition: base.h:130
core::_ObjectAdapter
Definition: base.h:161