]> rtime.felk.cvut.cz Git - l4.git/blobdiff - kernel/fiasco/src/lib/libk/bitmap.cpp
update
[l4.git] / kernel / fiasco / src / lib / libk / bitmap.cpp
index 11a886683f999516ea6a539f0e394e39486f3d86..be106bf6793742f32d7eb9a93266102808f78b9c 100644 (file)
@@ -98,6 +98,8 @@ public:
   }
 
 protected:
+  template< bool BIG, unsigned BTS > friend class Bitmap_base;
+
   Bitmap_base() {}
   Bitmap_base(Bitmap_base const &) = delete;
   Bitmap_base &operator = (Bitmap_base const &) = delete;
@@ -109,8 +111,13 @@ protected:
       _bits[i] |= r._bits[i];
   }
 
-  void _copy(Bitmap_base const &s)
-  { __builtin_memcpy(_bits, s._bits, Nr_elems * sizeof(_bits[0])); }
+  template<unsigned SOURCE_BITS>
+  void _copy(Bitmap_base<true, SOURCE_BITS> const &s)
+  {
+    static_assert(BITS <= SOURCE_BITS,
+                  "cannot copy smaller bitmap into bigger one");
+    __builtin_memcpy(_bits, s._bits, Nr_elems * sizeof(_bits[0]));
+  }
 
   unsigned long _bits[Nr_elems];
 };
@@ -183,6 +190,7 @@ public:
 
 
 protected:
+  template< bool BIG, unsigned BTS > friend class Bitmap_base;
   enum
   {
     Bpl      = sizeof(unsigned long) * 8,
@@ -201,9 +209,26 @@ protected:
 
   void _copy(Bitmap_base const &s)
   { _bits = s._bits; }
+
+  template<unsigned SOURCE_BITS>
+  void _copy(Bitmap_base<false, SOURCE_BITS> const &s)
+  {
+    static_assert(BITS <= SOURCE_BITS,
+                  "cannot copy smaller bitmap into bigger one");
+    _bits = s._bits;
+  }
+
+  template<unsigned SOURCE_BITS>
+  void _copy(Bitmap_base<true, SOURCE_BITS> const &s)
+  {
+    static_assert(BITS <= SOURCE_BITS,
+                  "cannot copy smaller bitmap into bigger one");
+    _bits = s._bits[0];
+  }
+
 };
 
-template<int BITS>
+template<unsigned BITS>
 class Bitmap : public Bitmap_base< (BITS > sizeof(unsigned long) * 8), BITS >
 {
 public:
@@ -217,6 +242,13 @@ public:
     return *this;
   }
 
+  template<unsigned SBITS>
+  Bitmap &operator = (Bitmap<SBITS> const &o)
+  {
+    this->_copy(o);
+    return *this;
+  }
+
   Bitmap &operator |= (Bitmap const &o)
   {
     this->_or(o);