summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Time/TAO_TIO.cpp
blob: eca24247b4e856280ba719505772b74409b30617 (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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
// -*- C++ -*-
// $Id$

#include "TAO_TIO.h"

// Constructor.
TAO_TIO::TAO_TIO (TimeBase::TimeT lower,
		  TimeBase::TimeT upper)
{
  this->attr_time_interval.lower_bound = lower;
  this->attr_time_interval.upper_bound = upper;
}

// Destructor.
TAO_TIO::~TAO_TIO (void)
{
}

// This is the get method for the attribute time interval.

TimeBase::IntervalT
TAO_TIO::time_interval (CORBA::Environment &)
{
  return attr_time_interval;
}

// This operation returns a value of type OverlapType depending on how
// the interval in the object and the time range represented by the
// parameter UTO overlap.  If OverlapType is not OTNoOverlap, then the
// out parameter overlap contains the overlap interval, otherwise the
// out parameter contains the gap between the two intervals.

CosTime::OverlapType
TAO_TIO::spans (CosTime::UTO_ptr uto,
		CosTime::TIO_out overlap,
		CORBA::Environment &)
{
  TAO_TIO *tio = 0;

  TAO_TRY
    {
      TimeBase::TimeT lb1 =
	this->time_interval (TAO_TRY_ENV).lower_bound;
      TimeBase::TimeT up1 =
	this->time_interval (TAO_TRY_ENV).upper_bound;
      TimeBase::TimeT lb2 =
	uto->time (TAO_TRY_ENV) - uto->inaccuracy (TAO_TRY_ENV);
      TimeBase::TimeT up2 =
	uto->time (TAO_TRY_ENV) + uto->inaccuracy (TAO_TRY_ENV);

      TAO_CHECK_ENV;

      if (lb1 == lb2 && up1 == up2)
	{
	  ACE_NEW_RETURN (tio,
			  TAO_TIO (lb1, up1),
			  CosTime::OTNoOverlap);
	  overlap = tio->_this ();

	  return CosTime::OTOverlap;
	}
      else if (lb1 > lb2 && up1 < up2)
	{
	  ACE_NEW_RETURN (tio,
			  TAO_TIO (lb1, up1),
			  CosTime::OTNoOverlap);

	  overlap = tio->_this ();

	  return CosTime::OTContained;
	}
      else if (lb1 < lb2 && up1 > up2)
	{
	  ACE_NEW_RETURN (tio,
			  TAO_TIO (lb2, up2),
			  CosTime::OTNoOverlap);

	  overlap = tio->_this ();

	  return CosTime::OTContained;
	}
      else if (lb1 < lb2)
	{
	  if (up1 < lb2)
	    {
	      ACE_NEW_RETURN (tio,
			      TAO_TIO (0, 0),
			      CosTime::OTNoOverlap);

	      overlap = tio->_this ();

	      return CosTime::OTNoOverlap;
	    }
	  else
	    {
	      ACE_NEW_RETURN (tio,
			      TAO_TIO (lb2, up1),
			      CosTime::OTNoOverlap);
	      overlap = tio->_this ();

	      return CosTime::OTOverlap;
	    }
	}
      else if (up2 < lb1)
	{

	  ACE_NEW_RETURN (tio,
			  TAO_TIO (0, 0),
			  CosTime::OTNoOverlap);

	  overlap = tio->_this ();

	  return CosTime::OTNoOverlap;
	}
      else
	{
	  ACE_NEW_RETURN (tio,
			  TAO_TIO (lb1, up2),
			  CosTime::OTNoOverlap);

	  overlap = tio->_this ();

	}
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
    }
  TAO_ENDTRY;

  return CosTime::OTNoOverlap;
}

// This operation returns a value of type OverlapType depending on how
// the interval in the object and interval in the parameter TIO
// overlap. If OverlapType is not OTNoOverlap, then the out parameter
// overlap contains the overlap interval, otherwise the out parameter
// contains the gap between the two intervals.

CosTime::OverlapType
TAO_TIO::overlaps (CosTime::TIO_ptr tio,
		   CosTime::TIO_out overlap,
		   CORBA::Environment &)
{
  TAO_TIO *tio_i = 0;

  TAO_TRY
    {
      TimeBase::TimeT lb1 =
	this->time_interval (TAO_TRY_ENV).lower_bound;
      TimeBase::TimeT up1 =
	this->time_interval (TAO_TRY_ENV).upper_bound;
      TimeBase::TimeT lb2 =
	tio->time_interval (TAO_TRY_ENV).lower_bound;
      TimeBase::TimeT up2 =
	tio->time_interval (TAO_TRY_ENV).upper_bound;

      TAO_CHECK_ENV;

      if (lb1 == lb2 && up1 == up2)
	{
	  ACE_NEW_RETURN (tio_i,
			  TAO_TIO (lb1, up1),
			  CosTime::OTNoOverlap);

	  overlap = tio_i->_this ();

	  return CosTime::OTOverlap;
	}
      else if (lb1 > lb2 && up1 < up2)
	{
	  ACE_NEW_RETURN (tio_i,
			  TAO_TIO (lb1, up1),
			  CosTime::OTNoOverlap);

	  overlap = tio_i->_this ();

	  return CosTime::OTContained;
	}
      else if (lb1 < lb2 && up1 > up2)
	{
	  ACE_NEW_RETURN (tio_i,
			  TAO_TIO (lb2, up2),
			  CosTime::OTNoOverlap);

	  overlap = tio_i->_this ();

	  return CosTime::OTContained;
	}
      else if (lb1 < lb2)
	{
	  if (up1 < lb2)
	    {
	      ACE_NEW_RETURN (tio_i,
			      TAO_TIO (0, 0),
			      CosTime::OTNoOverlap);

	      overlap = tio_i->_this ();

	      return CosTime::OTNoOverlap;
	    }
	  else
	    {
	      ACE_NEW_RETURN (tio_i,
			      TAO_TIO (lb2, up1),
			      CosTime::OTNoOverlap);

	      overlap = tio_i->_this ();

	      return CosTime::OTOverlap;
	    }
	}
      else if (up2 < lb1)
	{
	  ACE_NEW_RETURN (tio_i,
			  TAO_TIO (0, 0),
			  CosTime::OTNoOverlap);

	  overlap = tio_i->_this ();

	  return CosTime::OTNoOverlap;
	}
      else
	{
	  ACE_NEW_RETURN (tio_i,
			  TAO_TIO (lb1, up2),
			  CosTime::OTNoOverlap);

	  overlap = tio_i->_this ();

	}
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
    }
  TAO_ENDTRY;

  return CosTime::OTNoOverlap;
}

CosTime::UTO_ptr
TAO_TIO::time (CORBA::Environment &TAO_IN_ENV)
{
  TAO_UTO *uto = 0;

  TAO_TRY
    {
      ACE_NEW_THROW_RETURN (uto,
			    TAO_UTO ((this->time_interval (TAO_TRY_ENV).upper_bound -
				      this->time_interval (TAO_TRY_ENV).lower_bound) / 2,
				     this->time_interval (TAO_TRY_ENV).upper_bound -
				     this->time_interval (TAO_TRY_ENV).lower_bound,
				     0),
			    CORBA::NO_MEMORY (CORBA::COMPLETED_NO),
			    CosTime::UTO::_nil ());
      TAO_CHECK_ENV;
    }
  TAO_CATCHANY
    {
      TAO_TRY_ENV.print_exception ("Exception:");
      return CosTime::UTO::_nil ();
    }
  TAO_ENDTRY;
  return uto->_this ();
}