You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
131 lines
4.4 KiB
Plaintext
131 lines
4.4 KiB
Plaintext
1 year ago
|
/***************************************************************************
|
||
|
* Copyright (C) gempa GmbH *
|
||
|
* All rights reserved. *
|
||
|
* Contact: gempa GmbH (seiscomp-dev@gempa.de) *
|
||
|
* *
|
||
|
* GNU Affero General Public License Usage *
|
||
|
* This file may be used under the terms of the GNU Affero *
|
||
|
* Public License version 3.0 as published by the Free Software Foundation *
|
||
|
* and appearing in the file LICENSE included in the packaging of this *
|
||
|
* file. Please review the following information to ensure the GNU Affero *
|
||
|
* Public License version 3.0 requirements will be met: *
|
||
|
* https://www.gnu.org/licenses/agpl-3.0.html. *
|
||
|
* *
|
||
|
* Other Usage *
|
||
|
* Alternatively, this file may be used in accordance with the terms and *
|
||
|
* conditions contained in a signed written agreement between you and *
|
||
|
* gempa GmbH. *
|
||
|
***************************************************************************/
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline Enum<ENUMTYPE, END, NAMES>::Enum(ENUMTYPE value)
|
||
|
: _value(value) {
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline Enum<ENUMTYPE, END, NAMES>::operator ENUMTYPE () const {
|
||
|
return _value;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline void Enum<ENUMTYPE, END, NAMES>::serialize(Archive& ar) {
|
||
|
std::string str;
|
||
|
if ( ar.isReading() ) {
|
||
|
ar.read(str);
|
||
|
ar.setValidity(fromString(str));
|
||
|
}
|
||
|
else {
|
||
|
str = NAMES::name(int(_value)-int(0));
|
||
|
ar.write(str);
|
||
|
}
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline bool
|
||
|
Enum<ENUMTYPE, END, NAMES>::operator==(ENUMTYPE value) const {
|
||
|
return value == _value;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline bool
|
||
|
Enum<ENUMTYPE, END, NAMES>::operator!=(ENUMTYPE value) const {
|
||
|
return value != _value;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline const char* Enum<ENUMTYPE, END, NAMES>::toString() const {
|
||
|
return NAMES::name(_value-0);
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline bool
|
||
|
Enum<ENUMTYPE, END, NAMES>::fromString(const std::string& str) {
|
||
|
int index = int(0);
|
||
|
|
||
|
while( str != std::string(NAMES::name(index-0)) ) {
|
||
|
++index;
|
||
|
if ( index >= int(END) )
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
_value = static_cast<ENUMTYPE>(index);
|
||
|
return true;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline int Enum<ENUMTYPE, END, NAMES>::toInt() const {
|
||
|
return _value;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
||
|
template <typename ENUMTYPE, ENUMTYPE END, typename NAMES>
|
||
|
inline bool
|
||
|
Enum<ENUMTYPE, END, NAMES>::fromInt(int v) {
|
||
|
if ( v < int(0) || v >= int(END) )
|
||
|
return false;
|
||
|
|
||
|
_value = static_cast<ENUMTYPE>(v);
|
||
|
return true;
|
||
|
}
|
||
|
// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
|