1 /* |
|
2 * Licensed to the Apache Software Foundation (ASF) under one or more |
|
3 * contributor license agreements. See the NOTICE file distributed with |
|
4 * this work for additional information regarding copyright ownership. |
|
5 * The ASF licenses this file to You under the Apache License, Version 2.0 |
|
6 * (the "License"); you may not use this file except in compliance with |
|
7 * the License. You may obtain a copy of the License at |
|
8 * |
|
9 * http://www.apache.org/licenses/LICENSE-2.0 |
|
10 * |
|
11 * Unless required by applicable law or agreed to in writing, software |
|
12 * distributed under the License is distributed on an "AS IS" BASIS, |
|
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14 * See the License for the specific language governing permissions and |
|
15 * limitations under the License. |
|
16 */ |
|
17 |
|
18 /* |
|
19 * $Id: XProtoType.hpp 568078 2007-08-21 11:43:25Z amassari $ |
|
20 */ |
|
21 |
|
22 |
|
23 #if !defined(XPROTOTYPE_HPP) |
|
24 #define XPROTOTYPE_HPP |
|
25 |
|
26 #include <xercesc/util/PlatformUtils.hpp> |
|
27 |
|
28 XERCES_CPP_NAMESPACE_BEGIN |
|
29 |
|
30 class XSerializeEngine; |
|
31 class XSerializable; |
|
32 |
|
33 class XMLUTIL_EXPORT XProtoType |
|
34 { |
|
35 public: |
|
36 |
|
37 void store(XSerializeEngine& serEng) const; |
|
38 |
|
39 static void load(XSerializeEngine& serEng |
|
40 , XMLByte* const name |
|
41 , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager |
|
42 ); |
|
43 |
|
44 // ------------------------------------------------------------------------------- |
|
45 // data |
|
46 // |
|
47 // fClassName: |
|
48 // name of the XSerializable derivatives |
|
49 // |
|
50 // fCreateObject: |
|
51 // pointer to the factory method (createObject()) |
|
52 // of the XSerializable derivatives |
|
53 // |
|
54 // ------------------------------------------------------------------------------- |
|
55 |
|
56 XMLByte* fClassName; |
|
57 |
|
58 XSerializable* (*fCreateObject)(MemoryManager*); |
|
59 |
|
60 }; |
|
61 |
|
62 #define DECL_XPROTOTYPE(class_name) \ |
|
63 static XProtoType class##class_name; \ |
|
64 static XSerializable* createObject(MemoryManager* manager); |
|
65 |
|
66 /*** |
|
67 * For non-abstract class |
|
68 ***/ |
|
69 #define IMPL_XPROTOTYPE_TOCREATE(class_name) \ |
|
70 IMPL_XPROTOTYPE_INSTANCE(class_name) \ |
|
71 XSerializable* class_name::createObject(MemoryManager* manager) \ |
|
72 {return new (manager) class_name(manager);} |
|
73 |
|
74 /*** |
|
75 * For abstract class |
|
76 ***/ |
|
77 #define IMPL_XPROTOTYPE_NOCREATE(class_name) \ |
|
78 IMPL_XPROTOTYPE_INSTANCE(class_name) \ |
|
79 XSerializable* class_name::createObject(MemoryManager*) \ |
|
80 {return 0;} |
|
81 |
|
82 |
|
83 /*** |
|
84 * Helper Macro |
|
85 ***/ |
|
86 #define XPROTOTYPE_CLASS(class_name) ((XProtoType*)(&class_name::class##class_name)) |
|
87 |
|
88 #define IMPL_XPROTOTYPE_INSTANCE(class_name) \ |
|
89 XProtoType class_name::class##class_name = \ |
|
90 {(XMLByte*) #class_name, class_name::createObject }; |
|
91 |
|
92 XERCES_CPP_NAMESPACE_END |
|
93 |
|
94 #endif |
|