Definitions.h

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #ifndef OPENDDS_DCPS_DEFINITION_H
00009 #define OPENDDS_DCPS_DEFINITION_H
00010 
00011 #include "Cached_Allocator_With_Overflow_T.h"
00012 #include "dds/DdsDcpsInfoUtilsC.h"
00013 #include "dds/DdsDcpsInfrastructureC.h"
00014 #include "dds/DCPS/Serializer.h"
00015 #include "ace/Message_Block.h"
00016 #include "ace/Global_Macros.h"
00017 
00018 #include <functional>
00019 #include <utility>
00020 
00021 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00022 #pragma once
00023 #endif /* ACE_LACKS_PRAGMA_ONCE */
00024 
00025 // More strict check than ACE does: if we have GNU lib C++ without support for
00026 // wchar_t (std::wstring, std::wostream, etc.) then we don't have DDS_HAS_WCHAR
00027 #if defined (ACE_HAS_WCHAR) && \
00028     (!defined (_GLIBCPP_VERSION) || defined(_GLIBCPP_USE_WCHAR_T)) && \
00029     !defined (__ANDROID__)
00030 #define DDS_HAS_WCHAR
00031 #endif
00032 
00033 #define OPENDDS_DELETED_COPY_CTOR_ASSIGN(CLASS)         \
00034   ACE_UNIMPLEMENTED_FUNC(CLASS(const CLASS&))           \
00035   ACE_UNIMPLEMENTED_FUNC(CLASS& operator=(const CLASS&))
00036 
00037 // If features content_filtered_topic, multi_topic, and query_condition
00038 // are all disabled, define a macro to indicate common code these
00039 // three features depend on should not be built.
00040 #if defined(OPENDDS_NO_QUERY_CONDITION) && defined(OPENDDS_NO_CONTENT_FILTERED_TOPIC) && defined(OPENDDS_NO_MULTI_TOPIC)
00041 #define OPENDDS_NO_CONTENT_SUBSCRIPTION_PROFILE
00042 #endif
00043 
00044 namespace OpenDDS {
00045 namespace DCPS {
00046 
00047 typedef ACE_UINT16 CoherencyGroup;
00048 typedef RepoId PublicationId;
00049 typedef RepoId SubscriptionId;
00050 
00051 /// Sequence number abstraction.  Only allows positive 64 bit values.
00052 class OpenDDS_Dcps_Export SequenceNumber {
00053 public:
00054   typedef ACE_INT64 Value;
00055   /// Construct with a value, default to one (starting point).
00056   SequenceNumber(Value value = MIN_VALUE) {
00057     setValue(value);
00058   }
00059 
00060   /// Pre-increment.
00061   SequenceNumber& operator++() {
00062     if (this->low_ == ACE_UINT32_MAX) {
00063       if (this->high_ == ACE_INT32_MAX) {
00064         // this code is here, despite the RTPS spec statement:
00065         // "sequence numbers never wrap"
00066         this->high_ = 0;
00067         this->low_ = 1;
00068       } else {
00069         ++this->high_;
00070         this->low_ = 0;
00071       }
00072     } else {
00073       ++this->low_;
00074     }
00075     return *this ;
00076   }
00077 
00078   /// Post-increment.
00079   SequenceNumber operator++(int) {
00080     SequenceNumber value(*this);
00081     ++*this;
00082     return value ;
00083   }
00084 
00085   SequenceNumber previous() const {
00086     SequenceNumber retVal(*this);
00087     if ((this->low_ == 1) && (this->high_ == 0)) {
00088       retVal.high_ = ACE_INT32_MAX;
00089       retVal.low_  = ACE_UINT32_MAX;
00090       return retVal;
00091     }
00092     if (this->low_ == 0) {
00093       --retVal.high_;
00094       retVal.low_ = ACE_UINT32_MAX;
00095     } else {
00096       --retVal.low_;
00097     }
00098     return retVal ;
00099   }
00100 
00101   void setValue(Value value) {
00102     if (value < MIN_VALUE) {
00103       value = MIN_VALUE;
00104     }
00105     this->high_ = ACE_INT32(value / LOW_BASE);
00106     this->low_  = ACE_UINT32(value % LOW_BASE);
00107   }
00108 
00109   void setValue(ACE_INT32 high, ACE_UINT32 low) {
00110     this->high_ = high;
00111     this->low_ = low;
00112     if (this->getValue() < MIN_VALUE) {
00113       this->setValue(MIN_VALUE);
00114     }
00115   }
00116 
00117   Value getValue() const {
00118     return LOW_BASE * this->high_ + this->low_;
00119   }
00120 
00121   bool operator<(const SequenceNumber& rvalue) const {
00122     return (this->high_ < rvalue.high_)
00123       || (this->high_ == rvalue.high_ && this->low_ < rvalue.low_);
00124   }
00125 
00126   /// Derive a full suite of logical operations.
00127   bool operator==(const SequenceNumber& rvalue) const {
00128     return (this->high_ == rvalue.high_) &&
00129            (this->low_ == rvalue.low_) ;
00130   }
00131   bool operator!=(const SequenceNumber& rvalue) const {
00132     return (this->high_ != rvalue.high_) ||
00133            (this->low_ != rvalue.low_) ;
00134   }
00135   bool operator>=(const SequenceNumber& rvalue) const {
00136     return !(*this  < rvalue);
00137   }
00138   bool operator<=(const SequenceNumber& rvalue) const {
00139     return !(rvalue < *this);
00140   }
00141   bool operator>(const SequenceNumber& rvalue) const {
00142     return (rvalue < *this)
00143            && (*this != rvalue);
00144   }
00145 
00146   ACE_INT32 getHigh() const {
00147     return high_;
00148   }
00149   ACE_UINT32 getLow() const {
00150     return low_;
00151   }
00152 
00153   // SEQUENCENUMBER_UNKOWN is defined by the RTPS spec.
00154   static SequenceNumber SEQUENCENUMBER_UNKNOWN() {
00155     return SequenceNumber(-1, 0);
00156   }
00157 
00158   static SequenceNumber ZERO() {
00159     return SequenceNumber(0, 0);
00160   }
00161 
00162   static const Value MAX_VALUE = ACE_INT64_MAX;
00163   static const Value MIN_VALUE = 1;
00164   static const Value LOW_BASE = 0x0000000100000000LL;
00165 
00166   friend ACE_CDR::Boolean operator>>(Serializer& s, SequenceNumber& x);
00167 
00168 private:
00169 
00170   // Private constructor used to force construction of SEQUENCENUMBER_UNKNOWN.
00171   // Also used by operator>> to allow deserialization of the same value.
00172   SequenceNumber(ACE_INT32 high, ACE_UINT32 low)
00173     : high_(high), low_(low) {
00174   }
00175 
00176   ACE_INT32  high_;
00177   ACE_UINT32 low_;
00178 };
00179 
00180 inline ACE_CDR::Boolean
00181 operator<<(Serializer& s, const SequenceNumber& x) {
00182   s << x.getHigh();
00183   s << x.getLow();
00184   return s.good_bit();
00185 }
00186 
00187 inline ACE_CDR::Boolean
00188 operator>>(Serializer& s, SequenceNumber& x) {
00189   ACE_INT32 high;
00190   ACE_UINT32 low;
00191   s >> high;
00192   if (!s.good_bit()) return false;
00193   s >> low;
00194   if (!s.good_bit()) return false;
00195   x = SequenceNumber(high, low);
00196   return true;
00197 }
00198 
00199 inline SequenceNumber
00200 operator+(const SequenceNumber& lhs, int rhs)
00201 {
00202   return SequenceNumber(lhs.getValue() + rhs);
00203 }
00204 
00205 inline SequenceNumber
00206 operator+=(SequenceNumber& lhs, int rhs)
00207 {
00208   lhs.setValue(lhs.getValue() + rhs);
00209   return lhs;
00210 }
00211 
00212 inline SequenceNumber
00213 operator+(int lhs, const SequenceNumber& rhs)
00214 {
00215   return rhs + lhs;
00216 }
00217 
00218 inline void
00219 gen_find_size(const SequenceNumber& /*sn*/, size_t& size, size_t& padding) {
00220   find_size_ulong(size, padding);
00221   size += gen_max_marshaled_size(CORBA::Long());
00222 }
00223 
00224 typedef std::pair<SequenceNumber, SequenceNumber> SequenceRange;
00225 
00226 typedef Cached_Allocator_With_Overflow<ACE_Message_Block, ACE_Thread_Mutex>
00227 MessageBlockAllocator;
00228 typedef Cached_Allocator_With_Overflow<ACE_Data_Block, ACE_Thread_Mutex>
00229 DataBlockAllocator;
00230 struct DataSampleHeader;
00231 typedef Cached_Allocator_With_Overflow<DataSampleHeader, ACE_Null_Mutex>
00232 DataSampleHeaderAllocator;
00233 
00234 #define DUP true
00235 #define NO_DUP false
00236 
00237 /// This struct holds both object reference and the corresponding servant.
00238 template <typename T_impl, typename T, typename T_ptr, typename T_var>
00239 struct Objref_Servant_Pair {
00240   Objref_Servant_Pair()
00241     : svt_(0)
00242   {}
00243 
00244   Objref_Servant_Pair(T_impl* svt, T_ptr obj, bool dup)
00245     : svt_(svt)
00246   {
00247     if (dup) {
00248       obj_ = T::_duplicate(obj);
00249 
00250     } else {
00251       obj_ = obj;
00252     }
00253   }
00254 
00255   ~Objref_Servant_Pair()
00256   {}
00257 
00258   bool operator==(const Objref_Servant_Pair & pair) const {
00259     return pair.svt_ == this->svt_;
00260   }
00261 
00262   bool operator<(const Objref_Servant_Pair & pair) const {
00263     return this->svt_ < pair.svt_;
00264   }
00265 
00266   T_impl* svt_;
00267   T_var   obj_;
00268 };
00269 
00270 /// Use a Foo_var in a std::set or std::map with this comparison function,
00271 /// for example std::set<Foo_var, VarLess<Foo> >
00272 template <class T, class V = typename T::_var_type>
00273 struct VarLess : public std::binary_function<V, V, bool> {
00274   bool operator()(const V& x, const V& y) const {
00275     return x.in() < y.in();
00276   }
00277 };
00278 
00279 } // namespace OpenDDS
00280 } // namespace DCPS
00281 
00282 
00283 #endif /* OPENDDS_DCPS_DEFINITION_H */

Generated on Fri Feb 12 20:05:22 2016 for OpenDDS by  doxygen 1.4.7