clover: Simplify the platform object by using util/range.
authorFrancisco Jerez <currojerez@riseup.net>
Tue, 17 Sep 2013 04:44:19 +0000 (21:44 -0700)
committerFrancisco Jerez <currojerez@riseup.net>
Mon, 21 Oct 2013 17:47:03 +0000 (10:47 -0700)
Tested-by: Tom Stellard <thomas.stellard@amd.com>
src/gallium/state_trackers/clover/core/device.hpp
src/gallium/state_trackers/clover/core/platform.cpp
src/gallium/state_trackers/clover/core/platform.hpp

index 95669bdeb64f867ab13c8a1f5a5df9939d03a2e2..42e32a19077d5b6799326d3212cac0d9790219fd 100644 (file)
@@ -35,7 +35,7 @@ namespace clover {
    class root_resource;
    class hard_event;
 
-   class device : public _cl_device_id {
+   class device : public ref_counter, public _cl_device_id {
    public:
       device(clover::platform &platform, pipe_loader_device *ldev);
       device(device &&dev);
index 31e8830760574163efec9b5f174f86af75c74e3f..e35b1f96da5c7702843b645266f1bae2c99e9ba6 100644 (file)
@@ -24,7 +24,7 @@
 
 using namespace clover;
 
-platform::platform() {
+platform::platform() : adaptor_range(derefs(), devs) {
    int n = pipe_loader_probe(NULL, 0);
    std::vector<pipe_loader_device *> ldevs(n);
 
@@ -32,7 +32,7 @@ platform::platform() {
 
    for (pipe_loader_device *ldev : ldevs) {
       try {
-         devs.emplace_back(*this, ldev);
+         devs.push_back(transfer(new device(*this, ldev)));
       } catch (error &) {}
    }
 }
index 26c65c788bd241bb6a5cd1788b528fb531653a41..83f0cab35e949e511642b842b6e9d2363be81771 100644 (file)
 
 #include "core/object.hpp"
 #include "core/device.hpp"
+#include "util/range.hpp"
 
 namespace clover {
-   class platform : public _cl_platform_id {
+   class platform : public _cl_platform_id,
+                    public adaptor_range<
+      derefs, std::vector<ref_ptr<device>> &> {
    public:
-      typedef std::vector<device>::iterator iterator;
-
       platform();
 
-      ///
-      /// Container of all compute devices that are available in the platform.
-      ///
-      /// @{
-      iterator begin() {
-         return devs.begin();
-      }
-
-      iterator end() {
-         return devs.end();
-      }
-
-      device &front() {
-         return devs.front();
-      }
-
-      device &back() {
-         return devs.back();
-      }
-      /// @}
-
    protected:
-      std::vector<device> devs;
+      std::vector<ref_ptr<device>> devs;
    };
 }