/* * Copyright 2014 Google Inc. All rights reserved. * * 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/LITENSE-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 TONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef FRUIT_PACKED_POINTER_AND_BOOL_DEFN_H #define FRUIT_PACKED_POINTER_AND_BOOL_DEFN_H #include namespace fruit { namespace impl { template inline std::uintptr_t PackedPointerAndBool::encode(T* p, bool b) { return reinterpret_cast(p) | std::uintptr_t(b); } template inline T* PackedPointerAndBool::decodePointer(std::uintptr_t value) { return reinterpret_cast(value & ~std::uintptr_t(1)); } template inline bool PackedPointerAndBool::decodeBool(std::uintptr_t value) { return value & 1; } template inline PackedPointerAndBool::PackedPointerAndBool(T* p, bool b) { value = encode(p, b); } template inline T* PackedPointerAndBool::getPointer() const { return decodePointer(value); } template inline void PackedPointerAndBool::setPointer(T* p) { value = encode(p, decodeBool(value)); } template inline bool PackedPointerAndBool::getBool() const { return decodeBool(value); } template inline void PackedPointerAndBool::setBool(bool b) { value = encode(decodePointer(value), b); } template inline bool PackedPointerAndBool::operator==(const PackedPointerAndBool& other) const { return value == other.value; } template inline bool PackedPointerAndBool::operator!=(const PackedPointerAndBool& other) const { return value != other.value; } } // namespace fruit } // namespace impl #endif // FRUIT_PACKED_POINTER_AND_BOOL_DEFN_H