00001 // [License] 00002 // The Ariba-Underlay Copyright 00003 // 00004 // Copyright (c) 2008-2009, Institute of Telematics, Universität Karlsruhe (TH) 00005 // 00006 // Institute of Telematics 00007 // Universität Karlsruhe (TH) 00008 // Zirkel 2, 76128 Karlsruhe 00009 // Germany 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are 00013 // met: 00014 // 00015 // 1. Redistributions of source code must retain the above copyright 00016 // notice, this list of conditions and the following disclaimer. 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE INSTITUTE OF TELEMATICS ``AS IS'' AND 00022 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00024 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE ARIBA PROJECT OR 00025 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00026 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00027 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00028 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00029 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00030 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00031 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00032 // 00033 // The views and conclusions contained in the software and documentation 00034 // are those of the authors and should not be interpreted as representing 00035 // official policies, either expressed or implied, of the Institute of 00036 // Telematics. 00037 // [License] 00038 00039 #ifndef SYSTEMEVENTTYPE_H_ 00040 #define SYSTEMEVENTTYPE_H_ 00041 00042 #include <iostream> 00043 #include <vector> 00044 #include <string> 00045 #include <boost/cstdint.hpp> 00046 #include <boost/foreach.hpp> 00047 00048 using std::string; 00049 using std::vector; 00050 using std::ostream; 00051 00052 namespace ariba { 00053 namespace utility { 00054 00055 class SystemEventType { 00056 public: 00057 typedef uint16_t eventid_t; 00058 static const SystemEventType DEFAULT; 00059 00060 private: 00061 eventid_t id; 00062 00063 private: 00064 class Descriptor { 00065 public: 00066 string description; 00067 eventid_t parent; 00068 00069 Descriptor(string _d, eventid_t _p = 0) : 00070 description(_d), parent(_p) { 00071 } 00072 00073 Descriptor(const Descriptor& rh) 00074 : description( rh.description ), parent( rh.parent ) { 00075 } 00076 00077 ~Descriptor() { 00078 } 00079 }; 00080 static vector<Descriptor> ids; 00081 00082 inline SystemEventType(eventid_t mtype) : 00083 id(mtype) { 00084 } 00085 00086 public: 00087 inline SystemEventType(string description, 00088 const SystemEventType parent = DEFAULT) { 00089 if (ids.size() == 0) ids.push_back(Descriptor( 00090 "<Default SystemEvent>", DEFAULT.id)); 00091 id = (eventid_t) ids.size(); 00092 ids.push_back(Descriptor(description, parent.id)); 00093 } 00094 00095 inline SystemEventType() { 00096 id = 0; 00097 if (ids.size() == 0) ids.push_back(Descriptor( 00098 "<Default SystemEvent>", DEFAULT.id)); 00099 } 00100 00101 inline SystemEventType(const SystemEventType& evtType) { 00102 this->id = evtType.id; 00103 } 00104 00105 inline ~SystemEventType() { 00106 } 00107 00108 inline string getDescription() const { 00109 return ids[id].description; 00110 } 00111 00112 inline const SystemEventType getParent() const { 00113 return SystemEventType(ids[id].parent); 00114 } 00115 00116 inline const int getDepth() const { 00117 int i = 0; 00118 SystemEventType type = *this; 00119 while (type != SystemEventType::DEFAULT) { 00120 type = type.getParent(); 00121 i++; 00122 } 00123 return i; 00124 } 00125 00126 inline const eventid_t getId() const { 00127 return id; 00128 } 00129 00130 inline SystemEventType& operator=(const SystemEventType& evtType) { 00131 this->id = evtType.id; 00132 return *this; 00133 } 00134 00135 inline bool operator==(const SystemEventType& evtType) const { 00136 return id == evtType.id; 00137 } 00138 00139 inline bool operator!=(const SystemEventType& evtType) const { 00140 return id != evtType.id; 00141 } 00142 00143 inline bool operator>(const SystemEventType& evtType) const { 00144 SystemEventType t = *this; 00145 while (t.getParent() != evtType && t.getParent() != DEFAULT) 00146 t = t.getParent(); 00147 return (t.getParent() == evtType && t != evtType); 00148 } 00149 00150 inline bool operator<(const SystemEventType& evtType) const { 00151 SystemEventType t = evtType; 00152 while (t.getParent() != *this && t.getParent() != DEFAULT) 00153 t = t.getParent(); 00154 return (t.getParent() == *this && t != *this); 00155 } 00156 00157 inline bool isDefault() { 00158 return ( id == 0 ); 00159 } 00160 00161 }; 00162 00163 ostream& operator<<(ostream& stream, SystemEventType type); 00164 00165 }} // spovnet, common 00166 00167 #endif /* SYSTEMEVENTTYPE_H_ */