Browse Source

Replace xtl::delete_ptr functor with lambdas

Michael Hansen 12 years ago
parent
commit
4c7ce8665c
  1. 27
      Sources/Plasma/CoreLib/hsStlUtils.h
  2. 8
      Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp
  3. 4
      Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp
  4. 4
      Sources/Plasma/PubUtilLib/plSDL/plSDLMgr.cpp
  5. 4
      Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp

27
Sources/Plasma/CoreLib/hsStlUtils.h

@ -76,31 +76,6 @@ OutIt copy_if( InIt srcBegin, InIt srcEnd, OutIt dstBegin, Pred pred )
} }
// useful when clearing a vector/list/set of pointers that need to be deleted.
// use like:
// std::vector<foo*> vec;
// std::for_each(vec.begin(),vec.end(),xtl::delete_ptr());
// vec.clear();
struct delete_ptr
{
template< class T > void operator()( T * p ) const { delete p;}
};
// useful when clearing a map of pointers that need to be deleted.
// use like:
// typedef std::map<int,foo*> foomap;
// foomap m;
// std::for_each(m.begin(),m.end(),xtl::delete_map_ptr_T<foomap>());
// m.clear();
template< class A >
struct delete_map_ptr_T
{
void operator()( typename A::value_type & pair ) const { delete pair.second;}
};
// std::string trim // std::string trim
std::string & trimleft(std::string & s, const char * charset=" \t\n\r"); std::string & trimleft(std::string & s, const char * charset=" \t\n\r");
std::wstring & trimleft(std::wstring & s, const wchar_t * charset=L" \t\n\r"); std::wstring & trimleft(std::wstring & s, const wchar_t * charset=L" \t\n\r");
@ -128,7 +103,7 @@ template <typename T> bool GetStringGroupAsString(const T& group, std::string& s
template <typename T> bool GetStringGroupAsString(const T& group, std::wstring& s, wchar_t sep = L','); template <typename T> bool GetStringGroupAsString(const T& group, std::wstring& s, wchar_t sep = L',');
} // namespace xtd } // namespace xtl

8
Sources/Plasma/PubUtilLib/plNetClient/plNetClientMgr.cpp

@ -210,7 +210,9 @@ void plNetClientMgr::Shutdown()
// //
void plNetClientMgr::IClearPendingLoads() void plNetClientMgr::IClearPendingLoads()
{ {
std::for_each( fPendingLoads.begin(), fPendingLoads.end(), xtl::delete_ptr() ); std::for_each( fPendingLoads.begin(), fPendingLoads.end(),
[](PendingLoad *pl) { delete pl; }
);
fPendingLoads.clear(); fPendingLoads.clear();
} }
@ -1557,7 +1559,9 @@ void plNetClientMgr::SendPendingPagingRoomMsgs()
void plNetClientMgr::ClearPendingPagingRoomMsgs() void plNetClientMgr::ClearPendingPagingRoomMsgs()
{ {
std::for_each( fPendingPagingRoomMsgs.begin(), fPendingPagingRoomMsgs.end(), xtl::delete_ptr() ); std::for_each( fPendingPagingRoomMsgs.begin(), fPendingPagingRoomMsgs.end(),
[](plNetMsgPagingRoom *pr) { delete pr; }
);
fPendingPagingRoomMsgs.clear(); fPendingPagingRoomMsgs.clear();
} }

4
Sources/Plasma/PubUtilLib/plNetCommon/plNetCommonHelpers.cpp

@ -102,7 +102,9 @@ plCreatableListHelper::plCreatableListHelper()
void plCreatableListHelper::IClearItems() void plCreatableListHelper::IClearItems()
{ {
std::for_each( fManagedItems.begin(), fManagedItems.end(), xtl::delete_ptr() ); std::for_each( fManagedItems.begin(), fManagedItems.end(),
[](plCreatable * cre) { delete cre; }
);
fManagedItems.clear(); fManagedItems.clear();
fItems.clear(); fItems.clear();
} }

4
Sources/Plasma/PubUtilLib/plSDL/plSDLMgr.cpp

@ -83,7 +83,9 @@ void plSDLMgr::DeInit()
// //
void plSDLMgr::IDeleteDescriptors(plSDL::DescriptorList* dl) void plSDLMgr::IDeleteDescriptors(plSDL::DescriptorList* dl)
{ {
std::for_each( dl->begin(), dl->end(), xtl::delete_ptr() ); std::for_each( dl->begin(), dl->end(),
[](plStateDescriptor* sd) { delete sd; }
);
dl->clear(); dl->clear();
} }

4
Sources/Plasma/PubUtilLib/plSDL/plStateDataRecord.cpp

@ -121,7 +121,9 @@ void plStateDataRecord::SetDescriptor(const plString& name, int version)
void plStateDataRecord::IDeleteVarsList(VarsList& vars) void plStateDataRecord::IDeleteVarsList(VarsList& vars)
{ {
std::for_each( vars.begin(), vars.end(), xtl::delete_ptr() ); std::for_each( vars.begin(), vars.end(),
[](plStateVariable* var) { delete var; }
);
vars.clear(); vars.clear();
} }

Loading…
Cancel
Save