OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / I386LINUX / util / I386LINUX / include / mico / value.h
1 // -*- c++ -*-
2 /*
3  *  MICO --- an Open Source CORBA implementation
4  *  Copyright (c) 1997-2001 by The Mico Team
5  *
6  *  This library is free software; you can redistribute it and/or
7  *  modify it under the terms of the GNU Library General Public
8  *  License as published by the Free Software Foundation; either
9  *  version 2 of the License, or (at your option) any later version.
10  *
11  *  This library is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  *  Library General Public License for more details.
15  *
16  *  You should have received a copy of the GNU Library General Public
17  *  License along with this library; if not, write to the Free
18  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19  *
20  *  For more information, visit the MICO Home Page at
21  *  http://www.mico.org/
22  */
23
24 #ifndef __mico_value_h__
25 #define __mico_value_h__
26
27 namespace CORBA {
28
29 class ValueBase {
30 protected:
31     // begin-mico-extension
32     static ValueBase *_create (const std::vector<std::string> &repoids,
33                                const std::string &myrepoid);
34     // end-mico-extension
35 public:
36     virtual void _add_ref () = 0;
37     virtual void _remove_ref () = 0;
38     virtual ULong _refcount_value () = 0;
39     virtual ValueBase *_copy_value ();
40     virtual ValueDef_ptr get_value_def () = 0;
41
42     static ValueBase *_downcast (ValueBase *);
43
44     // begin-mico-extension
45     static void _marshal (DataEncoder &ec, ValueBase *vb);
46     static Boolean _demarshal (DataDecoder &dc, ValueBase *&vb,
47                                const std::string &myrepoid);
48     virtual void * _narrow_helper (const char *);
49     // end-mico-extension
50
51 protected:
52     ValueBase ();
53     ValueBase (const ValueBase &);
54     virtual ~ValueBase ();
55
56     // begin-mico-extension
57     virtual void _get_marshal_info (std::vector<std::string> &repoids,
58                                     Boolean &chunked);
59     virtual void _marshal_members (DataEncoder &ec);
60     virtual Boolean _demarshal_members (DataDecoder &dc);
61     // end-mico-extension
62
63 public:
64     // support for arbitrarily recursive ValueTypes
65     typedef std::set<ValueBase *, std::less<ValueBase *> > visited;
66     virtual Long _count_refs (visited * = 0);
67     virtual void _release_members ();
68     bool _destructing;
69
70 private:
71     void operator= (const ValueBase&);
72 };
73
74 typedef ValueVar<ValueBase> ValueBase_var;
75 typedef ValueOut<ValueBase> ValueBase_out;
76
77 static inline void add_ref (ValueBase *vb)
78 {
79     if (vb)
80         vb->_add_ref();
81 }
82
83 static inline void remove_ref (ValueBase *vb)
84 {
85     if (vb)
86         vb->_remove_ref();
87 }
88
89 class DefaultValueRefCountBase :
90   virtual public ServerlessObject,
91   virtual public ValueBase
92 {
93 public:
94   DefaultValueRefCountBase ();
95   virtual ~DefaultValueRefCountBase ();
96
97   void _add_ref () { _ref(); }
98   void _remove_ref () {
99     if (_deref()) {
100       delete this;
101     }
102     else if (!_destructing && _count_refs () == -1) {
103       // orphaned circular graph
104       _add_ref ();
105       _release_members ();
106       delete this;
107     }
108   }
109   ULong _refcount_value () { return _refcnt(); }
110
111 private:
112   void operator= (const DefaultValueRefCountBase &);
113 };
114
115 // begin-mico-extension
116 /*
117  * This class can be used instead of DefaultValueRefCountBase. It does
118  * not check for orphaned circular graphs and is much faster for value
119  * types that are *potentially* recursive but that do not actually
120  * employ recursion, for example lists or trees.
121  */
122
123 class SimpleValueRefCountBase :
124   virtual public ServerlessObject,
125   virtual public ValueBase
126 {
127 public:
128   SimpleValueRefCountBase ();
129   virtual ~SimpleValueRefCountBase ();
130
131   void _add_ref () { _ref(); }
132   void _remove_ref () {
133     if (_deref()) {
134       delete this;
135     }
136   }
137   ULong _refcount_value () { return _refcnt(); }
138
139 private:
140   void operator= (const SimpleValueRefCountBase &);
141 };
142 // end-mico-extension
143
144 class ValueFactoryBase;
145 typedef ValueFactoryBase *ValueFactory;
146 typedef ValueVar<ValueFactoryBase> ValueFactoryBase_var;
147
148 class ValueFactoryBase : public ServerlessObject {
149 public:
150     virtual ~ValueFactoryBase ();
151
152     virtual void _add_ref () { _ref(); }
153     virtual void _remove_ref () { if (_deref()) delete this; }
154
155     static ValueFactory _downcast (ValueFactory);
156
157     // begin-mico-extension
158     virtual void * _narrow_helper (const char *);
159     // end-mico-extension
160
161 protected:
162     ValueFactoryBase ();
163
164 //private:
165 public:
166     virtual ValueBase *create_for_unmarshal () = 0;
167 };
168
169 //-------------------
170
171 class AbstractBase;
172 typedef AbstractBase *AbstractBase_ptr;
173
174 class AbstractBase {
175 public:
176   virtual ~AbstractBase () = 0;
177
178   static AbstractBase_ptr _nil ()
179   {
180     return 0;
181   }
182   static AbstractBase_ptr _duplicate (AbstractBase_ptr);
183   static AbstractBase_ptr _narrow (AbstractBase_ptr);
184
185   // begin-mico-extension
186   virtual Object_ptr _to_object ();
187   virtual ValueBase * _to_value ();
188   static void _marshal (DataEncoder &ec, AbstractBase *vb);
189   static Boolean _demarshal (DataDecoder &dc, AbstractBase *&vb);
190   virtual void * _narrow_helper (const char *);
191   // end-mico-extension
192
193 protected:
194   AbstractBase ();
195   AbstractBase (const AbstractBase &);
196 };
197
198 typedef ObjVar<AbstractBase> AbstractBase_var;
199 typedef AbstractBase_var AbstractBase_out;
200
201 extern void release (AbstractBase_ptr);
202 static inline Boolean is_nil (AbstractBase_ptr ab)
203 {
204   return !ab;
205 }
206
207 /*
208  * We need MixedBase to resolve overloading problems; if a concrete
209  * interface is derived from both AbstractBase and ServerlessObject,
210  * the use of release() is ambiguous.
211  */
212
213 class MixedBase :
214   virtual public AbstractBase,
215   virtual public Object
216 {
217 public:
218   virtual ~MixedBase () = 0;
219 };
220
221 static inline void release (MixedBase *mb)
222 {
223   CORBA::release ((Object_ptr) mb);
224 }
225
226 static inline Boolean is_nil (MixedBase *mb)
227 {
228   return CORBA::is_nil ((Object_ptr) mb);
229 }
230
231 /*
232  * UnknownAbstract is used when unmarshalling an AbstractBase type
233  * where we don't know a concrete type and either represent an Object
234  * or a Valuetype, and support narrowing/downcasting to both.
235  */
236
237 class UnknownAbstract : virtual public AbstractBase
238 {
239 public:
240   UnknownAbstract (Object_ptr, ValueBase *);
241   ~UnknownAbstract ();
242
243   Object_ptr _to_object ();
244   ValueBase * _to_value ();
245   void * _narrow_helper (const char *);
246
247 private:
248   Object_var obj;
249   ValueBase_var val;
250 };
251
252 }
253
254 #endif // __mico_value_h__