00001 /** @file nub/ref.cc smart pointers (both strong and weak) using 00002 intrusive ref-counting with nub::object and derivatives */ 00003 00004 /////////////////////////////////////////////////////////////////////// 00005 // 00006 // Copyright (c) 2000-2004 California Institute of Technology 00007 // Copyright (c) 2004-2007 University of Southern California 00008 // Rob Peters <rjpeters at usc dot edu> 00009 // 00010 // created: Wed Nov 16 09:06:27 2005 00011 // commit: $Id: ref.cc 8249 2007-04-12 06:03:40Z rjpeters $ 00012 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/nub/ref.cc $ 00013 // 00014 // -------------------------------------------------------------------- 00015 // 00016 // This file is part of GroovX. 00017 // [http://www.klab.caltech.edu/rjpeters/groovx/] 00018 // 00019 // GroovX is free software; you can redistribute it and/or modify it 00020 // under the terms of the GNU General Public License as published by 00021 // the Free Software Foundation; either version 2 of the License, or 00022 // (at your option) any later version. 00023 // 00024 // GroovX is distributed in the hope that it will be useful, but 00025 // WITHOUT ANY WARRANTY; without even the implied warranty of 00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00027 // General Public License for more details. 00028 // 00029 // You should have received a copy of the GNU General Public License 00030 // along with GroovX; if not, write to the Free Software Foundation, 00031 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00032 // 00033 /////////////////////////////////////////////////////////////////////// 00034 00035 #ifndef GROOVX_NUB_REF_CC_UTC20051116170627_DEFINED 00036 #define GROOVX_NUB_REF_CC_UTC20051116170627_DEFINED 00037 00038 #include "nub/ref.h" 00039 00040 #include "nub/objdb.h" 00041 00042 #include "rutz/error.h" 00043 #include "rutz/demangle.h" 00044 00045 #include "rutz/debug.h" 00046 GVX_DBG_REGISTER 00047 00048 #ifndef GVX_DEFAULT_REFVIS 00049 # define GVX_DEFAULT_REFVIS PRIVATE 00050 #endif 00051 00052 namespace 00053 { 00054 nub::ref_vis default_vis = nub::GVX_DEFAULT_REFVIS; 00055 } 00056 00057 nub::ref_vis nub::get_default_ref_vis() 00058 { 00059 return default_vis; 00060 } 00061 00062 void nub::set_default_ref_vis(nub::ref_vis vis) 00063 { 00064 default_vis = vis; 00065 } 00066 00067 bool nub::detail::is_valid_uid(nub::uid id) throw() 00068 { 00069 return nub::objectdb::instance().is_valid_uid(id); 00070 } 00071 00072 nub::object* nub::detail::get_checked_item(nub::uid id) 00073 { 00074 return nub::objectdb::instance().get_checked_obj(id); 00075 } 00076 00077 void nub::detail::insert_item(nub::object* obj, ref_vis vis) 00078 { 00079 if (vis == DEFAULT) 00080 { 00081 vis = default_vis; 00082 } 00083 00084 switch (vis) 00085 { 00086 case PUBLIC: nub::objectdb::instance().insert_obj(obj); break; 00087 case PROTECTED: nub::objectdb::instance().insert_obj_weak(obj); break; 00088 case PRIVATE: /* nothing */ break; 00089 default: 00090 GVX_PANIC("unknown ref_vis enum value"); 00091 } 00092 } 00093 00094 static const char __attribute__((used)) vcid_groovx_nub_ref_cc_utc20051116170627[] = "$Id: ref.cc 8249 2007-04-12 06:03:40Z rjpeters $ $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/nub/ref.cc $"; 00095 #endif // !GROOVX_NUB_REF_CC_UTC20051116170627DEFINED