summaryrefslogtreecommitdiff
path: root/TAO/tao/MProfile.i
blob: 54c46dc744d6c92cfbb2ab006e7189753c1e4ab0 (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
// This may look like C, but it's really -*- C++ -*-
// $Id$

ACE_INLINE
TAO_MProfile::TAO_MProfile (CORBA::ULong sz)
  :  forward_from_(0),
     pfiles_ (0),
     current_ (0),
     size_ (0),
     last_ (0)
{
  this->set (sz);
}

ACE_INLINE
TAO_MProfile::TAO_MProfile (const TAO_MProfile &mprofiles)
  :  forward_from_(0),
     pfiles_ (0),
     current_ (0),
     size_ (0),
     last_ (0)
{
  this->set (mprofiles);
}

ACE_INLINE TAO_MProfile&
TAO_MProfile::operator= (const TAO_MProfile& rhs)
{
  if (this == &rhs)
    return *this;

  this->set (rhs);
  return *this;
}

ACE_INLINE
TAO_MProfile::~TAO_MProfile (void)
{
  this->cleanup ();
}

// Cyclic get next.  It will simply cycle through the complete list.

ACE_INLINE TAO_Profile *
TAO_MProfile::get_cnext (void)
{
  if (last_ == 0)
      return 0;

  if (current_ == last_)
      current_ = 0;

  return pfiles_[current_++];
}

// This will return the next element until either null is found or the
// end of list.  It then continues to return NULL until rewind.

ACE_INLINE TAO_Profile *
TAO_MProfile::get_next (void)
{
  // Nolist or EndOfList
  if (last_ == 0 || current_ == last_)
    return 0;
  else
    return pfiles_[current_++];
}

ACE_INLINE TAO_Profile *
TAO_MProfile::get_cprev (void)
{
  if (last_ == 0)
    return 0;
  else if (last_ == 1)
    current_=1;
  else if (current_ > 1)
    current_--;
  else // current_ == 0 or 1, 0 => list never read before and == 1
    current_ = last_;

  return pfiles_[current_ - 1];
}

ACE_INLINE TAO_Profile *
TAO_MProfile::get_prev (void)
{
  if (last_ == 0 || current_ <= 1)
    // No List of BeginningOfList
    return 0;
  if (current_ > 1)
    current_--;

  return pfiles_[current_ - 1];
}

// does not affect the current_ setting!

ACE_INLINE TAO_Profile *
TAO_MProfile::get_profile (TAO_PHandle handle)
{
  if (handle < last_)
    return pfiles_[handle];
  else
    return 0;
}

ACE_INLINE TAO_Profile *
TAO_MProfile::get_current_profile (void)
{
  if (last_ == 0)
    return 0;
  if (current_ == 0)
    // means list has not been read before.
    current_ = 1;

  return pfiles_[current_ - 1];
}

ACE_INLINE TAO_PHandle
TAO_MProfile::get_current_handle (void)
{
  if (current_ > 0)
    return current_ - 1;
  else
    return 0;
}

ACE_INLINE void
TAO_MProfile::rewind (void)
{
  current_ = 0;
}

ACE_INLINE int
TAO_MProfile::give_profile (TAO_Profile *pfile)
{
  // skip by the used slots
  if (last_ == size_) // full!
    return -1;

  pfiles_[last_++] = pfile;

  return last_ - 1;
}

ACE_INLINE
void
TAO_MProfile::forward_from (TAO_MProfile *from)
{
  this->forward_from_ = from;
}

ACE_INLINE
TAO_MProfile *
TAO_MProfile::forward_from (void)
{
  return this->forward_from_;
}

ACE_INLINE CORBA::ULong
TAO_MProfile::profile_count (void) const
{
  return this->last_;
}

ACE_INLINE CORBA::ULong
TAO_MProfile::size (void) const
{
  return this->size_;
}

ACE_INLINE const TAO_Profile*
TAO_MProfile::get_profile (CORBA::ULong slot) const
{
  if (slot >= this->last_)
    return 0;
  return this->pfiles_[slot];
}

ACE_INLINE TAO_Profile **
TAO_MProfile::pfiles (void) const
{
  return this->pfiles_;
}


// Not thread safe!
ACE_INLINE int
TAO_MProfile::grow (CORBA::ULong sz)
{
  if (sz <= this->size_)
    return 0;

  // get the additional space
  TAO_Profile **new_pfiles, **old_pfiles;
  ACE_NEW_RETURN (new_pfiles,
                  TAO_Profile *[sz],
                  -1);

  old_pfiles = this->pfiles_;

  // got it, now copy profiles
  for (TAO_PHandle h = 0; h < this->size_; ++h)
    {
      new_pfiles[h] = old_pfiles[h];
      old_pfiles[h] = 0;
    }

  this->pfiles_ = new_pfiles;
  this->size_ = sz;
  delete [] old_pfiles;

  return 0;
}

ACE_INLINE int
TAO_MProfile::add_profile (TAO_Profile *pfile)
{
  // skip by the used slots
  if (last_ == size_) // full!
    {
      if (this->grow (this->size_ + 1) < 0)
        return -1;
    }

  pfiles_[last_++] = pfile;

  if (pfile && pfile->_incr_refcnt () == 0)
    ACE_ERROR_RETURN ((LM_ERROR,
                       "(%P|%t) Unable to increment reference count in add_profile!\n"),
                      -1);
  return last_ - 1;
}