Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
rename Lib to Facetable
authorMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Dec 2015 22:03:18 +0000 (23:03 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Tue, 15 Dec 2015 22:03:18 +0000 (23:03 +0100)
include/simgrid/Host.hpp
include/xbt/Facetable.hpp [moved from include/xbt/Lib.hpp with 57% similarity]
tools/cmake/DefinePackages.cmake

index e914303..d61aefa 100644 (file)
 #include <vector>
 
 #include <xbt/base.h>
-#include <xbt/Lib.hpp>
+#include <xbt/Facetable.hpp>
 
 namespace simgrid {
 
-XBT_PUBLIC_CLASS Host : public simgrid::xbt::Lib<Host> {
+XBT_PUBLIC_CLASS Host : public simgrid::xbt::Facetable<Host> {
 private:
   std::string id_;
 public:
similarity index 57%
rename from include/xbt/Lib.hpp
rename to include/xbt/Facetable.hpp
index 36c10b7..08be86e 100644 (file)
 namespace simgrid {
 namespace xbt {
 
+/** A Facetable is an object that you can extend with external facets.
+ *
+ * Facets are similar to the concept of mixins, that is, a set of behavior that is injected into a class without derivation.
+ *
+ * Imagine that you want to write a plugin dealing with the energy in SimGrid.
+ * You will have to store some information about each and every host.
+ *
+ * You could modify the Host class directly (but your code will soon become messy).
+ * You could create a class EnergyHost deriving Host, but it is not easily combinable
+ *    with a notion of Host extended with another concept (such as mobility).
+ * You could completely externalize these data with an associative map Host->EnergyHost.
+ *    It would work, provided that you implement this classical feature correctly (and it would induce a little performance penalty).
+ * Instead, you should add a new facet to the Host class, that happens to be Facetable.
+ *
+ */
+
 template<class T>
-class Lib {
+class Facetable {
 private:
   static std::vector<void(*)(void*)> deleters_;
 protected:
@@ -32,8 +48,8 @@ public:
   {
     return add_level([](void* p){ delete (U*)p; });
   }
-  Lib() : facets_(deleters_.size(), nullptr) {}
-  ~Lib()
+  Facetable() : facets_(deleters_.size(), nullptr) {}
+  ~Facetable()
   {
     for (std::size_t i = 0; i < facets_.size(); ++i)
       if (facets_[i] != nullptr)
@@ -60,7 +76,7 @@ public:
 };
 
 template<class T>
-std::vector<void(*)(void*)> Lib<T>::deleters_ = {};
+std::vector<void(*)(void*)> Facetable<T>::deleters_ = {};
 
 }
 }
index cdb6b0a..c5b9922 100644 (file)
@@ -751,7 +751,7 @@ set(headers_to_install
   include/xbt/hash.h
   include/xbt/heap.h
   include/xbt/lib.h
-  include/xbt/Lib.hpp
+  include/xbt/Facetable.hpp
   include/xbt/log.h
   include/xbt/mallocator.h
   include/xbt/matrix.h