diff --git a/base/application.cpp b/base/application.cpp index df4949ab0..3e63ebc2e 100644 --- a/base/application.cpp +++ b/base/application.cpp @@ -18,7 +18,7 @@ Application::Application(void) #endif /* _WIN32 */ m_ShuttingDown = false; - m_ConfigHive = new_object(); + m_ConfigHive = make_shared(); } Application::~Application(void) @@ -94,7 +94,7 @@ void Application::RunEventLoop(void) else if (ready == 0) continue; - EventArgs::Ptr ea = new_object(); + EventArgs::Ptr ea = make_shared(); ea->Source = shared_from_this(); list::iterator prev, i; diff --git a/base/application.h b/base/application.h index 72940ba64..b532a5d4d 100644 --- a/base/application.h +++ b/base/application.h @@ -49,7 +49,7 @@ int application_main(int argc, char **argv) { int result; - Application::Instance = new_object(); + Application::Instance = make_shared(); vector args; diff --git a/base/confighive.cpp b/base/confighive.cpp index 9463b3483..a76734a8a 100644 --- a/base/confighive.cpp +++ b/base/confighive.cpp @@ -17,7 +17,7 @@ void ConfigHive::AddObject(const ConfigObject::Ptr& object) string name = object->GetName(); ti->second[name] = object; - ConfigHiveEventArgs::Ptr ea = new_object(); + ConfigHiveEventArgs::Ptr ea = make_shared(); ea->Source = shared_from_this(); ea->Object = object; OnObjectCreated(ea); @@ -33,7 +33,7 @@ void ConfigHive::RemoveObject(const ConfigObject::Ptr& object) ti->second.erase(object->GetName()); - ConfigHiveEventArgs::Ptr ea = new_object(); + ConfigHiveEventArgs::Ptr ea = make_shared(); ea->Source = shared_from_this(); ea->Object = object; OnObjectRemoved(ea); diff --git a/base/configobject.cpp b/base/configobject.cpp index 3542bf43a..35b9a0df7 100644 --- a/base/configobject.cpp +++ b/base/configobject.cpp @@ -38,7 +38,7 @@ void ConfigObject::SetProperty(const string& name, const string& value) ConfigHive::Ptr hive = m_Hive.lock(); if (hive.get() != NULL) { - ConfigHiveEventArgs::Ptr ea = new_object(); + ConfigHiveEventArgs::Ptr ea = make_shared(); ea->Source = hive; ea->Object = static_pointer_cast(shared_from_this()); ea->Property = name; diff --git a/base/object.h b/base/object.h index 00096adcd..71c278ead 100644 --- a/base/object.h +++ b/base/object.h @@ -36,36 +36,12 @@ public: } }; -template -shared_ptr new_object(void) -{ - T *instance = new T(); - - return shared_ptr(instance); -} - -template -shared_ptr new_object(const TArg1& arg1) -{ - T *instance = new T(arg1); - - return shared_ptr(instance); -} - -template -shared_ptr new_object(const TArg1& arg1, const TArg2& arg2) -{ - T *instance = new T(arg1, arg2); - - return shared_ptr(instance); -} - typedef function factory_function; template Object::Ptr factory(void) { - return new_object(); + return make_shared(); } } diff --git a/base/socket.cpp b/base/socket.cpp index db6332cdc..2371ad854 100644 --- a/base/socket.cpp +++ b/base/socket.cpp @@ -52,7 +52,7 @@ void Socket::Close(bool from_dtor) /* nobody can possibly have a valid event subscription when the destructor has been called */ if (!from_dtor) { - EventArgs::Ptr ea = new_object(); + EventArgs::Ptr ea = make_shared(); ea->Source = shared_from_this(); OnClosed(ea); } diff --git a/base/tcpclient.cpp b/base/tcpclient.cpp index bdcca575a..595be9203 100644 --- a/base/tcpclient.cpp +++ b/base/tcpclient.cpp @@ -4,8 +4,8 @@ using namespace icinga; TCPClient::TCPClient(void) { - m_SendQueue = new_object(); - m_RecvQueue = new_object(); + m_SendQueue = make_shared(); + m_RecvQueue = make_shared(); } void TCPClient::Start(void) @@ -48,7 +48,7 @@ int TCPClient::ReadableEventHandler(EventArgs::Ptr ea) m_RecvQueue->Write(NULL, rc); - EventArgs::Ptr dea = new_object(); + EventArgs::Ptr dea = make_shared(); dea->Source = shared_from_this(); OnDataAvailable(dea); diff --git a/base/tcpserver.cpp b/base/tcpserver.cpp index 4c8e5b6b1..bb8f6718c 100644 --- a/base/tcpserver.cpp +++ b/base/tcpserver.cpp @@ -39,7 +39,7 @@ int TCPServer::ReadableEventHandler(EventArgs::Ptr ea) fd = accept(GetFD(), (sockaddr *)&addr, &addrlen); - NewClientEventArgs::Ptr nea = new_object(); + NewClientEventArgs::Ptr nea = make_shared(); nea->Source = shared_from_this(); nea->Client = static_pointer_cast(m_ClientFactory()); nea->Client->SetFD(fd); diff --git a/base/timer.cpp b/base/timer.cpp index ad7d7b03f..817ae2f88 100644 --- a/base/timer.cpp +++ b/base/timer.cpp @@ -74,7 +74,7 @@ void Timer::StopAllTimers(void) * the timer that originally invoked the delegate */ void Timer::Call(void) { - TimerEventArgs::Ptr ea = new_object(); + TimerEventArgs::Ptr ea = make_shared(); ea->Source = shared_from_this(); ea->UserArgs = m_UserArgs; OnTimerExpired(ea); diff --git a/configfilecomponent/configfilecomponent.cpp b/configfilecomponent/configfilecomponent.cpp index 688b88878..30f166256 100644 --- a/configfilecomponent/configfilecomponent.cpp +++ b/configfilecomponent/configfilecomponent.cpp @@ -13,7 +13,7 @@ string ConfigFileComponent::GetName(void) void ConfigFileComponent::Start(void) { ifstream fp; - FIFO::Ptr fifo = new_object(); + FIFO::Ptr fifo = make_shared(); string filename; if (!GetConfig()->GetProperty("configFilename", &filename)) @@ -51,7 +51,7 @@ void ConfigFileComponent::Start(void) for (cJSON *object = typeobj->child; object != NULL; object = object->next) { string name = object->string; - ConfigObject::Ptr cfgobj = new_object(); + ConfigObject::Ptr cfgobj = make_shared(); cfgobj->SetName(name); cfgobj->SetType(type); diff --git a/configrpccomponent/configrpccomponent.cpp b/configrpccomponent/configrpccomponent.cpp index 20a425502..43aeebc79 100644 --- a/configrpccomponent/configrpccomponent.cpp +++ b/configrpccomponent/configrpccomponent.cpp @@ -40,7 +40,7 @@ void ConfigRpcComponent::Stop(void) JsonRpcMessage::Ptr ConfigRpcComponent::MakeObjectMessage(const ConfigObject::Ptr& object, string method, bool includeProperties) { - JsonRpcMessage::Ptr msg = new_object(); + JsonRpcMessage::Ptr msg = make_shared(); msg->SetVersion("2.0"); msg->SetMethod(method); cJSON *params = msg->GetParams(); diff --git a/icinga/icingaapplication.cpp b/icinga/icingaapplication.cpp index f882d7027..344cebfa5 100644 --- a/icinga/icingaapplication.cpp +++ b/icinga/icingaapplication.cpp @@ -11,7 +11,7 @@ using namespace icinga; IcingaApplication::IcingaApplication(void) { - m_ConnectionManager = new_object(); + m_ConnectionManager = make_shared(); } int IcingaApplication::Main(const vector& args) @@ -33,7 +33,7 @@ int IcingaApplication::Main(const vector& args) GetConfigHive()->OnObjectCreated += bind_weak(&IcingaApplication::ConfigObjectCreatedHandler, shared_from_this()); GetConfigHive()->OnObjectRemoved += bind_weak(&IcingaApplication::ConfigObjectRemovedHandler, shared_from_this()); - ConfigObject::Ptr fileComponentConfig = new_object(); + ConfigObject::Ptr fileComponentConfig = make_shared(); fileComponentConfig->SetName("configfilecomponent"); fileComponentConfig->SetType("component"); fileComponentConfig->SetProperty("configFilename", args[1]); diff --git a/jsonrpc/connectionmanager.cpp b/jsonrpc/connectionmanager.cpp index 67151bef0..681d5fb0b 100644 --- a/jsonrpc/connectionmanager.cpp +++ b/jsonrpc/connectionmanager.cpp @@ -50,7 +50,7 @@ int ConnectionManager::NewMessageHandler(NewMessageEventArgs::Ptr nmea) i = m_Methods.find(request->GetMethod()); if (i == m_Methods.end()) { - JsonRpcMessage::Ptr response = new_object(); + JsonRpcMessage::Ptr response = make_shared(); response->SetVersion("2.0"); response->SetError("Unknown method."); response->SetID(request->GetID()); diff --git a/jsonrpc/jsonrpcclient.cpp b/jsonrpc/jsonrpcclient.cpp index 34db54c07..e449b33e9 100644 --- a/jsonrpc/jsonrpcclient.cpp +++ b/jsonrpc/jsonrpcclient.cpp @@ -30,9 +30,9 @@ int JsonRpcClient::DataAvailableHandler(EventArgs::Ptr ea) if (json == NULL) break; - JsonRpcMessage::Ptr msg = new_object(); + JsonRpcMessage::Ptr msg = make_shared(); msg->SetJSON(json); - NewMessageEventArgs::Ptr nea = new_object(); + NewMessageEventArgs::Ptr nea = make_shared(); nea->Source = shared_from_this(); nea->Message = msg; OnNewMessage(nea);