1 | /*
|
---|
2 | * Copyright 2003,2004 The Apache Software Foundation.
|
---|
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 | /*
|
---|
18 | * $Id: XProtoType.hpp,v 1.5 2004/09/08 13:56:14 peiyongz Exp $
|
---|
19 | * $Log: XProtoType.hpp,v $
|
---|
20 | * Revision 1.5 2004/09/08 13:56:14 peiyongz
|
---|
21 | * Apache License Version 2.0
|
---|
22 | *
|
---|
23 | * Revision 1.4 2004/01/29 11:46:30 cargilld
|
---|
24 | * Code cleanup changes to get rid of various compiler diagnostic messages.
|
---|
25 | *
|
---|
26 | * Revision 1.3 2003/12/17 00:18:34 cargilld
|
---|
27 | * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
|
---|
28 | *
|
---|
29 | * Revision 1.2 2003/09/23 18:12:19 peiyongz
|
---|
30 | * Macro re-organized: provide create/nocreate macros for abstract and
|
---|
31 | * nonabstract classes
|
---|
32 | *
|
---|
33 | * Revision 1.1 2003/09/18 18:31:24 peiyongz
|
---|
34 | * OSU: Object Serialization Utilities
|
---|
35 | *
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 | #if !defined(XPROTOTYPE_HPP)
|
---|
40 | #define XPROTOTYPE_HPP
|
---|
41 |
|
---|
42 | #include <xercesc/util/PlatformUtils.hpp>
|
---|
43 |
|
---|
44 | XERCES_CPP_NAMESPACE_BEGIN
|
---|
45 |
|
---|
46 | class XSerializeEngine;
|
---|
47 | class XSerializable;
|
---|
48 |
|
---|
49 | class XMLUTIL_EXPORT XProtoType
|
---|
50 | {
|
---|
51 | public:
|
---|
52 |
|
---|
53 | void store(XSerializeEngine& serEng) const;
|
---|
54 |
|
---|
55 | static void load(XSerializeEngine& serEng
|
---|
56 | , XMLByte* const name
|
---|
57 | , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
|
---|
58 | );
|
---|
59 |
|
---|
60 | // -------------------------------------------------------------------------------
|
---|
61 | // data
|
---|
62 | //
|
---|
63 | // fClassName:
|
---|
64 | // name of the XSerializable derivatives
|
---|
65 | //
|
---|
66 | // fCreateObject:
|
---|
67 | // pointer to the factory method (createObject())
|
---|
68 | // of the XSerializable derivatives
|
---|
69 | //
|
---|
70 | // -------------------------------------------------------------------------------
|
---|
71 |
|
---|
72 | XMLByte* fClassName;
|
---|
73 |
|
---|
74 | XSerializable* (*fCreateObject)(MemoryManager*);
|
---|
75 |
|
---|
76 | };
|
---|
77 |
|
---|
78 | #define DECL_XPROTOTYPE(class_name) \
|
---|
79 | static XProtoType class##class_name; \
|
---|
80 | static XSerializable* createObject(MemoryManager* manager);
|
---|
81 |
|
---|
82 | /***
|
---|
83 | * For non-abstract class
|
---|
84 | ***/
|
---|
85 | #define IMPL_XPROTOTYPE_TOCREATE(class_name) \
|
---|
86 | IMPL_XPROTOTYPE_INSTANCE(class_name) \
|
---|
87 | XSerializable* class_name::createObject(MemoryManager* manager) \
|
---|
88 | {return new (manager) class_name(manager);}
|
---|
89 |
|
---|
90 | /***
|
---|
91 | * For abstract class
|
---|
92 | ***/
|
---|
93 | #define IMPL_XPROTOTYPE_NOCREATE(class_name) \
|
---|
94 | IMPL_XPROTOTYPE_INSTANCE(class_name) \
|
---|
95 | XSerializable* class_name::createObject(MemoryManager*) \
|
---|
96 | {return 0;}
|
---|
97 |
|
---|
98 |
|
---|
99 | /***
|
---|
100 | * Helper Macro
|
---|
101 | ***/
|
---|
102 | #define XPROTOTYPE_CLASS(class_name) ((XProtoType*)(&class_name::class##class_name))
|
---|
103 |
|
---|
104 | #define IMPL_XPROTOTYPE_INSTANCE(class_name) \
|
---|
105 | XProtoType class_name::class##class_name = \
|
---|
106 | {(XMLByte*) #class_name, class_name::createObject };
|
---|
107 |
|
---|
108 | XERCES_CPP_NAMESPACE_END
|
---|
109 |
|
---|
110 | #endif
|
---|