avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cutt...@apache.org
Subject svn commit: r817765 - in /hadoop/avro/trunk: CHANGES.txt src/c++/api/AvroTraits.hh src/c++/api/Boost.hh src/c++/api/Compiler.hh src/c++/scripts/gen.py
Date Tue, 22 Sep 2009 18:51:04 GMT
Author: cutting
Date: Tue Sep 22 18:51:04 2009
New Revision: 817765

URL: http://svn.apache.org/viewvc?rev=817765&view=rev
Log:
AVRO-115.  Make C++ compatible with Boost 1.32. Contributed by Scott Banachowski.

Added:
    hadoop/avro/trunk/src/c++/api/Boost.hh
Modified:
    hadoop/avro/trunk/CHANGES.txt
    hadoop/avro/trunk/src/c++/api/AvroTraits.hh
    hadoop/avro/trunk/src/c++/api/Compiler.hh
    hadoop/avro/trunk/src/c++/scripts/gen.py

Modified: hadoop/avro/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/CHANGES.txt?rev=817765&r1=817764&r2=817765&view=diff
==============================================================================
--- hadoop/avro/trunk/CHANGES.txt (original)
+++ hadoop/avro/trunk/CHANGES.txt Tue Sep 22 18:51:04 2009
@@ -11,6 +11,9 @@
     AVRO-99.  Use Boost framework for C++ unit tests.
     (Scott Banachowski via cutting)
 
+    AVRO-116.  Make C++ compatible with Boost 1.32.
+    (Scott Banachowski via cutting)
+
   OPTIMIZATIONS
 
   BUG FIXES

Modified: hadoop/avro/trunk/src/c++/api/AvroTraits.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/AvroTraits.hh?rev=817765&r1=817764&r2=817765&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/AvroTraits.hh (original)
+++ hadoop/avro/trunk/src/c++/api/AvroTraits.hh Tue Sep 22 18:51:04 2009
@@ -19,8 +19,7 @@
 #ifndef avro_AvroTraits_hh__
 #define avro_AvroTraits_hh__
 
-#include <boost/type_traits.hpp>
-
+#include "Boost.hh"
 #include "Types.hh"
 
 /// \file

Added: hadoop/avro/trunk/src/c++/api/Boost.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Boost.hh?rev=817765&view=auto
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Boost.hh (added)
+++ hadoop/avro/trunk/src/c++/api/Boost.hh Tue Sep 22 18:51:04 2009
@@ -0,0 +1,101 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef avro_Boost_hh__
+#define avro_Boost_hh__
+
+#include <boost/version.hpp>
+
+#define BOOST_MINOR_VERSION ( BOOST_VERSION / 100 % 1000 )
+
+#if (BOOST_MINOR_VERSION < 33)
+
+/* 
+ * In boost 1.33, boost introduced the type trait definitions for true_type and
+ * false_type, the pointer containers, and allow any objects to return
+ * references.
+ *
+ * In order to support earlier versions of boost, if these do not exist we just
+ * create them here.
+ */
+
+#define AVRO_BOOST_NO_ANYREF
+#define AVRO_BOOST_NO_TRAIT
+#define AVRO_BOOST_NO_PTRVECTOR
+
+#else
+#endif
+
+#include <boost/any.hpp>
+
+#ifdef AVRO_BOOST_NO_TRAIT
+// this is copied directly from boost documentation
+namespace boost {
+    template <class T, T val>
+    struct integral_constant {
+        typedef integral_constant<T, val>  type;
+        typedef T                          value_type;
+        static const T value = val;
+    };
+
+    typedef integral_constant<bool, true>  true_type;
+    typedef integral_constant<bool, false> false_type;
+}
+#else 
+#include <boost/type_traits.hpp>
+#endif // AVRO_BOOST_NO_TRAIT
+
+#ifdef AVRO_BOOST_NO_PTRVECTOR
+#include <vector>
+// this implements a minimal subset of ptr_vector (the parts of the API used by avro)
+namespace boost {
+    template <class T>
+    class ptr_vector {
+      public:
+        ptr_vector() : ptrs_() {}
+        ~ptr_vector() {
+            for(size_t i=0; i < ptrs_.size(); ++i) {
+                delete ptrs_[i];
+            }
+        }
+        void push_back(T *v) {
+            ptrs_.push_back(v);
+        }
+        void pop_back() {
+            T *toDelete = ptrs_.back();
+            ptrs_.pop_back();
+            delete toDelete;
+        }
+        const T& back() const {
+            return *ptrs_.back();
+        };
+        T& back() {
+            return *ptrs_.back();
+        };
+        bool empty() const {
+            return ptrs_.empty();
+        }
+      private:
+        std::vector<T *> ptrs_;
+    };
+}
+#else 
+#include <boost/ptr_container/ptr_vector.hpp>
+#endif // AVRO_BOOST_NO_PTRVECTOR
+
+#endif // avro_Boost_hh__

Modified: hadoop/avro/trunk/src/c++/api/Compiler.hh
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/api/Compiler.hh?rev=817765&r1=817764&r2=817765&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/api/Compiler.hh (original)
+++ hadoop/avro/trunk/src/c++/api/Compiler.hh Tue Sep 22 18:51:04 2009
@@ -19,7 +19,7 @@
 #ifndef avro_Compiler_hh__
 #define avro_Compiler_hh__
 
-#include <boost/ptr_container/ptr_vector.hpp>
+#include "Boost.hh"
 
 #include <FlexLexer.h>
 #include "Types.hh"

Modified: hadoop/avro/trunk/src/c++/scripts/gen.py
URL: http://svn.apache.org/viewvc/hadoop/avro/trunk/src/c%2B%2B/scripts/gen.py?rev=817765&r1=817764&r2=817765&view=diff
==============================================================================
--- hadoop/avro/trunk/src/c++/scripts/gen.py (original)
+++ hadoop/avro/trunk/src/c++/scripts/gen.py Tue Sep 22 18:51:04 2009
@@ -23,7 +23,7 @@
 #include <string>
 #include <vector>
 #include <map>
-#include <boost/any.hpp>
+#include "Boost.hh"
 #include "Exception.hh"
 #include "AvroSerialize.hh"
 #include "AvroParse.hh"
@@ -103,10 +103,17 @@
     $name$() : choice(0), value(T0()) {}
 
 $setfuncs$
+#ifdef AVRO_BOOST_NO_ANYREF
+    template<typename T>
+    T getValue() const {
+        return boost::any_cast<T>(value);
+    }
+#else
     template<typename T>
     const T &getValue() const {
         return boost::any_cast<const T&>(value);
     }
+#endif
 
     int64_t choice; 
     boost::any value;



Mime
View raw message