summaryrefslogtreecommitdiff
path: root/TAO/tao/ValueFactory.h
blob: 9d682aa227b135d6c369e970fc786fd7296b37a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// This may look like C, but it's really -*- C++ -*-

//=============================================================================
/**
 *  @file     ValueFactory.h
 *
 *  $Id$
 *
 *  @author  Torsten Kuepper  <kuepper2@lfa.uni-wuppertal.de>
 */
//=============================================================================


#ifndef TAO_VALUEFACTORY_H
#define TAO_VALUEFACTORY_H
#include "ace/pre.h"

#include "tao/corbafwd.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "ace/Synch_T.h"

namespace CORBA
{
  class TAO_Export ValueFactoryBase
  {
  public:
    ValueFactoryBase ();
    virtual ~ValueFactoryBase ();

    // non-virtual is non-standard
    void _add_ref (void);
    void _remove_ref (void);

    // private: %!
    /// In a derived class T use return type TAO_OBV_CREATE_RETURN_TYPE (T)
    /// (see at definition below)
    virtual CORBA::ValueBase * create_for_unmarshal (void) = 0;

    // Not pure virtual because this will be overridden only by valuetypes
    // that support an abstract interface.
    virtual CORBA::AbstractBase * create_for_unmarshal_abstract (void);

  private:
    CORBA::ULong _tao_reference_count_;
    TAO_SYNCH_MUTEX _tao_reference_count_lock_;
  }; // CORBA_ValueFactoryBase

  /**
   * @class ValueFactoryBase_var
   *
   * @brief _var class for ValueFactoryBase
   */
  class TAO_Export ValueFactoryBase_var
  {
  public:
    ValueFactoryBase_var (void);
    ValueFactoryBase_var (CORBA::ValueFactoryBase *);
    ValueFactoryBase_var (const ValueFactoryBase_var &);
    ~ValueFactoryBase_var (void);

    ValueFactoryBase_var &operator= (CORBA::ValueFactoryBase *);
    ValueFactoryBase_var &operator= (const ValueFactoryBase_var &);
    CORBA::ValueFactoryBase *operator-> (void) const;

    /// in, inout, out, _retn
    CORBA::ValueFactoryBase *in (void) const;
    CORBA::ValueFactoryBase *&inout (void);
    CORBA::ValueFactoryBase *&out (void);
    CORBA::ValueFactoryBase *_retn (void);
    CORBA::ValueFactoryBase *ptr (void) const;

  private:
    CORBA::ValueFactoryBase *ptr_;
  };

}  // End CORBA namespace

// Use this macro for writing code that is independend from
// the compiler support of covariant return types of pointers to
// virtual inherited classes.
// (e.g. in egcs-2.90.29 980515 (egcs-1.0.3 release) its not yet implemented)
// (But it is TAO specific and at the moment the covariant case is not
// elaborated --- its just a suggestion.)

#ifdef TAO_HAS_OBV_COVARIANT_RETURN
#  define TAO_OBV_CREATE_RETURN_TYPE(TYPE) TYPE *
#else /*  TAO_HAS_OBV_COVARIANT_RETURN */
#  define TAO_OBV_CREATE_RETURN_TYPE(TYPE) CORBA::ValueBase *
#endif /* TAO_HAS_OBV_COVARIANT_RETURN */

// (The obtaining of the repository id is currently not yet like the OMG way. %!)
//
// Macro for on the fly registration of a factory (with type Factory).
// The repository id is taken from the static repository id of the
// valuetype via tao_repository_id () of the specialized factory.
// It forgets the pre-registered factory (if any) and the reference
// to the newly created one. (A new reference could be obtained with
// orb->lookup_value_factory (char * repo_id) .)

#define TAO_OBV_REGISTER_FACTORY(FACTORY, VALUETYPE) \
  { CORBA::ValueFactory factory = new FACTORY; \
    CORBA::ValueFactory prev_factory = \
    TAO_ORB_Core_instance ()->orb ()->register_value_factory (\
      VALUETYPE::_tao_obv_static_repository_id (),\
                                   factory); \
    if (prev_factory) prev_factory->_remove_ref (); \
    factory->_remove_ref (); }


#if defined (__ACE_INLINE__)
# include "tao/ValueFactory.i"
#endif /* __ACE_INLINE__) */

#include "ace/post.h"

#endif /* TAO_VALUEFACTORY_H */