51473e89266d2728103c0183bd788a8e2c115e6e
[platform/framework/web/wrt-commons.git] / modules / event / include / dpl / event / model_bind_to_dao.h
1 /*
2  * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  *    Licensed under the Apache License, Version 2.0 (the "License");
5  *    you may not use this file except in compliance with the License.
6  *    You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *    Unless required by applicable law or agreed to in writing, software
11  *    distributed under the License is distributed on an "AS IS" BASIS,
12  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *    See the License for the specific language governing permissions and
14  *    limitations under the License.
15  */
16 /**
17  * @file    model_bind_to_dao.h
18  * @author  Grzegorz Krawczyk (g.krawczyk@samsung.com)
19  * @version 1.0
20  * @brief
21  */
22
23 #ifndef DPL_MODEL_BIND_TO_DAO_H_
24 #define DPL_MODEL_BIND_TO_DAO_H_
25
26 namespace DPL
27 {
28 namespace Event
29 {
30
31 /**
32  * @param ObjectType type of object used as delegate argument
33  * @param RetType Type returned from the external function
34  * @param ExtArg Type of argument required by external fun
35  * @param getterFun Object Type method which returns value of type ExtArg
36  * used as argument for external function
37  * */
38 //STATIC FUNCTION
39 template <
40     typename ObjectType,
41     typename ValueType,
42     typename ExtArg,
43     ExtArg(ObjectType::*argGetter) () const,
44     ValueType(*externalGetter) (ExtArg)
45     >
46 struct BindToDAO_Static
47 {
48     static ValueType Get(DPL::Event::Model* obj)
49     {
50         ObjectType* instance = static_cast<ObjectType*>(obj);
51
52         return externalGetter((instance->*argGetter)());
53     }
54 };
55
56 template <
57     typename ObjectType,
58     typename ValueType,
59     typename ExtArg,
60     typename ExtObject,
61     ExtArg(ObjectType::*argGetter) () const,
62     ValueType(ExtObject::*externalGetter) () const
63     >
64 struct BindToDAO
65 {
66     static ValueType Get(DPL::Event::Model* obj)
67     {
68         ObjectType* instance = static_cast<ObjectType*>(obj);
69         ExtObject extObject((instance->*argGetter)());
70         return (extObject.*externalGetter)();
71     }
72 };
73
74 }
75 }
76
77 #endif