Skip to content

Commit 9bfbb43

Browse files
util: Added a fixed version of MemBitmap which owns storage
1 parent 75953aa commit 9bfbb43

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

api/util/fixed_bitmap.hpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// This file is a part of the IncludeOS unikernel - www.includeos.org
2+
//
3+
// Copyright 2017 Oslo and Akershus University College of Applied Sciences
4+
// and Alfred Bratterud
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
18+
#pragma once
19+
#ifndef UTIL_FIXED_BITMAP_HPP
20+
#define UTIL_FIXED_BITMAP_HPP
21+
22+
#include "membitmap.hpp"
23+
#include <array>
24+
25+
/**
26+
* @brief A membitmap with a fixed amount of bits and storage.
27+
*
28+
* @tparam N Number of bits. Needs to be divisable by sizeof(Storage)
29+
*/
30+
template <size_t N>
31+
class Fixed_bitmap : public MemBitmap {
32+
public:
33+
using Storage = MemBitmap::word;
34+
static_assert(N >= sizeof(Storage), "Number of bits need to be atleast sizeof(Storage)");
35+
static_assert(N % sizeof(Storage) == 0, "Number of bits need to be divisable by sizeof(Storage)");
36+
37+
public:
38+
Fixed_bitmap() :
39+
MemBitmap{},
40+
storage{}
41+
{
42+
set_location(storage.data(), N / sizeof(Storage));
43+
}
44+
45+
private:
46+
std::array<Storage, N / sizeof(Storage)> storage;
47+
48+
}; // < class Fixed_bitmap
49+
50+
#endif

0 commit comments

Comments
 (0)