Optionally use c++11 stuff instead of boost in cycles where possible. We do and conti...
authorMartijn Berger <martijn.berger@gmail.com>
Sun, 29 Mar 2015 20:12:22 +0000 (22:12 +0200)
committerMartijn Berger <martijn.berger@gmail.com>
Sun, 29 Mar 2015 20:12:40 +0000 (22:12 +0200)
Reviewers: dingto, sergey

Reviewed By: sergey

Subscribers: #cycles

Differential Revision: https://developer.blender.org/D1185

13 files changed:
intern/cycles/CMakeLists.txt
intern/cycles/SConscript
intern/cycles/device/device.h
intern/cycles/device/device_task.h
intern/cycles/render/image.h
intern/cycles/render/session.h
intern/cycles/util/util_foreach.h
intern/cycles/util/util_function.h
intern/cycles/util/util_map.h
intern/cycles/util/util_progress.h
intern/cycles/util/util_set.h
intern/cycles/util/util_task.h
intern/cycles/util/util_thread.h

index 2ba6af48d0d7f7fdf76995511d3d4271ddd02ad7..c4cadfe0bf735c1c6b150d6583a407410d818fea 100644 (file)
@@ -152,6 +152,27 @@ add_definitions(
        -DWITH_MULTI
 )
 
+TEST_UNORDERED_MAP_SUPPORT()
+if(HAVE_STD_UNORDERED_MAP_HEADER)
+    if(HAVE_UNORDERED_MAP_IN_STD_NAMESPACE)
+        add_definitions(-DCYCLES_STD_UNORDERED_MAP)
+    else()
+        if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+            add_definitions(-DCYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
+        else()
+            add_definitions(-DCYCLES_NO_UNORDERED_MAP)
+            message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
+        endif()
+    endif()
+else()
+    if(HAVE_UNORDERED_MAP_IN_TR1_NAMESPACE)
+        add_definitions(-DCYCLES_TR1_UNORDERED_MAP)
+    else()
+        add_definitions(-DCYCLES_NO_UNORDERED_MAP)
+        message(STATUS "Replacing unordered_map/set with map/set (warning: slower!)")
+    endif()
+endif()
+
 # Logging capabilities using GLog library.
 if(WITH_CYCLES_LOGGING)
        add_definitions(-DWITH_CYCLES_LOGGING)
index 9cbdb93ce85f180757895cb878f56ddfb43c21d9..79e14ab9a58dc33b58d8c162d6a95fe126fa5316 100644 (file)
@@ -47,6 +47,18 @@ cxxflags = Split(env['CXXFLAGS'])
 
 defs += env['BF_GL_DEFINITIONS']
 
+if env['WITH_UNORDERED_MAP_SUPPORT']:
+    if env['UNORDERED_MAP_HEADER'] == 'unordered_map':
+        if env['UNORDERED_MAP_NAMESPACE'] == 'std':
+            defs.append('CYCLES_STD_UNORDERED_MAP')
+        elif env['UNORDERED_MAP_NAMESPACE'] == 'std::tr1':
+            defs.append('CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE')
+    elif env['UNORDERED_MAP_NAMESPACE'] == 'std::tr1':
+        defs.append('CYCLES_TR1_UNORDERED_MAP')
+else:
+    print("-- Replacing unordered_map/set with map/set (warning: slower!)")
+    defs.append('CYCLES_NO_UNORDERED_MAP')
+
 defs.append('CCL_NAMESPACE_BEGIN=namespace ccl {')
 defs.append('CCL_NAMESPACE_END=}')
 
index 18fc707beab1a9ddb4c212563c0166675c96603e..7eb3f6c822bada5ff8607b73f7da58d9ed90b4bc 100644 (file)
@@ -72,8 +72,8 @@ public:
 /* Device */
 
 struct DeviceDrawParams {
-       boost::function<void(void)> bind_display_space_shader_cb;
-       boost::function<void(void)> unbind_display_space_shader_cb;
+       function<void(void)> bind_display_space_shader_cb;
+       function<void(void)> unbind_display_space_shader_cb;
 };
 
 class Device {
index 84945bcf9a5169f715dcf9eda97bdf1688eac259..0c23d8971e059848bf145e1225773a7710b0ef0c 100644 (file)
@@ -57,11 +57,11 @@ public:
 
        void update_progress(RenderTile *rtile);
 
-       boost::function<bool(Device *device, RenderTile&)> acquire_tile;
-       boost::function<void(void)> update_progress_sample;
-       boost::function<void(RenderTile&)> update_tile_sample;
-       boost::function<void(RenderTile&)> release_tile;
-       boost::function<bool(void)> get_cancel;
+       function<bool(Device *device, RenderTile&)> acquire_tile;
+       function<void(void)> update_progress_sample;
+       function<void(RenderTile&)> update_tile_sample;
+       function<void(RenderTile&)> release_tile;
+       function<bool(void)> get_cancel;
 
        bool need_finish_queue;
        bool integrator_branched;
index 2f5dcb6efd598bd90f66f50040ad318b42cc727e..1045b4532e4eb7469b0755ccc99d92f0fb9b9218 100644 (file)
@@ -73,9 +73,9 @@ public:
 
        bool need_update;
 
-       boost::function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
-       boost::function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
-       boost::function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
+       function<void(const string &filename, void *data, bool &is_float, int &width, int &height, int &depth, int &channels)> builtin_image_info_cb;
+       function<bool(const string &filename, void *data, unsigned char *pixels)> builtin_image_pixels_cb;
+       function<bool(const string &filename, void *data, float *pixels)> builtin_image_float_pixels_cb;
 
        struct Image {
                string filename;
index c77652d372258e88cce383cd50bec2d3df834949..8b108b0940f9d4d4d93ec3839b9a08a73e1f279c 100644 (file)
@@ -125,8 +125,8 @@ public:
        TileManager tile_manager;
        Stats stats;
 
-       boost::function<void(RenderTile&)> write_render_tile_cb;
-       boost::function<void(RenderTile&)> update_render_tile_cb;
+       function<void(RenderTile&)> write_render_tile_cb;
+       function<void(RenderTile&)> update_render_tile_cb;
 
        Session(const SessionParams& params);
        ~Session();
index 065bd33ebd2c9cae2707fac4639af939c05d376f..4f7337107b32435c7ba625002708d1b4f8cab2a2 100644 (file)
 
 /* Use Boost to get nice foreach() loops for STL data structures. */
 
-#include <boost/foreach.hpp>
-#define foreach BOOST_FOREACH
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#  define foreach(x, y) for(x : y)
+#else
+#  include <boost/foreach.hpp>
+#  define foreach BOOST_FOREACH
+#endif
 
 #endif /* __UTIL_FOREACH_H__ */
 
index 7a312efaad7260c6c52459534a8a587972393c14..83c07ae06a8974d4962b52e11a81a0d2ed7f85f8 100644 (file)
 #ifndef __UTIL_FUNCTION_H__
 #define __UTIL_FUNCTION_H__
 
-#include <boost/bind.hpp>
-#include <boost/function.hpp>
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#  include <functional>
+#else
+#  include <boost/bind.hpp>
+#  include <boost/function.hpp>
+#endif
 
 CCL_NAMESPACE_BEGIN
 
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#  define function_bind std::bind
+using std::function;
+using std::placeholders::_1;
+using std::placeholders::_2;
+using std::placeholders::_3;
+using std::placeholders::_4;
+using std::placeholders::_5;
+using std::placeholders::_6;
+using std::placeholders::_7;
+using std::placeholders::_8;
+using std::placeholders::_9;
+#else
 using boost::function;
-#define function_bind boost::bind
-
+#  define function_bind boost::bind
+#endif
 CCL_NAMESPACE_END
 
 #endif /* __UTIL_FUNCTION_H__ */
index 54d6a8d64241af2487ecd5bf9d92ce6b12534603..46c2885f8b06775de012bbe8382ab6d45e60aba9 100644 (file)
 #define __UTIL_MAP_H__
 
 #include <map>
-#include <boost/tr1/unordered_map.hpp>
+
+#if defined(CYCLES_TR1_UNORDERED_MAP)
+#  include <tr1/unordered_map>
+#endif
+
+#if defined(CYCLES_STD_UNORDERED_MAP) || defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
+#  include <unordered_map>
+#endif
+
+#if !defined(CYCLES_NO_UNORDERED_MAP) && !defined(CYCLES_TR1_UNORDERED_MAP) && \
+       !defined(CYCLES_STD_UNORDERED_MAP) && !defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)  // NOLINT
+#  error One of: CYCLES_NO_UNORDERED_MAP, CYCLES_TR1_UNORDERED_MAP,\
+ CYCLES_STD_UNORDERED_MAP, CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE must be defined!  // NOLINT
+#endif
+
 
 CCL_NAMESPACE_BEGIN
 
 using std::map;
 using std::pair;
+
+#if defined(CYCLES_NO_UNORDERED_MAP)
+typedef std::map unordered_map;
+#endif
+
+#if defined(CYCLES_TR1_UNORDERED_MAP) || defined(CYCLES_STD_UNORDERED_MAP_IN_TR1_NAMESPACE)
 using std::tr1::unordered_map;
+#endif
+
+#if defined(CYCLES_STD_UNORDERED_MAP)
+using std::unordered_map;
+#endif
 
 CCL_NAMESPACE_END
 
index 0ff48630a813f9cd0f7c8f10b537d3b6b10b4195..963987487ed623d90e19a09aaf39e5a9984f60ac 100644 (file)
@@ -110,7 +110,7 @@ public:
                return cancel_message;
        }
 
-       void set_cancel_callback(boost::function<void(void)> function)
+       void set_cancel_callback(function<void(void)> function)
        {
                cancel_cb = function;
        }
@@ -275,7 +275,7 @@ public:
                }
        }
 
