summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/CORBA_Utils_T.h
blob: 8abf180d9e1650caddc168c24a759265b9c6217d (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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//    ace_orb
// 
// = FILENAME
//    CORBA_Utilities.h
//
// = AUTHORS
//    Tim Harrison.
//
// = NOTE
//   This class is a bit ackward when using a real ORB, but we cannot
//   easily remove it since some of the types are used in the
//   implementation of the EC. TODO
// 
// ============================================================================

#if !defined (ACE_CORBA_UTILS_H)
#define ACE_CORBA_UTILS_H

#include "ace/Time_Value.h"
#include "tao/corba.h"

template <class TYPE>
class ACE_CORBA_Sequence// : public CORBA::Object
// = TITLE
//
// = DESCRIPTION
{
public:

  ACE_CORBA_Sequence (const ACE_CORBA_Sequence<TYPE> &source);
  // Copy construction.

  ACE_CORBA_Sequence (CORBA::ULong max);
  ACE_CORBA_Sequence (CORBA::ULong max, 
		      CORBA::ULong length, 
		      TYPE* data, 
		      CORBA::Boolean release = 0);
  ACE_CORBA_Sequence (void);

  virtual ~ACE_CORBA_Sequence (void);

  ACE_CORBA_Sequence<TYPE> &operator= (const ACE_CORBA_Sequence<TYPE> &);

  // static TYPE* allocbuf(CORBA::ULong nelems);
  // static void freebuf(TYPE* data);

  CORBA::ULong maximum (void) const;
  CORBA::ULong length (void) const;
  void length (CORBA::ULong len);

  TYPE& operator [] (CORBA::ULong IT_i);

  const TYPE& operator [] (CORBA::ULong IT_i) const;

  virtual TYPE *new_array (size_t len);
  // Allocates TYPE[len].  This facilitates template methods through
  // template specialization to allow the use of different memory
  // pools.

  virtual void delete_array (TYPE *buf, size_t len);
  // delete [] <buf>.

protected:
  CORBA::ULong maximum_;
  CORBA::ULong length_;
  TYPE* buffer_;
  unsigned char release_;
};

// Utility for debugging sequences.
//template <class TYPE>
//void dump (const ACE_CORBA_Sequence<TYPE> &seq);

// Utility for appending single items.  Increases the length of <set>
// and adds <event> to the end of <set>.
template <class TYPE> void
operator += (ACE_CORBA_Sequence<TYPE> &seq,
	     const TYPE &item)
{
  CORBA::ULong length = seq.length ();
  seq.length (length + 1);
  seq[length] = item;
}

// Utility for appending sequences.
template <class TYPE> void
operator += (ACE_CORBA_Sequence<TYPE> &dest, 
	     const ACE_CORBA_Sequence<TYPE> &source);

template <class TYPE> void
remove_item (TYPE &seq, CORBA::ULong index)
{
  int new_length = seq.length () - 1;

  // Shift the set back one, starting at <index>.
  for (int x = index; x < new_length; x++)
    seq[x] = seq[x+1];

  // Set the new length.
  seq.length (new_length);
}
// Removes seq[index] by moving everything after <index> back and
// decrementing the length.

// ************************************************************

template <class TYPE>
class ACE_CORBA_var
// = TITLE
//
// = DESCRIPTION
{
public:
  ACE_CORBA_var (const ACE_CORBA_var<TYPE> &source);
  ACE_CORBA_var (void);
  ACE_CORBA_var (TYPE *source);
  ~ACE_CORBA_var (void);
  ACE_CORBA_var<TYPE> &operator= (TYPE *source);
  ACE_CORBA_var<TYPE> &operator= (const ACE_CORBA_var<TYPE> &source);
  TYPE *operator->(void);
  operator TYPE *(void) const;
  //  operator TYPE *&(void);
  operator TYPE &(void) const;
private:
  TYPE *me_;
};

// ************************************************************

/*
template <class IMPL>
class ACE_CORBA_Object_Ref : public CORBA::Object
// = TITLE
//    ACE CORBA Object Reference
//
// = DESCRIPTION
//    A wrapper for making CORBA Object References.  For a single
//    address space ORB, this points directly to the IMPL
//    class.  This is supposed to look like a pointer to
//    IMPL with an additional static _duplicate method.
{
public:
  // ACE_CORBA_Object_Ref (ACE_CORBA_Object_Ref<IMPL> &obj);
  ACE_CORBA_Object_Ref (void);
  ACE_CORBA_Object_Ref (IMPL *impl);
  ~ACE_CORBA_Object_Ref (void);
  //  ACE_CORBA_Object_Ref<IMPL> &operator= (IMPL *source);
  ACE_CORBA_Object_Ref<IMPL> &operator= 
    (const ACE_CORBA_Object_Ref<IMPL> &source);
  
  IMPL *operator->(void);
  // A distributed ORB would require that the CORBA Object Reference
  // implement all IMPL interfaces, marshall the parameters,
  // and transmit over IIOP.  For this single address space ORB, we'll
  // just delegate method calls to the IMPL directly.

  operator IMPL *(void) const;
  // operator IMPL *&(void);
  // operator IMPL &(void) const;

  static ACE_CORBA_Object_Ref<IMPL> *_duplicate 
    (ACE_CORBA_Object_Ref<IMPL> *source);

private:
  IMPL *impl_;
};
*/

// ************************************************************

template <class ITEM, size_t SIZE>
class ACE_ES_Simple_Array
// = TITLE
//    Simple Array
//
// = DESCRIPTION
//    Wraps ITEM[SIZE] with insert and an iterator.  There is no
//    remove.  It allows duplicates.  It is truly very simple.
{
 public:
  ACE_ES_Simple_Array (void);
  int insert (const ITEM &copy_me);
  size_t size (void);
  ITEM *data (void);
 protected:
  ITEM data_[SIZE];
  size_t size_;
};

template <class ITEM>
class ACE_ES_Array_Iterator
// = TITLE
//    Simple Iterator
//
// = DESCRIPTION
//    Iterates through an array of ITEMs.
{
public:
  ACE_ES_Array_Iterator (ITEM *data, size_t size);

  int next (ITEM *&next_item);
  // Returns 0 when all items have been seen, else 1.  Sets
  // <next_item> to point at the next ITEM.

  int advance (void);
  // Move forward by one element in the Stack.  Returns 0 when all the
  // items in the Stack have been seen, else 1.

  int done (void) const;
  // Returns 1 when all items have been seen, else 0.

private:
  ITEM *data_;
  size_t size_;
  size_t index_;
};

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

#if defined (ACE_TEMPLATES_REQUIRE_SOURCE)
#include "CORBA_Utils_T.cpp"
#endif /* ACE_TEMPLATES_REQUIRE_SOURCE */

#if defined (ACE_TEMPLATES_REQUIRE_PRAGMA)
#pragma implementation ("CORBA_Utils_T.cpp")
#endif /* ACE_TEMPLATES_REQUIRE_PRAGMA */

#endif /* ACE_CORBA_UTILS_H */