objdb.h

Go to the documentation of this file.
00001 
00006 
00007 //
00008 // Copyright (c) 1999-2004 California Institute of Technology
00009 // Copyright (c) 2004-2007 University of Southern California
00010 // Rob Peters <rjpeters at usc dot edu>
00011 //
00012 // created: Sun Nov 21 00:26:29 1999
00013 // commit: $Id: objdb.h 10065 2007-04-12 05:54:56Z rjpeters $
00014 // $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/nub/objdb.h $
00015 //
00016 // --------------------------------------------------------------------
00017 //
00018 // This file is part of GroovX.
00019 //   [http://ilab.usc.edu/rjpeters/groovx/]
00020 //
00021 // GroovX is free software; you can redistribute it and/or modify it
00022 // under the terms of the GNU General Public License as published by
00023 // the Free Software Foundation; either version 2 of the License, or
00024 // (at your option) any later version.
00025 //
00026 // GroovX is distributed in the hope that it will be useful, but
00027 // WITHOUT ANY WARRANTY; without even the implied warranty of
00028 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00029 // General Public License for more details.
00030 //
00031 // You should have received a copy of the GNU General Public License
00032 // along with GroovX; if not, write to the Free Software Foundation,
00033 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00034 //
00036 
00037 #ifndef GROOVX_NUB_OBJDB_H_UTC20050626084019_DEFINED
00038 #define GROOVX_NUB_OBJDB_H_UTC20050626084019_DEFINED
00039 
00040 #include "nub/uid.h"
00041 
00042 #include "rutz/error.h"
00043 #include "rutz/iter.h"
00044 
00045 namespace nub
00046 {
00047   class object;
00048   class objectdb;
00049   class invalid_uid_error;
00050 }
00051 
00060 class nub::invalid_uid_error : public rutz::error
00061 {
00062 public:
00064   invalid_uid_error(nub::uid id, const rutz::file_pos& pos);
00065 
00067   virtual ~invalid_uid_error() throw();
00068 };
00069 
00071 
00079 
00080 
00081 class nub::objectdb
00082 {
00083 protected:
00085   objectdb();
00086 
00087 public:
00089   virtual ~objectdb();
00090 
00092   static objectdb& instance();
00093 
00094   class impl;
00095 
00096   //
00097   // Iterators
00098   //
00099 
00100   typedef rutz::fwd_iter<object* const> iterator;
00101 
00102   iterator objects() const;
00103 
00105   template <class T>
00106   class casting_iterator
00107   {
00108     iterator m_itr;
00109 
00110     void advance_to_valid()
00111     {
00112       while (!m_itr.at_end() && (dynamic_cast<T*>(*m_itr)==0))
00113         ++m_itr;
00114     }
00115 
00116   public:
00117     casting_iterator(const iterator& begin) : m_itr(begin)
00118     { advance_to_valid(); }
00119 
00120     casting_iterator& operator++() { ++m_itr; advance_to_valid(); return *this; }
00121 
00122     bool at_end() const { return m_itr.at_end(); }
00123     bool is_valid() const { return m_itr.is_valid(); }
00124 
00125     T* operator*() const { return &(dynamic_cast<T&>(**m_itr)); }
00126 
00127     T* operator->() const { return operator*(); }
00128   };
00129 
00130   //
00131   // Collection interface
00132   //
00133 
00135   int count() const throw();
00136 
00138   bool is_valid_uid(nub::uid id) const throw();
00139 
00141 
00143   void remove(nub::uid id);
00144 
00146   void release(nub::uid id);
00147 
00149 
00151   void purge();
00152 
00154 
00156   void clear();
00157 
00159 
00162   void clear_on_exit();
00163 
00165 
00167   nub::object* get_checked_obj(nub::uid id) throw (nub::invalid_uid_error);
00168 
00170   void insert_obj(nub::object* obj);
00171 
00173   void insert_obj_weak(nub::object* obj);
00174 
00175 private:
00176   objectdb(const objectdb&);
00177   objectdb& operator=(const objectdb&);
00178 
00179   impl* const rep;
00180 };
00181 
00182 static const char __attribute__((used)) vcid_groovx_nub_objdb_h_utc20050626084019[] = "$Id: objdb.h 10065 2007-04-12 05:54:56Z rjpeters $ $HeadURL: file:
00183 #endif // !GROOVX_NUB_OBJDB_H_UTC20050626084019_DEFINED

The software described here is Copyright (c) 1998-2005, Rob Peters.
This page was generated Wed Dec 3 06:49:39 2008 by Doxygen version 1.5.5.