2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef MANGOS_CREATIONPOLICY_H
20 #define MANGOS_CREATIONPOLICY_H
23 #include "Platform/Define.h"
28 * OperatorNew policy creates an object on the heap using new.
31 class MANGOS_DLL_DECL OperatorNew
34 static T
* Create(void) { return (new T
); }
35 static void Destroy(T
*obj
) { delete obj
; }
39 * LocalStaticCreation policy creates an object on the stack
40 * the first time call Create.
43 class MANGOS_DLL_DECL LocalStaticCreation
53 long double longDouble_
;
56 int (Test::*pMemberFn_
)(int);
59 static T
* Create(void)
61 static MaxAlign si_localStatic
;
62 return new(&si_localStatic
) T
;
65 static void Destroy(T
*obj
) { obj
->~T(); }
69 * CreateUsingMalloc by pass the memory manger.
72 class MANGOS_DLL_DECL CreateUsingMalloc
77 void* p
= ::malloc(sizeof(T
));
82 static void Destroy(T
* p
)
90 * CreateOnCallBack creates the object base on the call back.
92 template<class T
, class CALL_BACK
>
93 class MANGOS_DLL_DECL CreateOnCallBack
98 return CALL_BACK::createCallBack();
101 static void Destroy(T
*p
)
103 CALL_BACK::destroyCallBack(p
);