source: NonGTP/Xerces/xerces/include/xercesc/internal/XSerializable.hpp @ 358

Revision 358, 4.1 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 1999-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: XSerializable.hpp,v 1.4 2004/09/08 13:56:14 peiyongz Exp $
19 * $Log: XSerializable.hpp,v $
20 * Revision 1.4  2004/09/08 13:56:14  peiyongz
21 * Apache License Version 2.0
22 *
23 * Revision 1.3  2003/10/29 16:16:08  peiyongz
24 * GrammarPool' serialization/deserialization support
25 *
26 * Revision 1.2  2003/09/23 18:12:19  peiyongz
27 * Macro re-organized: provide create/nocreate macros for abstract and
28 * nonabstract classes
29 *
30 * Revision 1.1  2003/09/18 18:31:24  peiyongz
31 * OSU: Object Serialization Utilities
32 *
33 *
34 */
35
36#if !defined(XSERIALIZABLE_HPP)
37#define XSERIALIZABLE_HPP
38
39#include <xercesc/internal/XSerializeEngine.hpp>
40#include <xercesc/internal/XProtoType.hpp>
41
42XERCES_CPP_NAMESPACE_BEGIN
43
44class XMLUTIL_EXPORT XSerializable
45{
46public :
47
48    // -----------------------------------------------------------------------
49    //  Constructors and Destructor
50    // -----------------------------------------------------------------------
51    virtual ~XSerializable() {} ;
52
53    // -----------------------------------------------------------------------
54    //  Serialization Interface
55    // -----------------------------------------------------------------------   
56    virtual bool        isSerializable()               const = 0;
57
58    virtual void        serialize(XSerializeEngine& )        = 0;
59
60    virtual XProtoType* getProtoType()                 const = 0;
61
62protected:
63    XSerializable(){} ;
64
65private:
66    // -----------------------------------------------------------------------
67    //  Unimplemented copy ctor and assignment operator
68    // -----------------------------------------------------------------------
69        XSerializable(const XSerializable& );             
70        XSerializable& operator=(const XSerializable&);
71
72};
73
74inline void XSerializable::serialize(XSerializeEngine& )
75{
76}
77
78/***
79 * Macro to be included in XSerializable derivatives'
80 * declaration's public section
81 ***/
82#define DECL_XSERIALIZABLE(class_name) \
83public: \
84\
85DECL_XPROTOTYPE(class_name) \
86\
87virtual bool                    isSerializable()                  const ;  \
88virtual XProtoType*             getProtoType()                    const;   \
89virtual void                    serialize(XSerializeEngine&); \
90friend  class XObjectComparator;   \
91friend  class XTemplateComparator; \
92\
93inline friend XSerializeEngine& operator>>(XSerializeEngine& serEng  \
94                                         , class_name*&      objPtr) \
95{objPtr = (class_name*) serEng.read(XPROTOTYPE_CLASS(class_name));   \
96 return serEng; \
97};
98       
99/***
100 * Macro to be included in the implementation file
101 * of XSerializable derivatives' which is instantiable
102 ***/
103#define IMPL_XSERIALIZABLE_TOCREATE(class_name) \
104IMPL_XPROTOTYPE_TOCREATE(class_name) \
105IMPL_XSERIAL(class_name)
106
107/***
108 * Macro to be included in the implementation file
109 * of XSerializable derivatives' which is UN-instantiable
110 ***/
111#define IMPL_XSERIALIZABLE_NOCREATE(class_name) \
112IMPL_XPROTOTYPE_NOCREATE(class_name) \
113IMPL_XSERIAL(class_name)
114
115/***
116 * Helper Macro
117 ***/
118#define IMPL_XSERIAL(class_name) \
119bool        class_name::isSerializable() const \
120{return true; } \
121XProtoType* class_name::getProtoType()   const \
122{return XPROTOTYPE_CLASS(class_name); }
123
124#define IS_EQUIVALENT(lptr, rptr) \
125    if (lptr == rptr)             \
126        return true;              \
127    if (( lptr && !rptr) || (!lptr &&  rptr))  \
128        return false;
129
130XERCES_CPP_NAMESPACE_END
131
132#endif
133
Note: See TracBrowser for help on using the repository browser.