Blame include/ceres/internal/port.h

Packit ea1746
// Ceres Solver - A fast non-linear least squares minimizer
Packit ea1746
// Copyright 2015 Google Inc. All rights reserved.
Packit ea1746
// http://ceres-solver.org/
Packit ea1746
//
Packit ea1746
// Redistribution and use in source and binary forms, with or without
Packit ea1746
// modification, are permitted provided that the following conditions are met:
Packit ea1746
//
Packit ea1746
// * Redistributions of source code must retain the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer.
Packit ea1746
// * Redistributions in binary form must reproduce the above copyright notice,
Packit ea1746
//   this list of conditions and the following disclaimer in the documentation
Packit ea1746
//   and/or other materials provided with the distribution.
Packit ea1746
// * Neither the name of Google Inc. nor the names of its contributors may be
Packit ea1746
//   used to endorse or promote products derived from this software without
Packit ea1746
//   specific prior written permission.
Packit ea1746
//
Packit ea1746
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Packit ea1746
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Packit ea1746
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Packit ea1746
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
Packit ea1746
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
Packit ea1746
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
Packit ea1746
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
Packit ea1746
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
Packit ea1746
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
Packit ea1746
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
Packit ea1746
// POSSIBILITY OF SUCH DAMAGE.
Packit ea1746
//
Packit ea1746
// Author: keir@google.com (Keir Mierle)
Packit ea1746
Packit ea1746
#ifndef CERES_PUBLIC_INTERNAL_PORT_H_
Packit ea1746
#define CERES_PUBLIC_INTERNAL_PORT_H_
Packit ea1746
Packit ea1746
// This file needs to compile as c code.
Packit ea1746
#ifdef __cplusplus
Packit ea1746
#include <cstddef>
Packit ea1746
#include "ceres/internal/config.h"
Packit ea1746
#if defined(CERES_TR1_MEMORY_HEADER)
Packit ea1746
#include <tr1/memory>
Packit ea1746
#else
Packit ea1746
#include <memory>
Packit ea1746
#endif
Packit ea1746
Packit ea1746
namespace ceres {
Packit ea1746
Packit ea1746
#if defined(CERES_TR1_SHARED_PTR)
Packit ea1746
using std::tr1::shared_ptr;
Packit ea1746
#else
Packit ea1746
using std::shared_ptr;
Packit ea1746
#endif
Packit ea1746
Packit ea1746
// We allocate some Eigen objects on the stack and other places they
Packit ea1746
// might not be aligned to X(=16 [SSE], 32 [AVX] etc)-byte boundaries.  If we
Packit ea1746
// have C++11, we can specify their alignment (which is desirable, as it means
Packit ea1746
// we can safely enable vectorisation on matrices).  However, the standard gives
Packit ea1746
// wide lattitude as to what alignments are legal.  It must be the case that
Packit ea1746
// alignments up to alignof(std::max_align_t) are valid, but this might be < 16
Packit ea1746
// on some platforms, in which case even if using C++11, on these platforms
Packit ea1746
// we should not attempt to align to X-byte boundaries.  If using < C++11,
Packit ea1746
// we cannot specify the alignment.
Packit ea1746
#ifdef CERES_USE_CXX11
Packit ea1746
namespace port_constants {
Packit ea1746
static constexpr size_t kMaxAlignBytes =
Packit ea1746
    // Work around a GCC 4.8 bug
Packit ea1746
    // (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56019) where
Packit ea1746
    // std::max_align_t is misplaced.
Packit ea1746
#if defined (__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 8
Packit ea1746
    alignof(::max_align_t);
Packit ea1746
#else
Packit ea1746
    alignof(std::max_align_t);
Packit ea1746
#endif
Packit ea1746
}  // namespace port_constants
Packit ea1746
#endif
Packit ea1746
Packit ea1746
}  // namespace ceres
Packit ea1746
Packit ea1746
#endif  // __cplusplus
Packit ea1746
Packit ea1746
// A macro to signal which functions and classes are exported when
Packit ea1746
// building a DLL with MSVC.
Packit ea1746
//
Packit ea1746
// Note that the ordering here is important, CERES_BUILDING_SHARED_LIBRARY
Packit ea1746
// is only defined locally when Ceres is compiled, it is never exported to
Packit ea1746
// users.  However, in order that we do not have to configure config.h
Packit ea1746
// separately for building vs installing, if we are using MSVC and building
Packit ea1746
// a shared library, then both CERES_BUILDING_SHARED_LIBRARY and
Packit ea1746
// CERES_USING_SHARED_LIBRARY will be defined when Ceres is compiled.
Packit ea1746
// Hence it is important that the check for CERES_BUILDING_SHARED_LIBRARY
Packit ea1746
// happens first.
Packit ea1746
#if defined(_MSC_VER) && defined(CERES_BUILDING_SHARED_LIBRARY)
Packit ea1746
# define CERES_EXPORT __declspec(dllexport)
Packit ea1746
#elif defined(_MSC_VER) && defined(CERES_USING_SHARED_LIBRARY)
Packit ea1746
# define CERES_EXPORT __declspec(dllimport)
Packit ea1746
#else
Packit ea1746
# define CERES_EXPORT
Packit ea1746
#endif
Packit ea1746
Packit ea1746
#endif  // CERES_PUBLIC_INTERNAL_PORT_H_