server.cc
Go to the documentation of this file.
00001 /* -*- C++ -*-
00002  * $Id: server.cc 970 2005-04-08 16:30:46Z sjoyeux $
00003  */
00004 #include "server.hh"
00005 
00006 using namespace std;
00007 
00008 using namespace utilmm::singleton;
00009 using boost::recursive_mutex;
00010 
00011 server* utilmm::singleton::server::the_instance = 0;
00012 
00013 boost::recursive_mutex utilmm::singleton::server::sing_mtx;
00014 
00015 /*
00016  * class utilmm::singleton::server
00017  */
00018 // structors 
00019 server::server() {
00020   the_instance = this;
00021 }
00022 
00023 server::~server() {
00024   the_instance = 0;
00025 }
00026 
00027 // modifiers
00028 void server::attach(std::string const &name, details::dummy_factory const& factory) {
00029   single_map::iterator it = singletons.find(name);
00030   if (it == singletons.end())
00031     it = singletons.insert( single_map::value_type(name, factory.create()) ).first;
00032 
00033   it->second->incr_ref();
00034 }
00035 
00036 bool server::detach(std::string const &name) {
00037   single_map::iterator i = singletons.find(name);
00038 
00039   if( i->second->decr_ref() ) {
00040     dummy *to_del = i->second;
00041 
00042     singletons.erase(i);
00043     delete to_del;
00044     return singletons.empty();
00045   }
00046   return false;
00047 }
00048 
00049 // observers 
00050 dummy *server::get(std::string const &name) const {
00051   return singletons.find(name)->second;
00052 }
00053 
00054 // statics
00055 server &server::instance() {
00056   if( 0==the_instance )
00057     new server;
00058   return *the_instance;
00059 }


typelib
Author(s): Sylvain Joyeux/sylvain.joyeux@m4x.org
autogenerated on Sat Jun 8 2019 18:49:22