An Overlay-based
Virtual Network Substrate
SpoVNet

source: source/ariba/utility/system/SystemEventType.h @ 4828

Last change on this file since 4828 was 3690, checked in by mies, 15 years ago

Merged 20090512-mies-connectors changes r3472:r3689 into trunk.

File size: 4.3 KB
Line 
1// [License]
2// The Ariba-Underlay Copyright
3//
4// Copyright (c) 2008-2009, Institute of Telematics, UniversitÀt Karlsruhe (TH)
5//
6// Institute of Telematics
7// UniversitÀt Karlsruhe (TH)
8// Zirkel 2, 76128 Karlsruhe
9// Germany
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17// 2. Redistributions in binary form must reproduce the above copyright
18// notice, this list of conditions and the following disclaimer in the
19// documentation and/or other materials provided with the distribution.
20//
21// THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND
22// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR
25// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32//
33// The views and conclusions contained in the software and documentation
34// are those of the authors and should not be interpreted as representing
35// official policies, either expressed or implied, of the Institute of
36// Telematics.
37// [License]
38
39#ifndef SYSTEMEVENTTYPE_H_
40#define SYSTEMEVENTTYPE_H_
41
42#include <iostream>
43#include <vector>
44#include <string>
45#include <boost/cstdint.hpp>
46#include <boost/foreach.hpp>
47
48using std::string;
49using std::vector;
50using std::ostream;
51
52namespace ariba {
53namespace utility {
54
55class SystemEventType {
56public:
57        typedef uint16_t eventid_t;
58        static const SystemEventType DEFAULT;
59
60private:
61        eventid_t id;
62
63private:
64        class Descriptor {
65        public:
66                string description;
67                eventid_t parent;
68
69                Descriptor(string _d, eventid_t _p = 0) :
70                        description(_d), parent(_p) {
71                }
72               
73                Descriptor(const Descriptor& rh) 
74                        : description( rh.description ), parent( rh.parent ) {
75                }
76
77                ~Descriptor() {
78                }
79        };
80        static vector<Descriptor> ids;
81
82        inline SystemEventType(eventid_t mtype) :
83                id(mtype) {
84        }
85
86public:
87        inline SystemEventType(string description,
88                        const SystemEventType parent = DEFAULT) {
89                if (ids.size() == 0) ids.push_back(Descriptor(
90                                "<Default SystemEvent>", DEFAULT.id));
91                id = (eventid_t) ids.size();
92                ids.push_back(Descriptor(description, parent.id));
93        }
94
95        inline SystemEventType() {
96                id = 0;
97                if (ids.size() == 0) ids.push_back(Descriptor(
98                                "<Default SystemEvent>", DEFAULT.id));
99        }
100
101        inline SystemEventType(const SystemEventType& evtType) {
102                this->id = evtType.id;
103        }
104
105        inline ~SystemEventType() {
106        }
107
108        inline string getDescription() const {
109                return ids[id].description;
110        }
111
112        inline const SystemEventType getParent() const {
113                return SystemEventType(ids[id].parent);
114        }
115
116        inline const int getDepth() const {
117                int i = 0;
118                SystemEventType type = *this;
119                while (type != SystemEventType::DEFAULT) {
120                        type = type.getParent();
121                        i++;
122                }
123                return i;
124        }
125
126        inline const eventid_t getId() const {
127                return id;
128        }
129
130        inline SystemEventType& operator=(const SystemEventType& evtType) {
131                this->id = evtType.id;
132                return *this;
133        }
134
135        inline bool operator==(const SystemEventType& evtType) const {
136                return id == evtType.id;
137        }
138
139        inline bool operator!=(const SystemEventType& evtType) const {
140                return id != evtType.id;
141        }
142
143        inline bool operator>(const SystemEventType& evtType) const {
144                SystemEventType t = *this;
145                while (t.getParent() != evtType && t.getParent() != DEFAULT)
146                        t = t.getParent();
147                return (t.getParent() == evtType && t != evtType);
148        }
149
150        inline bool operator<(const SystemEventType& evtType) const {
151                SystemEventType t = evtType;
152                while (t.getParent() != *this && t.getParent() != DEFAULT)
153                        t = t.getParent();
154                return (t.getParent() == *this && t != *this);
155        }
156
157        inline bool isDefault() {
158                return ( id == 0 );
159        }
160
161};
162
163ostream& operator<<(ostream& stream, SystemEventType type);
164
165}} // spovnet, common
166
167#endif /* SYSTEMEVENTTYPE_H_ */
Note: See TracBrowser for help on using the repository browser.