-       void set_update_callback(boost::function<void(void)> function)
+       void set_update_callback(function<void(void)> function)
        {
                update_cb = function;
        }
@@ -283,8 +283,8 @@ public:
 protected:
        thread_mutex progress_mutex;
        thread_mutex update_mutex;
-       boost::function<void(void)> update_cb;
-       boost::function<void(void)> cancel_cb;
+       function<void(void)> update_cb;
+       function<void(void)> cancel_cb;
 
        int tile;    /* counter for rendered tiles */
        int sample;  /* counter of rendered samples, global for all tiles */
index 73a2bf19899579ac35946380c58a6ed1d6c19a9d..b3cb8dd8af5112efd305a893a1e58dd01657e2a3 100644 (file)
 #define __UTIL_SET_H__
 
 #include <set>
-#include <boost/tr1/unordered_set.hpp>
-
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#  include <unordered_set>
+#else
+#  include <boost/tr1/unordered_set.hpp>
+#endif
 CCL_NAMESPACE_BEGIN
 
 using std::set;
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+using std::unordered_set;
+#else
 using std::tr1::unordered_set;
-
+#endif
 CCL_NAMESPACE_END
 
 #endif /* __UTIL_SET_H__ */
index 8fac12e9987397dc1236fcdb0695ba7bd5167760..debcff3b7767ce8136ee9c43918a84a2a8754619 100644 (file)
@@ -27,7 +27,7 @@ class Task;
 class TaskPool;
 class TaskScheduler;
 
