TAO_TIO.cpp

Go to the documentation of this file.
00001 // $Id: TAO_TIO.cpp 77001 2007-02-12 07:54:49Z johnnyw $
00002 
00003 #include "orbsvcs/Time/TAO_TIO.h"
00004 
00005 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00006 
00007 // Constructor.
00008 TAO_TIO::TAO_TIO (TimeBase::TimeT lower,
00009                   TimeBase::TimeT upper)
00010 {
00011   this->attr_time_interval.lower_bound = lower;
00012   this->attr_time_interval.upper_bound = upper;
00013 }
00014 
00015 // Destructor.
00016 TAO_TIO::~TAO_TIO (void)
00017 {
00018 }
00019 
00020 // This is the get method for the attribute time interval.
00021 
00022 TimeBase::IntervalT
00023 TAO_TIO::time_interval (void)
00024 {
00025   return attr_time_interval;
00026 }
00027 
00028 // This operation returns a value of type OverlapType depending on how
00029 // the interval in the object and the time range represented by the
00030 // parameter UTO overlap.  If OverlapType is not OTNoOverlap, then the
00031 // out parameter overlap contains the overlap interval, otherwise the
00032 // out parameter contains the gap between the two intervals.
00033 
00034 CosTime::OverlapType
00035 TAO_TIO::spans (CosTime::UTO_ptr uto,
00036                 CosTime::TIO_out overlap)
00037 {
00038   TAO_TIO *tio = 0;
00039 
00040   try
00041     {
00042       TimeBase::TimeT lb1 =
00043         this->time_interval ().lower_bound;
00044 
00045       TimeBase::TimeT up1 =
00046         this->time_interval ().upper_bound;
00047 
00048       TimeBase::TimeT tmp1 = uto->time ();
00049 
00050       TimeBase::TimeT tmp2 = uto->inaccuracy ();
00051 
00052       TimeBase::TimeT lb2 = tmp1 - tmp2;
00053 
00054 
00055       tmp1 = uto->time ();
00056 
00057       tmp2 = uto->inaccuracy ();
00058 
00059       TimeBase::TimeT up2 = tmp1 + tmp2;
00060 
00061       if (lb1 == lb2 && up1 == up2)
00062         {
00063           ACE_NEW_RETURN (tio,
00064                           TAO_TIO (lb1, up1),
00065                           CosTime::OTNoOverlap);
00066           overlap = tio->_this ();
00067 
00068           return CosTime::OTOverlap;
00069         }
00070       else if (lb1 > lb2 && up1 < up2)
00071         {
00072           ACE_NEW_RETURN (tio,
00073                           TAO_TIO (lb1, up1),
00074                           CosTime::OTNoOverlap);
00075 
00076           overlap = tio->_this ();
00077 
00078           return CosTime::OTContained;
00079         }
00080       else if (lb1 < lb2 && up1 > up2)
00081         {
00082           ACE_NEW_RETURN (tio,
00083                           TAO_TIO (lb2, up2),
00084                           CosTime::OTNoOverlap);
00085 
00086           overlap = tio->_this ();
00087 
00088           return CosTime::OTContained;
00089         }
00090       else if (lb1 < lb2)
00091         {
00092           if (up1 < lb2)
00093             {
00094               ACE_NEW_RETURN (tio,
00095                               TAO_TIO (0, 0),
00096                               CosTime::OTNoOverlap);
00097 
00098               overlap = tio->_this ();
00099 
00100               return CosTime::OTNoOverlap;
00101             }
00102           else
00103             {
00104               ACE_NEW_RETURN (tio,
00105                               TAO_TIO (lb2, up1),
00106                               CosTime::OTNoOverlap);
00107               overlap = tio->_this ();
00108 
00109               return CosTime::OTOverlap;
00110             }
00111         }
00112       else if (up2 < lb1)
00113         {
00114 
00115           ACE_NEW_RETURN (tio,
00116                           TAO_TIO (0, 0),
00117                           CosTime::OTNoOverlap);
00118 
00119           overlap = tio->_this ();
00120 
00121           return CosTime::OTNoOverlap;
00122         }
00123       else
00124         {
00125           ACE_NEW_RETURN (tio,
00126                           TAO_TIO (lb1, up2),
00127                           CosTime::OTNoOverlap);
00128 
00129           overlap = tio->_this ();
00130         }
00131     }
00132   catch (const CORBA::Exception& ex)
00133     {
00134       ex._tao_print_exception ("Exception:");
00135     }
00136 
00137   return CosTime::OTNoOverlap;
00138 }
00139 
00140 // This operation returns a value of type OverlapType depending on how
00141 // the interval in the object and interval in the parameter TIO
00142 // overlap. If OverlapType is not OTNoOverlap, then the out parameter
00143 // overlap contains the overlap interval, otherwise the out parameter
00144 // contains the gap between the two intervals.
00145 
00146 CosTime::OverlapType
00147 TAO_TIO::overlaps (CosTime::TIO_ptr tio,
00148                    CosTime::TIO_out overlap)
00149 {
00150   TAO_TIO *tio_i = 0;
00151 
00152   TimeBase::TimeT lb1 =
00153     this->time_interval ().lower_bound;
00154 
00155   TimeBase::TimeT up1 =
00156     this->time_interval ().upper_bound;
00157 
00158   TimeBase::TimeT lb2 =
00159     tio->time_interval ().lower_bound;
00160 
00161   TimeBase::TimeT up2 =
00162     tio->time_interval ().upper_bound;
00163 
00164   if (lb1 == lb2 && up1 == up2)
00165     {
00166       ACE_NEW_THROW_EX (tio_i,
00167                         TAO_TIO (lb1, up1),
00168                         CORBA::NO_MEMORY ());
00169 
00170 
00171       overlap = tio_i->_this ();
00172 
00173       return CosTime::OTOverlap;
00174     }
00175   else if (lb1 > lb2 && up1 < up2)
00176     {
00177       ACE_NEW_THROW_EX (tio_i,
00178                         TAO_TIO (lb1, up1),
00179                         CORBA::NO_MEMORY ());
00180 
00181       overlap = tio_i->_this ();
00182 
00183       return CosTime::OTContained;
00184     }
00185   else if (lb1 < lb2 && up1 > up2)
00186     {
00187       ACE_NEW_THROW_EX (tio_i,
00188                         TAO_TIO (lb2, up2),
00189                         CORBA::NO_MEMORY ());
00190 
00191       overlap = tio_i->_this ();
00192 
00193       return CosTime::OTContained;
00194     }
00195   else if (lb1 < lb2)
00196     {
00197       if (up1 < lb2)
00198         {
00199           ACE_NEW_THROW_EX (tio_i,
00200                             TAO_TIO (0, 0),
00201                             CORBA::NO_MEMORY ());
00202           overlap = tio_i->_this ();
00203 
00204           return CosTime::OTNoOverlap;
00205         }
00206       else
00207         {
00208           ACE_NEW_THROW_EX (tio_i,
00209                             TAO_TIO (lb2, up1),
00210                             CORBA::NO_MEMORY ());
00211 
00212           overlap = tio_i->_this ();
00213 
00214           return CosTime::OTOverlap;
00215         }
00216     }
00217   else if (up2 < lb1)
00218     {
00219       ACE_NEW_THROW_EX (tio_i,
00220                         TAO_TIO (0, 0),
00221                         CORBA::NO_MEMORY ());
00222 
00223       overlap = tio_i->_this ();
00224 
00225       return CosTime::OTNoOverlap;
00226     }
00227   else
00228     {
00229       ACE_NEW_THROW_EX (tio_i,
00230                         TAO_TIO (lb1, up2),
00231                         CORBA::NO_MEMORY ());
00232       overlap = tio_i->_this ();
00233     }
00234 
00235   return CosTime::OTNoOverlap;
00236 }
00237 
00238 CosTime::UTO_ptr
00239 TAO_TIO::time (void)
00240 {
00241   TAO_UTO *uto = 0;
00242 
00243   ACE_NEW_THROW_EX (uto,
00244                     TAO_UTO ((this->time_interval ().upper_bound -
00245                               this->time_interval ().lower_bound) / 2,
00246                              this->time_interval ().upper_bound -
00247                              this->time_interval ().lower_bound,
00248                              0),
00249                     CORBA::NO_MEMORY ());
00250 
00251 
00252   return uto->_this ();
00253 }
00254 
00255 TAO_END_VERSIONED_NAMESPACE_DECL

Generated on Tue Feb 2 17:49:17 2010 for TAO_CosTime by  doxygen 1.4.7