farm-ng-core
enum_flags.h
Go to the documentation of this file.
1 // Copyright 2022, farm-ng 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 // FARM_ENUM is a fork of MY_ENUM.
16 //
17 // https://github.com/facebookincubator/MY_ENUM/
18 //
19 // Copyright (c) Facebook, Inc. and its affiliates.
20 //
21 // This source code is licensed under the MIT license found in the
22 // LICENSE file in the root directory of this source tree.
23 
24 #pragma once
25 
27 
28 #include <ostream>
29 
30 #define FARM_ENUMFLAGS_OSTREAM_OVERLOAD(NAME) \
31  namespace enum_wrapper_ { \
32  inline auto operator<<(std::ostream &os, NAME##Impl value) \
33  -> std::ostream & { \
34  os << toPretty(value); \
35  return os; \
36  } \
37  } // namespace enum_wrapper_
38 
39 // Convenience marco which defines the enum flags plus alias and adds the
40 // ostream overload.
41 #define FARM_ENUMFLAGS(EnumName, UINT_TYPE, ...) \
42  FARM_ENUMFLAGS_WITHOUT_OSTREAM(EnumName, UINT_TYPE, __VA_ARGS__); \
43  FARM_ENUMFLAGS_OSTREAM_OVERLOAD(EnumName)
44 
45 // Convenience marco which defines the enum flags and adds the ostream overload.
46 #define FARM_ENUMFLAGS_DEF(EnumName, UINT_TYPE, ...) \
47  FARM_ENUMFLAGS_WITHOUT_OSTREAM_DEF(EnumName, UINT_TYPE, __VA_ARGS__); \
48  FARM_ENUMFLAGS_OSTREAM_OVERLOAD(EnumName)
enum_flags_without_ostream.h