3 * MICO --- an Open Source CORBA implementation
4 * Copyright (c) 1997-2001 by The Mico Team
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.
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.
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.
20 * For more information, visit the MICO Home Page at
21 * http://www.mico.org/
24 #ifndef __mico_value_h__
25 #define __mico_value_h__
31 // begin-mico-extension
32 static ValueBase *_create (const std::vector<std::string> &repoids,
33 const std::string &myrepoid);
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;
42 static ValueBase *_downcast (ValueBase *);
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 *);
53 ValueBase (const ValueBase &);
54 virtual ~ValueBase ();
56 // begin-mico-extension
57 virtual void _get_marshal_info (std::vector<std::string> &repoids,
59 virtual void _marshal_members (DataEncoder &ec);
60 virtual Boolean _demarshal_members (DataDecoder &dc);
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 ();
71 void operator= (const ValueBase&);
74 typedef ValueVar<ValueBase> ValueBase_var;
75 typedef ValueOut<ValueBase> ValueBase_out;
77 static inline void add_ref (ValueBase *vb)
83 static inline void remove_ref (ValueBase *vb)
89 class DefaultValueRefCountBase :
90 virtual public ServerlessObject,
91 virtual public ValueBase
94 DefaultValueRefCountBase ();
95 virtual ~DefaultValueRefCountBase ();
97 void _add_ref () { _ref(); }
102 else if (!_destructing && _count_refs () == -1) {
103 // orphaned circular graph
109 ULong _refcount_value () { return _refcnt(); }
112 void operator= (const DefaultValueRefCountBase &);
115 // begin-mico-extension
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.
123 class SimpleValueRefCountBase :
124 virtual public ServerlessObject,
125 virtual public ValueBase
128 SimpleValueRefCountBase ();
129 virtual ~SimpleValueRefCountBase ();
131 void _add_ref () { _ref(); }
132 void _remove_ref () {
137 ULong _refcount_value () { return _refcnt(); }
140 void operator= (const SimpleValueRefCountBase &);
142 // end-mico-extension
144 class ValueFactoryBase;
145 typedef ValueFactoryBase *ValueFactory;
146 typedef ValueVar<ValueFactoryBase> ValueFactoryBase_var;
148 class ValueFactoryBase : public ServerlessObject {
150 virtual ~ValueFactoryBase ();
152 virtual void _add_ref () { _ref(); }
153 virtual void _remove_ref () { if (_deref()) delete this; }
155 static ValueFactory _downcast (ValueFactory);
157 // begin-mico-extension
158 virtual void * _narrow_helper (const char *);
159 // end-mico-extension
166 virtual ValueBase *create_for_unmarshal () = 0;
169 //-------------------
172 typedef AbstractBase *AbstractBase_ptr;
176 virtual ~AbstractBase () = 0;
178 static AbstractBase_ptr _nil ()
182 static AbstractBase_ptr _duplicate (AbstractBase_ptr);
183 static AbstractBase_ptr _narrow (AbstractBase_ptr);
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
195 AbstractBase (const AbstractBase &);
198 typedef ObjVar<AbstractBase> AbstractBase_var;
199 typedef AbstractBase_var AbstractBase_out;
201 extern void release (AbstractBase_ptr);
202 static inline Boolean is_nil (AbstractBase_ptr ab)
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.
214 virtual public AbstractBase,
215 virtual public Object
218 virtual ~MixedBase () = 0;
221 static inline void release (MixedBase *mb)
223 CORBA::release ((Object_ptr) mb);
226 static inline Boolean is_nil (MixedBase *mb)
228 return CORBA::is_nil ((Object_ptr) mb);
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.
237 class UnknownAbstract : virtual public AbstractBase
240 UnknownAbstract (Object_ptr, ValueBase *);
243 Object_ptr _to_object ();
244 ValueBase * _to_value ();
245 void * _narrow_helper (const char *);
254 #endif // __mico_value_h__