/*************************************************************************** * 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. * ***************************************************************************/ #ifndef SEISCOMP_CORE_METAPROPERTY_H #define SEISCOMP_CORE_METAPROPERTY_H #include #include namespace Seiscomp { namespace Core { namespace Generic { class No { }; class Yes { No no[2]; }; template Yes isOptionalTester(boost::optional*); No isOptionalTester(void*); template class is_optional { static T* t; public: enum { value = sizeof(isOptionalTester(t)) == sizeof(Yes) }; }; template struct remove_optional_helper {}; template struct remove_optional_helper { typedef T type; }; template struct remove_optional_helper { typedef typename T::value_type type; }; template struct remove_optional { typedef typename remove_optional_helper::value>::type type; }; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template class MetaEnumImpl : public MetaEnum { public: MetaEnumImpl() : MetaEnum() {} public: int keyCount() const { return T::Quantity; } //! Returns the key name at a given index const char *key(int index) const; const char *valueToKey(int value) const; int keyToValue(const char *key) const; }; #define DECLARE_METAENUM(CLASS, var) Seiscomp::Core::MetaEnumImpl var // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template inline const char *MetaEnumImpl::key(int index) const { return T::NameDispatcher::name(index); } template inline const char *MetaEnumImpl::valueToKey(int value) const { T tmp; if ( !tmp.fromInt(value) ) throw ValueException("value out of bounds"); return tmp.toString(); } template inline int MetaEnumImpl::keyToValue(const char *key) const { T tmp; if ( !tmp.fromString(key) ) throw ValueException("invalid key"); return tmp.toInt(); } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> template class MetaClassProperty : public MetaProperty { // ------------------------------------------------------------------ // Xstruction // ------------------------------------------------------------------ public: MetaClassProperty() : MetaProperty() {} MetaClassProperty(const std::string& name, const std::string& type, bool isArray, bool isIndex, bool isOptional) : MetaProperty(name, type, isArray, true, isIndex, isOptional, false, false, nullptr) {} public: BaseObject *createClass() const { return new T(); } }; template