Boost.hh

00001 
00019 #ifndef avro_Boost_hh__
00020 #define avro_Boost_hh__
00021 
00022 #include <boost/version.hpp>
00023 
00024 #define BOOST_MINOR_VERSION ( BOOST_VERSION / 100 % 1000 )
00025 
00026 #if (BOOST_MINOR_VERSION < 33)
00027 
00028 /* 
00029  * In boost 1.33, boost introduced the type trait definitions for true_type and
00030  * false_type, the pointer containers, and allow any objects to return
00031  * references.
00032  *
00033  * In order to support earlier versions of boost, if these do not exist we just
00034  * create them here.
00035  */
00036 
00037 #define AVRO_BOOST_NO_ANYREF
00038 #define AVRO_BOOST_NO_TRAIT
00039 #define AVRO_BOOST_NO_PTRVECTOR
00040 
00041 #else
00042 #endif
00043 
00044 #include <boost/any.hpp>
00045 
00046 #ifdef AVRO_BOOST_NO_TRAIT
00047 // this is copied directly from boost documentation
00048 namespace boost {
00049     template <class T, T val>
00050     struct integral_constant {
00051         typedef integral_constant<T, val>  type;
00052         typedef T                          value_type;
00053         static const T value = val;
00054     };
00055 
00056     typedef integral_constant<bool, true>  true_type;
00057     typedef integral_constant<bool, false> false_type;
00058 } // namespace boost
00059 #else 
00060 #include <boost/type_traits.hpp>
00061 #endif // AVRO_BOOST_NO_TRAIT
00062 
00063 #ifdef AVRO_BOOST_NO_PTRVECTOR
00064 #include <vector>
00065 // this implements a minimal subset of ptr_vector (the parts of the API used by avro)
00066 namespace boost {
00067     template <class T>
00068     class ptr_vector {
00069       public:
00070         ptr_vector() : ptrs_() {}
00071         ~ptr_vector() {
00072             for(size_t i=0; i < ptrs_.size(); ++i) {
00073                 delete ptrs_[i];
00074             }
00075         }
00076         void push_back(T *v) {
00077             ptrs_.push_back(v);
00078         }
00079         void pop_back() {
00080             T *toDelete = ptrs_.back();
00081             ptrs_.pop_back();
00082             delete toDelete;
00083         }
00084         const T& back() const {
00085             return *ptrs_.back();
00086         };
00087         T& back() {
00088             return *ptrs_.back();
00089         };
00090         bool empty() const {
00091             return ptrs_.empty();
00092         }
00093         const T& at(size_t index) const {
00094             return *(ptrs_.at(index));
00095         }
00096         const T& operator[](size_t index) const {
00097             return *(ptrs_[index]);
00098         }
00099         size_t size() const {
00100             return ptrs_.size();
00101         }
00102         void reserve(size_t elems) {
00103             ptrs_.reserve(elems);
00104         }
00105       private:
00106         std::vector<T *> ptrs_;
00107     };
00108 } // namespace boost
00109 #else 
00110 #include <boost/ptr_container/ptr_vector.hpp>
00111 #endif // AVRO_BOOST_NO_PTRVECTOR
00112 
00113 #endif // avro_Boost_hh__
Generated on Thu Sep 2 18:40:54 2010 for Avro C++ by  doxygen 1.6.3