AERA
base.cpp
1 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
2 //_/_/
3 //_/_/ HUMANOBS - CoreLibrary
4 //_/_///_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
5 //_/_/
6 //_/_/ AERA
7 //_/_/ Autocatalytic Endogenous Reflective Architecture
8 //_/_/
9 //_/_/ Copyright (c) 2018-2021 Jeff Thompson
10 //_/_/ Copyright (c) 2018-2021 Kristinn R. Thorisson
11 //_/_/ Copyright (c) 2018-2021 Icelandic Institute for Intelligent Machines
12 //_/_/ http://www.iiim.is
13 //_/_/
14 //_/_/ Copyright (c) 2010-2012 Eric Nivel, Thor List
15 //_/_/ Center for Analysis and Design of Intelligent Agents
16 //_/_/ Reykjavik University, Menntavegur 1, 102 Reykjavik, Iceland
17 //_/_/ http://cadia.ru.is
18 //_/_/
19 //_/_/ Part of this software was developed by Eric Nivel
20 //_/_/ in the HUMANOBS EU research project, which included
21 //_/_/ the following parties:
22 //_/_/
23 //_/_/ Autonomous Systems Laboratory
24 //_/_/ Technical University of Madrid, Spain
25 //_/_/ http://www.aslab.org/
26 //_/_/
27 //_/_/ Communicative Machines
28 //_/_/ Edinburgh, United Kingdom
29 //_/_/ http://www.cmlabs.com/
30 //_/_/
31 //_/_/ Istituto Dalle Molle di Studi sull'Intelligenza Artificiale
32 //_/_/ University of Lugano and SUPSI, Switzerland
33 //_/_/ http://www.idsia.ch/
34 //_/_/
35 //_/_/ Institute of Cognitive Sciences and Technologies
36 //_/_/ Consiglio Nazionale delle Ricerche, Italy
37 //_/_/ http://www.istc.cnr.it/
38 //_/_/
39 //_/_/ Dipartimento di Ingegneria Informatica
40 //_/_/ University of Palermo, Italy
41 //_/_/ http://diid.unipa.it/roboticslab/
42 //_/_/
43 //_/_/
44 //_/_/ --- HUMANOBS Open-Source BSD License, with CADIA Clause v 1.0 ---
45 //_/_/
46 //_/_/ Redistribution and use in source and binary forms, with or without
47 //_/_/ modification, is permitted provided that the following conditions
48 //_/_/ are met:
49 //_/_/ - Redistributions of source code must retain the above copyright
50 //_/_/ and collaboration notice, this list of conditions and the
51 //_/_/ following disclaimer.
52 //_/_/ - Redistributions in binary form must reproduce the above copyright
53 //_/_/ notice, this list of conditions and the following disclaimer
54 //_/_/ in the documentation and/or other materials provided with
55 //_/_/ the distribution.
56 //_/_/
57 //_/_/ - Neither the name of its copyright holders nor the names of its
58 //_/_/ contributors may be used to endorse or promote products
59 //_/_/ derived from this software without specific prior
60 //_/_/ written permission.
61 //_/_/
62 //_/_/ - CADIA Clause: The license granted in and to the software
63 //_/_/ under this agreement is a limited-use license.
64 //_/_/ The software may not be used in furtherance of:
65 //_/_/ (i) intentionally causing bodily injury or severe emotional
66 //_/_/ distress to any person;
67 //_/_/ (ii) invading the personal privacy or violating the human
68 //_/_/ rights of any person; or
69 //_/_/ (iii) committing or preparing for any act of war.
70 //_/_/
71 //_/_/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
72 //_/_/ CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
73 //_/_/ INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
74 //_/_/ MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
75 //_/_/ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
76 //_/_/ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
77 //_/_/ SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
78 //_/_/ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
79 //_/_/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
80 //_/_/ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
81 //_/_/ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
82 //_/_/ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
83 //_/_/ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
84 //_/_/ OF SUCH DAMAGE.
85 //_/_/
86 //_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
87 
88 #include <memory>
89 #include "base.h"
90 #include "utils.h"
91 
92 
93 namespace core {
94 
95 #ifdef WITH_DETAIL_OID
96 // Start with a non-zero value so that it doesn't appear to track object OIDs.
97 static uint64 last_detail_oid = 10;
98 #endif
99 
100 _Object::_Object() : refCount_(0) {
101 #ifdef WITH_DETAIL_OID
102  detail_oid_ = ++last_detail_oid;
103  if (detail_oid_ == 0)
104  int set_breakpoint_here = 1;
105 #endif
106 }
107 
108 _Object::~_Object() {
109 }
110 
111 #ifdef WITH_DETAIL_OID
112 void _Object::set_detail_oid(uint64 detail_oid) {
113  detail_oid_ = detail_oid;
114  // Make sure the next assigned detail OID is higher.
115  last_detail_oid = detail_oid;
116 }
117 #endif
118 
119 void _Object::incRef() {
120 
121  Atomic::Increment32(&refCount_);
122 }
123 
124 void _Object::decRef() {
125 
126  if (Atomic::Decrement32(&refCount_) == 0)
127  delete this;
128 }
129 }