//////////////////////////////////////////////////////////////////////////////// /// DISCLAIMER /// /// Copyright 2016 ArangoDB GmbH, Cologne, Germany /// /// Licensed under the Apache License, Version 2.0 (the "License"); /// you may not use this file except in compliance with the License. /// You may obtain a copy of the License at /// /// http://www.apache.org/licenses/LICENSE-2.0 /// /// Unless required by applicable law or agreed to in writing, software /// distributed under the License is distributed on an "AS IS" BASIS, /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. /// See the License for the specific language governing permissions and /// limitations under the License. /// /// Copyright holder is ArangoDB GmbH, Cologne, Germany /// /// @author Simon Grätzer //////////////////////////////////////////////////////////////////////////////// #ifndef ARANGODB_PREGEL_MFORMAT_H #define ARANGODB_PREGEL_MFORMAT_H 1 #include #include "Basics/Common.h" #include #include #include namespace arangodb { namespace pregel { template struct MessageFormat { virtual ~MessageFormat() = default; virtual void unwrapValue(VPackSlice body, M& value) const = 0; virtual void addValue(VPackBuilder& arrayBuilder, M const& val) const = 0; }; struct IntegerMessageFormat : public MessageFormat { IntegerMessageFormat() {} void unwrapValue(VPackSlice s, int64_t& value) const override { value = s.getInt(); } void addValue(VPackBuilder& arrayBuilder, int64_t const& val) const override { arrayBuilder.add(VPackValue(val)); } }; /* struct DoubleMessageFormat : public MessageFormat { DoubleMessageFormat() {} void unwrapValue(VPackSlice s, double& value) const override { value = s.getDouble(); } void addValue(VPackBuilder& arrayBuilder, double const& val) const override { arrayBuilder.add(VPackValue(val)); } }; struct FloatMessageFormat : public MessageFormat { FloatMessageFormat() {} void unwrapValue(VPackSlice s, float& value) const override { value = (float)s.getDouble(); } void addValue(VPackBuilder& arrayBuilder, float const& val) const override { arrayBuilder.add(VPackValue(val)); } };*/ template struct NumberMessageFormat : public MessageFormat { static_assert(std::is_arithmetic::value, "Message type must be numeric"); NumberMessageFormat() {} void unwrapValue(VPackSlice s, M& value) const override { value = s.getNumber(); } void addValue(VPackBuilder& arrayBuilder, M const& val) const override { arrayBuilder.add(VPackValue(val)); } }; } // namespace pregel } // namespace arangodb #endif