utility.h

00001 /***************************************************************************
00002  *   Copyright (C) 2004 by Rick L. Vinyard, Jr.                            *
00003  *   rvinyard@cs.nmsu.edu                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation version 2.1.                *
00008  *                                                                         *
00009  *   This program is distributed in the hope that it will be useful,       *
00010  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00011  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00012  *   GNU General Public License for more details.                          *
00013  *                                                                         *
00014  *   You should have received a copy of the GNU Lesser General Public      *
00015  *   License along with this library; if not, write to the                 *
00016  *   Free Software Foundation, Inc.,                                       *
00017  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00018  ***************************************************************************/
00019 #ifndef IDIOSKOPOSUTILITY_H
00020 #define IDIOSKOPOSUTILITY_H
00021 
00022 #include <idioskopos/property.h>
00023 #include <idioskopos/error.h>
00024 
00025 namespace Idioskopos {
00026 
00030 template <typename T>
00031 inline
00032 Property<T>& property_cast(Object& pb) throw (error::bad_cast) {
00033     if (pb.type() != typeid(T))
00034         throw error::cast::wrong_property_type();
00035     return dynamic_cast<Property<T>&>(pb);
00036 }
00037 
00041 template <typename T>
00042 inline
00043 Property<T>& property_cast(Object* pb) throw (error::bad_cast) {
00044     if (pb == NULL)
00045         throw error::cast::null_pointer();
00046     if (pb->type() != typeid(T))
00047         throw  error::cast::wrong_property_type();
00048     return *(dynamic_cast<Property<T>*>(pb));
00049 }
00050 
00055 template <typename T>
00056 inline
00057 Property<T>& property(Introspectable& obj, const Glib::ustring name) throw (error::bad_cast) {
00058     Object* pb = obj.get_property(name);
00059     if (pb == NULL)
00060         throw  error::cast::null_pointer();
00061     return property_cast<T>(*pb);
00062 }
00063 
00064 }
00065 
00066 #endif

Generated on Thu Jan 11 00:26:41 2007 by  doxygen 1.5.1