00001 // 00002 // File: src/object.cpp 00003 // Object: Implementation of the base object 00004 // Project: http://www.m2osw.com/odbcpp 00005 // Author: alexis_wilke@sourceforge.net 00006 // 00007 // Copyright (C) 2008 Made to Order Software Corp. 00008 // 00009 // This program is free software: you can redistribute it and/or modify 00010 // it under the terms of the GNU General Public License as published by 00011 // the Free Software Foundation, either version 3 of the License, or 00012 // (at your option) any later version. 00013 // 00014 // This program is distributed in the hope that it will be useful, 00015 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00016 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00017 // GNU General Public License for more details. 00018 // 00019 // You should have received a copy of the GNU General Public License 00020 // along with this program. If not, see <http://www.gnu.org/licenses/> 00021 // or <http://gpl3.m2osw.com/>. 00022 // 00023 00024 #include "odbcpp/object.h" 00025 #include <stdlib.h> 00026 #include <iostream> 00027 00028 00029 namespace odbcpp 00030 { 00031 00032 00072 object::object() : 00073 f_refcount(1) 00074 { 00075 } 00076 00077 00085 object::object(const object& obj) : 00086 f_refcount(1) 00087 { 00088 // avoid some warnings 00089 (void) &obj; 00090 } 00091 00092 00103 object::~object() 00104 { 00105 if(f_refcount != 0 && f_refcount != 1) { 00106 // TODO: should be a throw I think 00107 std::cerr << "object at " << this << " has a refcount of " << f_refcount << "\n"; 00108 std::terminate(); 00109 } 00110 } 00111 00112 00113 00123 object& object::operator = (const object& obj) 00124 { 00125 // avoid some warnings 00126 (void) &obj; 00127 return *this; 00128 } 00129 00130 00141 unsigned long object::addref() const 00142 { 00143 if(this == 0) { 00144 return 0; 00145 } 00146 00147 return ++f_refcount; 00148 } 00149 00150 00162 unsigned long object::release() const 00163 { 00164 if(this == 0) { 00165 return 0; 00166 } 00167 00168 unsigned long result = --f_refcount; 00169 00170 // done with it? 00171 if(result == 0) { 00172 delete this; 00173 } 00174 00175 return result; 00176 } 00177 00178 00179 00180 } // namespace odbcpp 00181 00182