bmv2
Designing your own switch target with bmv2
Loading...
Searching...
No Matches
pre.h
1/* Copyright 2013-present Barefoot Networks, Inc.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * Srikrishna Gopu (krishna@barefootnetworks.com)
18 * Antonin Bas (antonin@barefootnetworks.com)
19 *
20 */
21
22#ifndef BM_BM_SIM_PRE_H_
23#define BM_BM_SIM_PRE_H_
24
25#include <string>
26#include <bitset>
27
28namespace bm {
29
30namespace McPre {
31
32template <size_t set_size>
33class Set {
34 public:
35 using reference = typename std::bitset<set_size>::reference;
36
37 public:
38 constexpr Set() noexcept { }
39
40 explicit Set(const std::string &str)
41 : port_map(str) { }
42
43 bool operator[] (size_t pos) const { return port_map[pos]; }
44 reference operator[] (size_t pos) { return port_map[pos]; }
45
46 constexpr size_t size() const noexcept { return port_map.size(); }
47
48 private:
49 std::bitset<set_size> port_map{};
50};
51
52} // namespace McPre
53
54} // namespace bm
55
56#endif // BM_BM_SIM_PRE_H_