|
Urbi SDK Remote for C++
2.7.5
|
00001 /* 00002 * Copyright (C) 2007, 2008, 2009, 2010, Gostai S.A.S. 00003 * 00004 * This software is provided "as is" without warranty of any kind, 00005 * either expressed or implied, including but not limited to the 00006 * implied warranties of fitness for a particular purpose. 00007 * 00008 * See the LICENSE file for more information. 00009 */ 00010 00012 #ifndef URBI_STARTER_HXX 00013 # define URBI_STARTER_HXX 00014 00015 # include <algorithm> 00016 # include <string> 00017 00018 # include <urbi/uobject.hh> 00019 # include <urbi/ustarter.hh> 00020 00021 namespace urbi 00022 { 00023 00024 /*------------------. 00025 | baseURBIStarter. | 00026 `------------------*/ 00027 00028 inline 00029 baseURBIStarter::baseURBIStarter(const std::string& name, bool local) 00030 : name(name) 00031 , local(local) 00032 {} 00033 00034 inline 00035 baseURBIStarter::~baseURBIStarter() 00036 {} 00037 00038 /*--------------. 00039 | URBIStarter. | 00040 `--------------*/ 00041 template <class T> 00042 inline 00043 URBIStarter<T>::URBIStarter(const std::string& name, bool local) 00044 : baseURBIStarter(name, local) 00045 { 00046 list().push_back(this); 00047 } 00048 00049 template <class T> 00050 inline 00051 URBIStarter<T>::~URBIStarter() 00052 { 00053 list().remove(this); 00054 } 00055 00056 template <class T> 00057 inline 00058 UObject* 00059 URBIStarter<T>::instanciate(impl::UContextImpl* ctx, 00060 const std::string& n) 00061 { 00062 std::string rn = n; 00063 if (rn.empty()) 00064 rn = name; 00065 // FIXME: not exception-safe 00066 setCurrentContext(ctx); 00067 UObject* res = new T(rn); 00068 ctx->instanciated(res); 00069 res->cloner = this; 00070 return res; 00071 } 00072 00073 /*---------------------. 00074 | baseURBIStarterHub. | 00075 `---------------------*/ 00076 00077 inline 00078 baseURBIStarterHub::baseURBIStarterHub(const std::string& name) 00079 : name(name) 00080 {} 00081 00082 inline 00083 baseURBIStarterHub::~baseURBIStarterHub() 00084 {} 00085 00086 /*-----------------. 00087 | URBIStarterHub. | 00088 `-----------------*/ 00089 00090 template <class T> 00091 inline 00092 URBIStarterHub<T>::URBIStarterHub(const std::string& name) 00093 : baseURBIStarterHub(name) 00094 { 00095 list().push_back(this); 00096 } 00097 00098 template <class T> 00099 inline 00100 URBIStarterHub<T>::~URBIStarterHub() 00101 { 00102 list().remove(this); 00103 } 00104 template <class T> 00105 inline 00106 UObjectHub* 00107 URBIStarterHub<T>::instanciate(impl::UContextImpl* ctx, 00108 const std::string& n) 00109 { 00110 setCurrentContext(ctx); 00111 return new T(n.empty()? name:n); 00112 } 00113 00114 } // end namespace urbi 00115 00116 #endif // !URBI_STARTER_HXX