Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

repository.h

Go to the documentation of this file.
00001 /*
00002     toxic - A Global Illumination Renderer
00003     Copyright (C) 2003-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of toxic.
00007 
00008     toxic is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     toxic is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with toxic; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef TOXIC_DRIVER_REPOSITORY_H
00024 #define TOXIC_DRIVER_REPOSITORY_H
00025 
00026 #include "renderer/globals.h"
00027 
00028 #include <map>
00029 #include <string>
00030 
00031 namespace toxic {
00032 
00033 #define DEFINE_EXCEPTION(e) \
00034     struct e { \
00035         e(const std::string &key) : \
00036             m_key(key) {} \
00037         std::string m_key; \
00038     };
00039 
00040     template<typename T>
00041     class Repository {
00042     public:
00043         DEFINE_EXCEPTION(DuplicateKeyException);
00044         DEFINE_EXCEPTION(InvalidKeyException);
00045 
00046         virtual ~Repository() {}
00047 
00048         virtual void Insert(const std::string &key, const T &object)
00049             throw(DuplicateKeyException);
00050 
00051         virtual void Remove(const std::string &key)
00052             throw(InvalidKeyException);
00053 
00054         virtual T &Find(const std::string &key)
00055             throw(InvalidKeyException);
00056 
00057         virtual const T &Find(const std::string &key) const
00058             throw(InvalidKeyException);
00059 
00060         virtual bool Contains(const std::string &key) const;
00061 
00062     protected:
00063         typedef std::map<std::string, T> object_map;
00064 
00065         object_map m_objects;
00066     };
00067 
00068 #undef DEFINE_EXCEPTION
00069 
00070 #include "repository.inl"
00071 
00072 }
00073 
00074 #endif  // !TOXIC_DRIVER_REPOSITORY_H

Generated on Tue May 11 01:31:52 2004 for toxic by doxygen 1.3.6