-typedef boost::function<void(void)> TaskRunFunction;
+typedef function<void(void)> TaskRunFunction;
 
 /* Task
  *
index fbbb9b42e31ab4b40ba88b78154cd5d7b887e79f..9c19235d41d194f0fcbbd94d5ce48ee34683f748 100644 (file)
 #ifndef __UTIL_THREAD_H__
 #define __UTIL_THREAD_H__
 
-#include <boost/thread.hpp>
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+#  include <thread>
+#  include <mutex>
+#  include <condition_variable>
+#  include <functional>
+#else
+#  include <boost/thread.hpp>
+#endif
 #include <pthread.h>
 #include <queue>
 
 
 CCL_NAMESPACE_BEGIN
 
+#if (__cplusplus > 199711L) || (defined(_MSC_VER) && _MSC_VER >= 1800)
+typedef std::mutex thread_mutex;
+typedef std::unique_lock<std::mutex> thread_scoped_lock;
+typedef std::condition_variable thread_condition_variable;
+#else
 /* use boost for mutexes */
-
 typedef boost::mutex thread_mutex;
 typedef boost::mutex::scoped_lock thread_scoped_lock;
 typedef boost::condition_variable thread_condition_variable;
+#endif
 
 /* own pthread based implementation, to avoid boost version conflicts with
  * dynamically loaded blender plugins */
 
 class thread {
 public:
-       thread(boost::function<void(void)> run_cb_)
+       thread(function<void(void)> run_cb_)
+
        {
                joined = false;
                run_cb = run_cb_;
@@ -63,7 +76,7 @@ public:
        }
 
 protected:
-       boost::function<void(void)> run_cb;
+       function<void(void)> run_cb;
        pthread_t pthread_id;
        bool joined;
 };