00001 /* 00002 * The information in this file is 00003 * Copyright(c) 2007 Ball Aerospace & Technologies Corporation 00004 * and is subject to the terms and conditions of the 00005 * GNU Lesser General Public License Version 2.1 00006 * The license text is available from 00007 * http://www.gnu.org/licenses/lgpl.html 00008 */ 00009 00010 #ifndef SERVICE_H 00011 #define SERVICE_H 00012 00013 /** 00014 * This class simplifies use of Services classes. 00015 * 00016 * For example, the following code: 00017 * \code 00018 * ModelServices* pModelServices = NULL; 00019 * ModuleManager::instance()->getService()->queryInterface("ModelServices2", reinterpret_cast<void**>(&pModelServices)); 00020 * bool bHasElement = pModelServices->hasElementType("AoiElement"); 00021 * \endcode 00022 * 00023 * Would instead be: 00024 * \code 00025 * Service<ModelServices> pModelServices; 00026 * bool bHasElement = pModelServices->hasElementType("AoiElement"); 00027 * \endcode 00028 * 00029 * The following can also be done: 00030 * \code 00031 * bool bHasElement = Service<ModelServices>()->hasElementType("AoiElement"); 00032 * \endcode 00033 * 00034 * This templated class can ONLY be used with the defined template 00035 * specializations or a link-time error will occur. The specializations are: 00036 * \li Service<AnimationServices> 00037 * \li Service<ApplicationServices> 00038 * \li Service<ConfigurationSettings> 00039 * \li Service<DataVariantFactory> 00040 * \li Service<DesktopServices> 00041 * \li Service<MessageLogMgr> 00042 * \li Service<ModelServices> 00043 * \li Service<ObjectFactory> 00044 * \li Service<PlugInManagerServices> 00045 * \li Service<SessionManager> 00046 * \li Service<SessionExplorer> 00047 * \li Service<UtilityServices> 00048 */ 00049 template<class T> 00050 class Service 00051 { 00052 public: 00053 /** 00054 * Provides direct access to the Service pointer. 00055 * 00056 * @return A pointer of type T. No implementation is provided in order to 00057 * force specialization. Specialized methods need to ensure that 00058 * NULL will never be returned. 00059 */ 00060 T *get() const; 00061 00062 /** 00063 * Allows the held Service pointer to be used with pointer indirection. 00064 * 00065 * @return A pointer of type T; for all template specializations, 00066 * this is guaranteed to be non-null. 00067 */ 00068 T *operator->() const 00069 { 00070 return get(); 00071 } 00072 }; 00073 00074 #endif