2 * Copyright (c) 2017 Cisco and/or its affiliates.
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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __VOM_ENUM_H__
17 #define __VOM_ENUM_H__
23 * A template base class for all enum types.
24 * This enum type exists to associate an enum value with a string for
25 * display/debug purposes.
26 * Concrete enum types use the CRTP. Derived classes thus inherit this
27 * base's function, but are not polymorphic.
34 * convert to string format for debug purposes
36 const std::string& to_string() const { return (m_desc); }
41 bool operator==(const enum_base& e) const { return (e.m_value == m_value); }
46 enum_base& operator=(const enum_base& e)
55 * bitwise or assignemnt
57 enum_base& operator|=(const enum_base& e)
60 m_desc += ":" + e.m_desc;
68 enum_base operator|(const enum_base& e1) const
78 bool operator!=(const enum_base& e) const { return (e.m_value != m_value); }
81 * integer conversion operator
83 operator int() const { return (m_value); }
86 * Return the value of the enum - same as integer conversion
88 int value() const { return (m_value); }
92 * Constructor of an enum - takes value and string description
94 enum_base(int value, const std::string desc)
103 virtual ~enum_base() {}
107 * Integer value of the enum
119 * fd.io coding-style-patch-verification: ON
122 * eval: (c-set-style "mozilla")