MOAB: Mesh Oriented datABase  (version 5.4.1)
Factory.cpp
Go to the documentation of this file.
00001 /**
00002  * MOAB, a Mesh-Oriented datABase, is a software component for creating,
00003  * storing and accessing finite element mesh data.
00004  *
00005  * Copyright 2004 Sandia Corporation.  Under the terms of Contract
00006  * DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government
00007  * retains certain rights in this software.
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public
00011  * License as published by the Free Software Foundation; either
00012  * version 2.1 of the License, or (at your option) any later version.
00013  *
00014  */
00015 
00016 #ifdef WIN32
00017 #ifdef _DEBUG
00018 // turn off warnings that say they debugging identifier has been truncated
00019 // this warning comes up when using some STL containers
00020 #pragma warning( disable : 4786 )
00021 #endif
00022 #endif
00023 
00024 #include "moab/Core.hpp"
00025 
00026 #ifdef XPCOM_MB
00027 
00028 #include "nsIGenericFactory.h"
00029 
00030 // define constructor function for Core
00031 NS_GENERIC_FACTORY_CONSTRUCTOR( moab::Core )
00032 
00033 // support for nsIClassInfo
00034 NS_DECL_CLASSINFO( moab::Core )
00035 
00036 MB_EXPORT const char* MoabVersion();
00037 MB_EXPORT void GetInterface( MBuuid& interface_requested, UnknownInterface** iface );
00038 MB_EXPORT void DeInitialize();
00039 MB_EXPORT void ReleaseInterface( UnknownInterface* iface );
00040 
00041 static const nsModuleComponentInfo components[] = {
00042     { "MOAB Interface", CORE_CID, CORE_CONTRACTID, CoreConstructor, NULL /* NULL if you dont need one */,
00043       NULL /* NULL if you dont need one */, NULL /* no factory destructor */, NS_CI_INTERFACE_GETTER_NAME( moab::Core ),
00044       NULL /* no language helper */, &NS_CLASSINFO_NAME( moab::Core ), 0 } };
00045 
00046 // implement NSGetModule()
00047 NS_IMPL_NSGETMODULE( moab::Core, components );
00048 
00049 #endif
00050 
00051 #ifndef WIN32
00052 #define MB_EXPORT extern "C"
00053 #else
00054 #define MB_EXPORT extern "C" __declspec( dllexport )
00055 #endif
00056 
00057 #include <list>
00058 
00059 namespace moab
00060 {
00061 
00062 class ComponentFactory : public UnknownInterface
00063 {
00064   public:
00065     ComponentFactory() {}
00066     virtual ~ComponentFactory() {}
00067     // returns the interface requested from an object
00068     virtual int QueryInterface( const MBuuid&, UnknownInterface** );
00069     // keep track of the objects this component factory creates
00070     static std::list< UnknownInterface* > objects_in_use;
00071 };
00072 
00073 // the list that keeps track of all the interfaces generated by this server
00074 std::list< UnknownInterface* > ComponentFactory::objects_in_use;
00075 
00076 // this QueryInterface function is supposed to create an instance of the object
00077 // that contains the interface requested
00078 //
00079 // note: the object is not the same as the interface, therefore
00080 // we ask the object for the interface that was requested
00081 //
00082 
00083 int ComponentFactory::QueryInterface( const MBuuid& uuid, UnknownInterface** iface )
00084 {
00085     // this is an unknown interface that was requested
00086     // if wanted, we could provide a default interface
00087     // if IDD_MBUnknown is specified
00088     if( uuid == IDD_MBUnknown ) return 0;
00089     // IDD_MBVerde interface was requested
00090     // create an Verde object and have it return the interface
00091     // requested
00092     else if( uuid == IDD_MBCore )
00093     {
00094         Core* mdb = new Core;
00095         // if the object does not contain the interface requested, delete the object
00096         if( !mdb->QueryInterface( uuid, iface ) )
00097         {
00098             delete mdb;
00099             return 0;
00100         }
00101         return 1;
00102     }
00103     else
00104         return 0;
00105 }
00106 
00107 // returns the interface version
00108 MB_EXPORT const char* MoabVersion()
00109 {
00110     return MB_INTERFACE_VERSION;
00111 }
00112 
00113 // Initialize function is accessed by the MBClient when asking for interfaces
00114 MB_EXPORT void GetInterface( MBuuid& interface_requested, UnknownInterface** iface )
00115 {
00116     // create an instance of our component factory
00117     ComponentFactory server;
00118     // ask the component factory to give us the interface we want
00119     server.QueryInterface( interface_requested, iface );
00120     // if the interface existed, put it on our list
00121     if( iface && *iface ) ComponentFactory::objects_in_use.push_front( *iface );
00122 }
00123 
00124 // DeInitialize function is accessed by the MBClient when disconnecting from this library
00125 // this will clean everything up prior to a disconnection
00126 // from this library
00127 MB_EXPORT void DeInitialize()
00128 {
00129     // delete all instances of objects
00130     while( ComponentFactory::objects_in_use.size() )
00131     {
00132         UnknownInterface* iface = ComponentFactory::objects_in_use.front();
00133         ComponentFactory::objects_in_use.pop_front();
00134         if( iface ) delete iface;
00135     }
00136 }
00137 
00138 // ReleaseInterface function is accessed by the MBClient when deleting an interface
00139 
00140 // ReleaseInterface will delete this interface
00141 MB_EXPORT void ReleaseInterface( UnknownInterface* iface )
00142 {
00143     if( !iface ) return;
00144     // remove this object from our list and delete it
00145     ComponentFactory::objects_in_use.remove( iface );
00146     delete iface;
00147 }
00148 
00149 }  // namespace moab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines