[Bf-blender-cvs] [f01456a] master: Optionally use c++11 stuff instead of boost in cycles where possible. We do and continue to depend on boost though

Martijn Berger noreply at git.blender.org
Sun Mar 29 22:14:10 CEST 2015


Commit: f01456aaa4a87cd76feaef50ec822340197f9eda
Author: Martijn Berger
Date:   Sun Mar 29 22:12:22 2015 +0200
Branches: master
https://developer.blender.org/rBf01456aaa4a87cd76feaef50ec822340197f9eda

Optionally use c++11 stuff instead of boost in cycles where possible. We do and continue to depend on boost though

Reviewers: dingto, sergey

Reviewed By: sergey

Subscribers: #cycles

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

===================================================================

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

===================================================================

diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt
index 2ba6af4..c4cadfe 100644
--- a/intern/cycles/CMakeLists.txt
+++ b/intern/cycles/CMakeLists.txt
@@ -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)
diff --git a/intern/cycles/SConscript b/intern/cycles/SConscript
index 9cbdb93..79e14ab 100644
--- a/intern/cycles/SConscript
+++ b/intern/cycles/SConscript
@@ -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=}')
 
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 18fc707..7eb3f6c 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -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 {
diff --git a/intern/cycles/device/device_task.h b/intern/cycles/device/device_task.h
index 84945bc..0c23d89 100644
--- a/intern/cycles/device/device_task.h
+++ b/intern/cycles/device/device_task.h
@@ -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;
diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h
index 2f5dcb6..1045b45 100644
--- a/intern/cycles/render/image.h
+++ b/intern/cycles/render/image.h
@@ -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;
diff --git a/intern/cycles/render/session.h b/intern/cycles/render/session.h
index c77652d..8b108b0 100644
--- a/intern/cycles/render/session.h
+++ b/intern/cycles/render/session.h
@@ -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();
diff --git a/intern/cycles/util/util_foreach.h b/intern/cycles/util/util_foreach.h
index 065bd33..4f73371 100644
--- a/intern/cycles/util/util_foreach.h
+++ b/intern/cycles/util/util_foreach.h
@@ -19,8 +19,12 @@
 
 /* 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__ */
 
diff --git a/intern/cycles/util/util_function.h b/intern/cycles/util/util_function.h
index 7a312ef..83c07ae 100644
--- a/intern/cycles/util/util_function.h
+++ b/intern/cycles/util/util_function.h
@@ -17,14 +17,31 @@
 #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__ */
diff --git a/intern/cycles/util/util_map.h b/intern/cycles/util/util_map.h
index 54d6a8d..46c2885 100644
--- a/intern/cycles/util/util_map.h
+++ b/intern/cycles/util/util_map.h
@@ -18,13 +18,38 @@
 #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
 
diff --git a/intern/cycles/util/util_progress.h b/intern/cycles/util/util_progress.h
index 0ff4863..9639874 100644
--- a/intern/cycles/util/util_progress.h
+++ b/intern/cycles/util/util_progress.h
@@ -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 */
diff --git a/intern/cycles/util/util_set.h b/intern/cycles/util/util_set.h
index 73a2bf1..b3cb8dd 100644
--- a/intern/cycles/util/util_set.h
+++ b/intern/cycles/util/util_set.h
@@ -18,13 +18,19 @@
 #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__ */
diff --git a/intern/cycles/util/util_task.h b/intern/cycles/util/util_task.h
index 8fac12e..debcff3 100644
--- a/intern/cycles/util/util_task.h
+++ b/intern/cycles/util/util_task.h
@@ -27,7 +27,7 @@ class Task;
 class TaskPool;
 class TaskScheduler;
 
-typedef boost::function<void(void)> TaskRunFunction;
+typedef function<void(void)> TaskRunFunction;
 
 /* Task
  *
diff --git a/intern/cycles/util/util_thread.h b/intern/cycles/util/util_thread.h
index fbbb9b4..9c19235 100644
--- a/intern/cycles/util/util_thread.h
+++ b/intern/cycles/util/util_thread.h
@@ -17,7 +17,14 @@
 #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 <functi

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list