<commit_before>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2014 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include <mapnik/expression_node.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/util/noncopyable.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#if defined(BOOST_REGEX_HAS_ICU)
#include <boost/regex/icu.hpp>
#else
#include <boost/regex.hpp>
#endif
#pragma GCC diagnostic pop

namespace mapnik
{

struct _regex_match_impl : util::noncopyable {
#if defined(BOOST_REGEX_HAS_ICU)
    _regex_match_impl(value_unicode_string const& ustr) :
        pattern_(boost::make_u32regex(ustr)) {}
    boost::u32regex pattern_;
#else
    _regex_match_impl(std::string const& ustr) :
        pattern_(ustr) {}
    boost::regex pattern_;
#endif
};

struct _regex_replace_impl : util::noncopyable {
#if defined(BOOST_REGEX_HAS_ICU)
    _regex_replace_impl(value_unicode_string const& ustr, value_unicode_string const& f) :
        pattern_(boost::make_u32regex(ustr)),
        format_(f) {}
    boost::u32regex pattern_;
    value_unicode_string format_;
#else
    _regex_replace_impl(std::string const& ustr,std::string const& f) :
        pattern_(ustr),
        format_(f) {}
    boost::regex pattern_;
    std::string format_;
#endif
};

regex_match_node::regex_match_node(transcoder const& tr,
                                   expr_node const& a,
                                   std::string const& ustr)
    : expr(a),
      impl_(new _regex_match_impl(
#if defined(BOOST_REGEX_HAS_ICU)
        tr.transcode(ustr.c_str())
#else
        ustr
#endif
        )) {}

value regex_match_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_match(v.to_unicode(),pattern);
#else
    return boost::regex_match(v.to_string(),pattern);
#endif
}

std::string regex_match_node::to_string() const
{
    std::string str_;
    str_ +=".match('";
    auto const& pattern = impl_.get()->pattern_;
#if defined(BOOST_REGEX_HAS_ICU)
    std::string utf8;
    value_unicode_string ustr = value_unicode_string::fromUTF32( &pattern.str()[0], pattern.str().length());
    to_utf8(ustr,utf8);
    str_ += utf8;
#else
    str_ += pattern.str();
#endif
    str_ +="')";
    return str_;
}

regex_replace_node::regex_replace_node(transcoder const& tr,
                                       expr_node const& a,
                                       std::string const& ustr,
                                       std::string const& f)
    : expr(a),
      impl_(new _regex_replace_impl(
#if defined(BOOST_REGEX_HAS_ICU)
                     tr.transcode(ustr.c_str()),
                     tr.transcode(f.c_str())
#else
                     ustr,
                     f
#endif
                     )) {}

value regex_replace_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
    auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_replace(v.to_unicode(),pattern,format);
#else
    std::string repl = boost::regex_replace(v.to_string(),pattern,format);
    transcoder tr_("utf8");
    return tr_.transcode(repl.c_str());
#endif
}

std::string regex_replace_node::to_string() const
{
    std::string str_;
    str_ +=".replace(";
    str_ += "'";
    auto const& pattern = impl_.get()->pattern_;
    auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
    std::string utf8;
    value_unicode_string ustr = value_unicode_string::fromUTF32( &pattern.str()[0], pattern.str().length());
    to_utf8(ustr,utf8);
    str_ += utf8;
    str_ +="','";
    to_utf8(format ,utf8);
    str_ += utf8;
#else
    str_ += pattern.str();
    str_ +="','";
    str_ += format;
#endif
    str_ +="')";
    return str_;
}

}
<commit_msg>use safe_cast to safely handle -Wsign-conversion/narrowing warnings<commit_after>/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2014 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include <mapnik/expression_node.hpp>
#include <mapnik/value_types.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/safe_cast.hpp>

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wsign-conversion"
#if defined(BOOST_REGEX_HAS_ICU)
#include <boost/regex/icu.hpp>
#else
#include <boost/regex.hpp>
#endif
#pragma GCC diagnostic pop

namespace mapnik
{

struct _regex_match_impl : util::noncopyable {
#if defined(BOOST_REGEX_HAS_ICU)
    _regex_match_impl(value_unicode_string const& ustr) :
        pattern_(boost::make_u32regex(ustr)) {}
    boost::u32regex pattern_;
#else
    _regex_match_impl(std::string const& ustr) :
        pattern_(ustr) {}
    boost::regex pattern_;
#endif
};

struct _regex_replace_impl : util::noncopyable {
#if defined(BOOST_REGEX_HAS_ICU)
    _regex_replace_impl(value_unicode_string const& ustr, value_unicode_string const& f) :
        pattern_(boost::make_u32regex(ustr)),
        format_(f) {}
    boost::u32regex pattern_;
    value_unicode_string format_;
#else
    _regex_replace_impl(std::string const& ustr,std::string const& f) :
        pattern_(ustr),
        format_(f) {}
    boost::regex pattern_;
    std::string format_;
#endif
};

regex_match_node::regex_match_node(transcoder const& tr,
                                   expr_node const& a,
                                   std::string const& ustr)
    : expr(a),
      impl_(new _regex_match_impl(
#if defined(BOOST_REGEX_HAS_ICU)
        tr.transcode(ustr.c_str())
#else
        ustr
#endif
        )) {}

value regex_match_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_match(v.to_unicode(),pattern);
#else
    return boost::regex_match(v.to_string(),pattern);
#endif
}

std::string regex_match_node::to_string() const
{
    std::string str_;
    str_ +=".match('";
    auto const& pattern = impl_.get()->pattern_;
#if defined(BOOST_REGEX_HAS_ICU)
    std::string utf8;
    value_unicode_string ustr = value_unicode_string::fromUTF32( &pattern.str()[0], safe_cast<int>(pattern.str().length()));
    to_utf8(ustr,utf8);
    str_ += utf8;
#else
    str_ += pattern.str();
#endif
    str_ +="')";
    return str_;
}

regex_replace_node::regex_replace_node(transcoder const& tr,
                                       expr_node const& a,
                                       std::string const& ustr,
                                       std::string const& f)
    : expr(a),
      impl_(new _regex_replace_impl(
#if defined(BOOST_REGEX_HAS_ICU)
                     tr.transcode(ustr.c_str()),
                     tr.transcode(f.c_str())
#else
                     ustr,
                     f
#endif
                     )) {}

value regex_replace_node::apply(value const& v) const
{
    auto const& pattern = impl_.get()->pattern_;
    auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
    return boost::u32regex_replace(v.to_unicode(),pattern,format);
#else
    std::string repl = boost::regex_replace(v.to_string(),pattern,format);
    transcoder tr_("utf8");
    return tr_.transcode(repl.c_str());
#endif
}

std::string regex_replace_node::to_string() const
{
    std::string str_;
    str_ +=".replace(";
    str_ += "'";
    auto const& pattern = impl_.get()->pattern_;
    auto const& format = impl_.get()->format_;
#if defined(BOOST_REGEX_HAS_ICU)
    std::string utf8;
    value_unicode_string ustr = value_unicode_string::fromUTF32( &pattern.str()[0], safe_cast<int>(pattern.str().length()));
    to_utf8(ustr,utf8);
    str_ += utf8;
    str_ +="','";
    to_utf8(format ,utf8);
    str_ += utf8;
#else
    str_ += pattern.str();
    str_ +="','";
    str_ += format;
#endif
    str_ +="')";
    return str_;
}

}
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2406
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1400478 by johtaylo@johtaylo-jtincrementor-increment on 2017/04/20 03:00:05<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2407
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2479
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1449431 by johtaylo@johtaylo-jtincrementor-increment on 2017/08/19 03:00:05<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 2480
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1946
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1211815 by johtaylo@johtaylo-JTBUILDER03-increment on 2015/11/17 03:00:10<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1947
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1977
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1222201 by johtaylo@johtaylo-JTBUILDER03-increment on 2015/12/18 03:00:12<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1978
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2265
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1337110 by johtaylo@johtaylo-jtincrementor-increment on 2016/11/05 03:00:03<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2266
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3037
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<commit_msg>P4 to Git Change 2030347 by chui@ocl-promo-incrementor on 2019/11/14 03:00:09<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
#define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif  // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
#define AMD_PLATFORM_BUILD_NUMBER 3038
#endif  // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
#define AMD_PLATFORM_REVISION_NUMBER 0
#endif  // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
#define AMD_PLATFORM_RELEASE_INFO
#endif  // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING                                                                           \
  XSTR(AMD_PLATFORM_BUILD_NUMBER)                                                                  \
  "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
#define AMD_PLATFORM_INFO                                                                          \
  "AMD-APP" AMD_PLATFORM_RELEASE_INFO DEBUG_ONLY(                                                  \
      "." IF(IS_OPTIMIZED, "opt", "dbg")) " (" AMD_BUILD_STRING ")"
#endif  // ATI_PLATFORM_INFO

#endif  // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1931
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1206344 by johtaylo@johtaylo-JTBUILDER03-increment on 2015/11/02 03:00:11<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 1932
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2045
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<commit_msg>P4 to Git Change 1241072 by johtaylo@johtaylo-JTBUILDER03-increment on 2016/02/26 03:00:11<commit_after>//
// Copyright (c) 2010 Advanced Micro Devices, Inc. All rights reserved.
//

#ifndef VERSIONS_HPP_
#define VERSIONS_HPP_

#include "utils/macros.hpp"

#ifndef AMD_PLATFORM_NAME
# define AMD_PLATFORM_NAME "AMD Accelerated Parallel Processing"
#endif // AMD_PLATFORM_NAME

#ifndef AMD_PLATFORM_BUILD_NUMBER
# define AMD_PLATFORM_BUILD_NUMBER 2046
#endif // AMD_PLATFORM_BUILD_NUMBER

#ifndef AMD_PLATFORM_REVISION_NUMBER
# define AMD_PLATFORM_REVISION_NUMBER 0
#endif // AMD_PLATFORM_REVISION_NUMBER

#ifndef AMD_PLATFORM_RELEASE_INFO
# define AMD_PLATFORM_RELEASE_INFO
#endif // AMD_PLATFORM_RELEASE_INFO

#define AMD_BUILD_STRING XSTR(AMD_PLATFORM_BUILD_NUMBER) \
    "." XSTR(AMD_PLATFORM_REVISION_NUMBER)

#ifndef AMD_PLATFORM_INFO
# define AMD_PLATFORM_INFO "AMD-APP" AMD_PLATFORM_RELEASE_INFO \
    DEBUG_ONLY("." IF(IS_OPTIMIZED,"opt","dbg")) " (" AMD_BUILD_STRING ")"
#endif // ATI_PLATFORM_INFO

#endif // VERSIONS_HPP_
<|endoftext|>


<commit_before>#include "featuresmanager.h"

#include <functional>
#include <fstream>
#include "exchangemanager.h"
#include "features.h"

static const unsigned int MIN_SEQUENCE_SIZE = 5; // Otherwise, the sequence is ignored

bool replace(std::string &str, const std::string &from, const std::string &to)
{
    size_t start_pos = str.find(from);
    if(start_pos == std::string::npos)
        return false;
    str.replace(start_pos, from.length(), to);
    return true;
}

FeaturesManager::FeaturesManager()
{
    // Loading the lists of sequences

    ifstream fileListPersons("../../Data/Traces/traces.txt");
    if(!fileListPersons.is_open())
    {
        cout << "Error: Impossible to load the trace file" << endl;
        exit(0);
    }

    // /!\ Warning: No verification on the file

    Sequence *currentSequence = nullptr;
    for(string line; std::getline(fileListPersons, line); )
    {
        // If new group of image
        if(line.find("-----") != std::string::npos)
        {
            replace(line, "----- ", "");
            replace(line, " -----", "");

            listSequences.push_back(Sequence(line));
            currentSequence = &listSequences.back();
        }
        // The associated camera information file
        else if(line.find("_cam") != std::string::npos)
        {
            currentSequence->setCamInfoId(line);
        }
        // Otherwise, simply add the image to the current person
        else
        {
            currentSequence->addImageId(line);
        }
    }

    fileListPersons.close();

    // Start with the first sequence
    currentSequenceId = 0;

    // Allocation of the array
    arrayToSend = nullptr;
}

FeaturesManager::~FeaturesManager()
{
    delete arrayToSend;
}

void FeaturesManager::sendNext()
{
    if(ExchangeManager::getInstance().getIsActive() &&
            !ExchangeManager::getInstance().getIsLocked() &&
            currentSequenceId < listSequences.size())
    {
        Sequence &currentSequence = listSequences.at(currentSequenceId);
        cout << "Sequence: " << currentSequence.getName() << endl;
        if(currentSequence.getListImageIds().size() < MIN_SEQUENCE_SIZE)
        {
            cout << "Sequence ignored (too short)"<< endl;
        }
        else
        {
            vector<FeaturesElement> listCurrentSequenceFeatures;

            // Selection of some images of the sequence (we don't send the entire sequence)
            for(unsigned int i = 0 ; i < MIN_SEQUENCE_SIZE ; ++i)
            {
                listCurrentSequenceFeatures.push_back(FeaturesElement());
                int index = i * ((currentSequence.getListImageIds().size()-1)/MIN_SEQUENCE_SIZE); // Linear function (0,0) to (MIN_SEQUENCE_SIZE, listImageIds().size()-1)
                Features::computeFeature("../../Data/Traces/" + currentSequence.getListImageIds().at(index), listCurrentSequenceFeatures.back());
            }

            // Fill the array

            size_t arrayToSendSize = 0; // Offset
            if(sizeof(size_t)/sizeof(float) != 2) // Depending of the computer architecture
            {
                cout << "Error: wrong architecture 2!=" << sizeof(size_t)/sizeof(float) << ", cannot send the size_t" << endl;
            }
            arrayToSendSize += 2; // Hashcode sequence name
            arrayToSendSize += 2; // Hashcode camera name
            arrayToSendSize += 2; // Entrance and exit time
            arrayToSendSize += 4; // Entrance and exit vectors

            Features::computeArray(arrayToSend, arrayToSendSize, listCurrentSequenceFeatures);

            // Add offset values to the array
            computeAddInfo(arrayToSend, currentSequence);

            // Send the features over the network
            ExchangeManager::getInstance().publishFeatures(arrayToSendSize*sizeof(float),arrayToSend);
        }
        ++currentSequenceId;
    }
}

void FeaturesManager::computeAddInfo(float *&array, const Sequence &sequence)
{
    if(sizeof(float) != sizeof(int)) // For casting
    {
        cout << "Error: convertion float<->int impossible" << endl;
        exit(0);
    }

    int value = 0; // Used as intermediate for bit copy into float

    FileStorage fileTraceCam("../../Data/Traces/" + sequence.getCamInfoId() + ".yml", FileStorage::READ);
    if(!fileTraceCam.isOpened())
    {
        cout << "Error: Cannot open the additional information file for the sequence " << sequence.getCamInfoId() << endl;
        exit(0);
    }

    // Save the sequence name id
    size_t hashCode = 0;
    unsigned int mostSignificantBits = 0;
    unsigned int leastSignificantBits = 0;

    hashCode = std::hash<std::string>()(sequence.getName()); // Hashcode used as id

    leastSignificantBits = hashCode & 0xFFFFFFFF;
    mostSignificantBits = hashCode >> 32 & 0xFFFFFFFF;
    array[0] = reinterpret_cast<float&>(leastSignificantBits);
    array[1] = reinterpret_cast<float&>(mostSignificantBits);

    // Save the cam id
    hashCode = std::hash<std::string>()(fileTraceCam["camId"]);

    leastSignificantBits = hashCode & 0xFFFFFFFF;
    mostSignificantBits = hashCode >> 32 & 0xFFFFFFFF;
    array[2] = reinterpret_cast<float&>(leastSignificantBits);
    array[3] = reinterpret_cast<float&>(mostSignificantBits);

    // Save the entrance and exit time
    value = fileTraceCam["beginDate"];
    array[4] = reinterpret_cast<float&>(value);
    value = fileTraceCam["endDate"];
    array[5] = reinterpret_cast<float&>(value);

    // Save the entrance and exit direction
    FileNode nodeVector;
    cv::Vec2f directionVector;

    nodeVector = fileTraceCam["entranceVector"];
    directionVector = Vec2f(static_cast<float>(nodeVector["x2"]) - static_cast<float>(nodeVector["x1"]),
                            static_cast<float>(nodeVector["y2"]) - static_cast<float>(nodeVector["y1"]));
    cv::normalize(directionVector, directionVector);
    array[6] = directionVector[0];
    array[7] = directionVector[1];

    nodeVector = fileTraceCam["exitVector"];
    directionVector = Vec2f(static_cast<float>(nodeVector["x2"]) - static_cast<float>(nodeVector["x1"]),
                            static_cast<float>(nodeVector["y2"]) - static_cast<float>(nodeVector["y1"]));
    cv::normalize(directionVector, directionVector);
    array[8] = directionVector[0];
    array[9] = directionVector[1];

    fileTraceCam.release();
}
<commit_msg>Send complete direction vector (also the initial position)<commit_after>#include "featuresmanager.h"

#include <functional>
#include <fstream>
#include "exchangemanager.h"
#include "features.h"

static const unsigned int MIN_SEQUENCE_SIZE = 5; // Otherwise, the sequence is ignored

bool replace(std::string &str, const std::string &from, const std::string &to)
{
    size_t start_pos = str.find(from);
    if(start_pos == std::string::npos)
        return false;
    str.replace(start_pos, from.length(), to);
    return true;
}

FeaturesManager::FeaturesManager()
{
    // Loading the lists of sequences

    ifstream fileListPersons("../../Data/Traces/traces.txt");
    if(!fileListPersons.is_open())
    {
        cout << "Error: Impossible to load the trace file" << endl;
        exit(0);
    }

    // /!\ Warning: No verification on the file

    Sequence *currentSequence = nullptr;
    for(string line; std::getline(fileListPersons, line); )
    {
        // If new group of image
        if(line.find("-----") != std::string::npos)
        {
            replace(line, "----- ", "");
            replace(line, " -----", "");

            listSequences.push_back(Sequence(line));
            currentSequence = &listSequences.back();
        }
        // The associated camera information file
        else if(line.find("_cam") != std::string::npos)
        {
            currentSequence->setCamInfoId(line);
        }
        // Otherwise, simply add the image to the current person
        else
        {
            currentSequence->addImageId(line);
        }
    }

    fileListPersons.close();

    // Start with the first sequence
    currentSequenceId = 0;

    // Allocation of the array
    arrayToSend = nullptr;
}

FeaturesManager::~FeaturesManager()
{
    delete arrayToSend;
}

void FeaturesManager::sendNext()
{
    if(ExchangeManager::getInstance().getIsActive() &&
            !ExchangeManager::getInstance().getIsLocked() &&
            currentSequenceId < listSequences.size())
    {
        Sequence &currentSequence = listSequences.at(currentSequenceId);
        cout << "Sequence: " << currentSequence.getName() << endl;
        if(currentSequence.getListImageIds().size() < MIN_SEQUENCE_SIZE)
        {
            cout << "Sequence ignored (too short)"<< endl;
        }
        else
        {
            vector<FeaturesElement> listCurrentSequenceFeatures;

            // Selection of some images of the sequence (we don't send the entire sequence)
            for(unsigned int i = 0 ; i < MIN_SEQUENCE_SIZE ; ++i)
            {
                listCurrentSequenceFeatures.push_back(FeaturesElement());
                int index = i * ((currentSequence.getListImageIds().size()-1)/MIN_SEQUENCE_SIZE); // Linear function (0,0) to (MIN_SEQUENCE_SIZE, listImageIds().size()-1)
                Features::computeFeature("../../Data/Traces/" + currentSequence.getListImageIds().at(index), listCurrentSequenceFeatures.back());
            }

            // Fill the array

            size_t arrayToSendSize = 0; // Offset
            if(sizeof(size_t)/sizeof(float) != 2) // Depending of the computer architecture
            {
                cout << "Error: wrong architecture 2!=" << sizeof(size_t)/sizeof(float) << ", cannot send the size_t" << endl;
            }
            arrayToSendSize += 2; // Hashcode sequence name
            arrayToSendSize += 2; // Hashcode camera name
            arrayToSendSize += 2; // Entrance and exit time
            arrayToSendSize += 8; // Entrance and exit vectors

            Features::computeArray(arrayToSend, arrayToSendSize, listCurrentSequenceFeatures);

            // Add offset values to the array
            computeAddInfo(arrayToSend, currentSequence);

            // Send the features over the network
            ExchangeManager::getInstance().publishFeatures(arrayToSendSize*sizeof(float),arrayToSend);
        }
        ++currentSequenceId;
    }
}

void FeaturesManager::computeAddInfo(float *&array, const Sequence &sequence)
{
    if(sizeof(float) != sizeof(int)) // For casting
    {
        cout << "Error: convertion float<->int impossible" << endl;
        exit(0);
    }

    int value = 0; // Used as intermediate for bit copy into float

    FileStorage fileTraceCam("../../Data/Traces/" + sequence.getCamInfoId() + ".yml", FileStorage::READ);
    if(!fileTraceCam.isOpened())
    {
        cout << "Error: Cannot open the additional information file for the sequence " << sequence.getCamInfoId() << endl;
        exit(0);
    }

    // Save the sequence name id
    size_t hashCode = 0;
    unsigned int mostSignificantBits = 0;
    unsigned int leastSignificantBits = 0;

    hashCode = std::hash<std::string>()(sequence.getName()); // Hashcode used as id

    leastSignificantBits = hashCode & 0xFFFFFFFF;
    mostSignificantBits = hashCode >> 32 & 0xFFFFFFFF;
    array[0] = reinterpret_cast<float&>(leastSignificantBits);
    array[1] = reinterpret_cast<float&>(mostSignificantBits);

    // Save the cam id
    hashCode = std::hash<std::string>()(fileTraceCam["camId"]);

    leastSignificantBits = hashCode & 0xFFFFFFFF;
    mostSignificantBits = hashCode >> 32 & 0xFFFFFFFF;
    array[2] = reinterpret_cast<float&>(leastSignificantBits);
    array[3] = reinterpret_cast<float&>(mostSignificantBits);

    // Save the entrance and exit time
    value = fileTraceCam["beginDate"];
    array[4] = reinterpret_cast<float&>(value);
    value = fileTraceCam["endDate"];
    array[5] = reinterpret_cast<float&>(value);

    // Save the entrance and exit direction
    FileNode nodeVector;

    nodeVector = fileTraceCam["entranceVector"];
    array[6] = static_cast<float>(nodeVector["x1"]);
    array[7] = static_cast<float>(nodeVector["y1"]);
    array[8] = static_cast<float>(nodeVector["x2"]);
    array[9] = static_cast<float>(nodeVector["y2"]);

    nodeVector = fileTraceCam["exitVector"];
    array[10] = static_cast<float>(nodeVector["x1"]);
    array[11] = static_cast<float>(nodeVector["y1"]);
    array[12] = static_cast<float>(nodeVector["x2"]);
    array[13] = static_cast<float>(nodeVector["y2"]);

    fileTraceCam.release();
}
<|endoftext|>


<commit_before>#pragma once

#include <string>

#include <cstring>

#include <boost/noncopyable.hpp>

#include "error_checked.hpp"

namespace rusql { namespace mysql {
	//! A wrapper around MYSQL (the struct), symbolizing a connection.
	struct Connection : boost::noncopyable {
		Connection() {
			memset(&database, 0, sizeof(MYSQL));
			init();
		}

		Connection(MYSQL&& database_)
		: database(std::move(database_))
		{}

		~Connection() {
			rusql::mysql::close(&database);
		}

		MYSQL database;

		inline MYSQL* init(){
			return rusql::mysql::init(&database);
		}

		inline int ping(){
			return rusql::mysql::ping(&database);
		}

		inline MYSQL_RES* use_result(){
			return rusql::mysql::use_result(&database);
		}

		inline size_t field_count(){
			return rusql::mysql::field_count(&database);
		}

		inline unsigned long long insert_id() {
			return rusql::mysql::insert_id(&database);
		}

		inline MYSQL_STMT* stmt_init(){
			return rusql::mysql::stmt_init(&database);
		}

		inline MYSQL* connect(std::string const host, int const port, std::string const user, std::string const password, std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, host, user, password, database_, port, boost::none, client_flag);
		}

		inline MYSQL* connect(std::string const unix_socket, std::string const user, std::string const password, std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, boost::none, user, password, database_, 0, unix_socket, client_flag);
		}

		inline MYSQL* connect(std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, boost::none, boost::none, boost::none, database_, 0, boost::none, client_flag);
		}

		inline void query(std::string const query_string) {
			return rusql::mysql::query(&database, query_string);
		}
	};
}}
<commit_msg>Swallow exception after closing mysql::Connection. Irrelevant at that point anyway.<commit_after>#pragma once

#include <string>

#include <cstring>

#include <boost/noncopyable.hpp>

#include "error_checked.hpp"

namespace rusql { namespace mysql {
	//! A wrapper around MYSQL (the struct), symbolizing a connection.
	struct Connection : boost::noncopyable {
		Connection() {
			memset(&database, 0, sizeof(MYSQL));
			init();
		}

		Connection(MYSQL&& database_)
		: database(std::move(database_))
		{}

		~Connection() {
			try
			{
				rusql::mysql::close(&database);
			} catch(const SQLError& e)
			{
				std::cerr << "Exception when closing Connection, ignoring: " << e.what() << std::endl;
			}
		}

		MYSQL database;

		inline MYSQL* init(){
			return rusql::mysql::init(&database);
		}

		inline int ping(){
			return rusql::mysql::ping(&database);
		}

		inline MYSQL_RES* use_result(){
			return rusql::mysql::use_result(&database);
		}

		inline size_t field_count(){
			return rusql::mysql::field_count(&database);
		}

		inline unsigned long long insert_id() {
			return rusql::mysql::insert_id(&database);
		}

		inline MYSQL_STMT* stmt_init(){
			return rusql::mysql::stmt_init(&database);
		}

		inline MYSQL* connect(std::string const host, int const port, std::string const user, std::string const password, std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, host, user, password, database_, port, boost::none, client_flag);
		}

		inline MYSQL* connect(std::string const unix_socket, std::string const user, std::string const password, std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, boost::none, user, password, database_, 0, unix_socket, client_flag);
		}

		inline MYSQL* connect(std::string const database_, unsigned long const client_flag){
			return rusql::mysql::connect(&database, boost::none, boost::none, boost::none, database_, 0, boost::none, client_flag);
		}

		inline void query(std::string const query_string) {
			return rusql::mysql::query(&database, query_string);
		}
	};
}}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: SlideSorterController.hxx,v $
 *
 *  $Revision: 1.11 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-09 06:18:21 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef SD_SLIDESORTER_SLIDE_SORTER_CONTROLLER_HXX
#define SD_SLIDESORTER_SLIDE_SORTER_CONTROLLER_HXX

#include "ViewShell.hxx"

#ifndef _SFX_SHELL_HXX
#include <sfx2/shell.hxx>
#endif
#ifndef _VIEWFAC_HXX
#include <sfx2/viewfac.hxx>
#endif
#ifndef _LINK_HXX
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#include <memory>
#include <comphelper/implementationreference.hxx>

class TabBar;

namespace sd { namespace slidesorter {
class SlideSorterViewShell;
} }

namespace sd { namespace slidesorter { namespace view {
class SlideSorterView;
} } }

namespace sd { namespace slidesorter { namespace model {
class SlideSorterModel;
class PageDescriptor;
} } }

namespace sd { namespace slidesorter { namespace controller {

class Clipboard;
class FocusManager;
class Listener;
class PageSelector;
class ScrollBarManager;
class SlotManager;

class SlideSorterController
{
public:
    /** Create a new controller for the slide sorter.
        @param pParentWindow
            The window that contains the controls of the new
            controller.
    */
    SlideSorterController (
        SfxViewFrame *pFrame,
        ::Window* pParentWindow,
        SlideSorterViewShell& rViewShell,
        model::SlideSorterModel& rModel,
        view::SlideSorterView& rView);

    /** Late initialization.  Call this method once a new new object has been
        created.
    */
    virtual void Init (void);

    virtual ~SlideSorterController (void);

    /** Place and size the scroll bars and the browser window so that the
        given rectangle is filled.
        @return
            The space occupied by the browser window is returned.
    */
    Rectangle Resize (const Rectangle& rAvailableSpace);

    /** Determine which of the UI elements--the scroll bars, the scroll bar
        filler, the actual slide sorter view--are visible and place them in
        the area last passed to Resize().
        @param bForce
            When <TRUE/> is given (<FALSE/> is the default) then the content
            window and with it the SlideSorterView is resized event when its
            size does not change (the size does change when the visibility
            of scroll bars changes.)
        @return
            Returns the space occupied by the browser window.
    */
    Rectangle Rearrange (bool bForce = false);

    SlideSorterViewShell& GetViewShell (void) const;
    model::SlideSorterModel& GetModel (void) const;
    view::SlideSorterView& GetView (void) const;

    /** Return the descriptor of the page that is rendered under the
        given position.
        @return
            Returns a pointer to a page descriptor instead of a
            reference because when no page is found at the position
            then NULL is returned to indicate this.
    */
    model::PageDescriptor* GetPageAt (const Point& rPixelPosition);

    /** Return the descriptor of the page that is associated to the page
        visible fade symbol at the given position.
        @return
            When the given position is not over a visible page fade symbol
            then NULL is returned.
    */
    model::PageDescriptor* GetFadePageAt (const Point& rPixelPosition);

    PageSelector& GetPageSelector (void);
    FocusManager& GetFocusManager (void);
    controller::Clipboard& GetClipboard (void);

    /** Return the object that manages the scroll bars.
    */
    ScrollBarManager& GetScrollBarManager (void);

    /** This method forwards the call to the SlideSorterView and executes
        pending operations like moving selected pages into the visible area.
    */
    void Paint (const Rectangle& rRect, ::sd::Window* pWin);

    /** The name of this method is taken from the ViewShell class.  It
        returns the page that (hopefully) has currently the attention of the
        user.
        @return
            When the slide sorter is not displayed in the center pane then
            the current page of the center pane view shell is returned.
            Other wise the focused page is returned or, if the focus
            indicator is not currently visible, the first selected page is
            returned.  If all that fails then NULL is returned.
    */
    SdPage* GetActualPage (void);

    void FuTemporary (SfxRequest& rRequest);
    void FuPermanent (SfxRequest& rRequest);
    void FuSupport (SfxRequest& rRequest);
    bool Command (
        const CommandEvent& rEvent,
        ::sd::Window* pWindow);

    void GetCtrlState (SfxItemSet &rSet);
    void GetMenuState (SfxItemSet &rSet);
    void GetStatusBarState (SfxItemSet& rSet);

    void ExecCtrl (SfxRequest& rRequest);
    void GetAttrState (SfxItemSet& rSet);
    void ExecStatusBar (SfxRequest& rRequest);

    /** Prepare for several model changes, i.e. prevent time-consuming and
        non-critical operations like repaints until UnlockModelChange() is
        called.  Ciritcal operations like releasing references to pages that
        do not exist anymore are executed.
    */
    void LockModelChange (void);

    /** Further calls to HandleModelChange() will result in a full featured
        update of model, view, and controller.  When HandleModelChange() has
        been called since the last LockModelChange() then this is done right
        away to bring the view up-to-date.
    */
    void UnlockModelChange (void);

    /** Create an object of this inner class to prevent updates due to model
        changes.
    */
    class ModelChangeLock
    {public:
        ModelChangeLock (SlideSorterController& rController);
        ~ModelChangeLock (void);
        void ModelHasChanged (void);
    private:
        SlideSorterController& mrController;
    };

    /** Prepare for a model change.  This method does all the things that
        need to be done _before_ the model changes, e.g. because they need
        access to the model data before the change.
    */
    void PreModelChange (void);

    /** Complete a model change.  This includes the recreation of data
        structures that depend on the model and the request for a repaint to
        show the changes.
    */
    void PostModelChange (void);

    /** Handle a change of the model, that is, handle the removal and
        insertion of whole pages or a change of the edit mode.

        This method is a convenience function that simply calls
        PreModelChange() and then PostModelChange().
    */
    void HandleModelChange (void);

    void DeleteSelectedPages (void);

    /** Move the maked pages to a position directly after the specified page.
    */
    bool MoveSelectedPages (USHORT nTargetPage);

    DECL_LINK(TabBarHandler, TabBar*);
    DECL_LINK(WindowEventHandler, VclWindowEvent*);

    /** Update the display of all pages.  This involves a redraw and
        releasing previews and caches.
    */
    void UpdateAllPages (void);

    /** Call this method after the selection has changed (possible several
        calls to the PageSelector) to invalidate the relevant slots and send
        appropriate events.
    */
    void SelectionHasChanged (bool bMakeSelectionVisible = true);

    enum SelectionHint { SH_FIRST, SH_LAST, SH_RECENT };

    /** Try to make all currently selected page objects visible, i.e. set
        the origin so that the page objects lie inside the visible area.
        When the selection is empty then the visible area is not modified.
        @param eSelectionHint
            This is an advice on which selected page object to handle with
            the highest priority when the whole selection does not fit in to
            the visible area.
        @return
            Returns the vertical translation of the visible area.  It is 0
            when no update of the visible area was done.
    */
    sal_Int32 MakeSelectionVisible (
        SelectionHint eSelectionHint = SH_RECENT);

    /** Modify the origin of the visible area so that the given rectangle
        comes into view.  This is done with the smallest change: no
        scrolling takes place when the given rectangle already lies in the
        visible area.  Otherwise either the top or the bottom of the given
        rectangle is aligned with the top or the bottom of the visible area.
        @return
            Returns the vertical translation of the visible area.  It is 0
            when no update of the visible area was done.
    */
    sal_Int32 MakeRectangleVisible (const Rectangle& rBox);

    /** Set the zoom factor.  The given value is clipped against an upper
        bound.
        @param nZoom
            An integer percent value, i.e. nZoom/100 is the actual zoom
            factor.
        */
    void SetZoom (long int nZoom);

    /** This factory method creates a selection function.
    */
    virtual FuPoor* CreateSelectionFunction (SfxRequest& rRequest);

    /** Add a listener that is called when the selection of the slide sorter
        changes.
        @param rListener
            When this method is called multiple times for the same listener
            the second and all following calls are ignored.  Each listener
            is added only once.
    */
    void AddSelectionChangeListener (const Link& rListener);

    /** Remove a listener that was called when the selection of the slide
        sorter changes.
        @param rListener
            It is save to pass a listener that was not added are has been
            removed previously.  Such calls are ignored.
    */
    void RemoveSelectionChangeListener (const Link& rListener);

    /** Prepare for a change of the edit mode.  Depending on the current
        edit mode we may save the selection so that it can be restored when
        later changing back to the current edit mode.
    */
    void PrepareEditModeChange (void);

    /** Set a new edit mode and return whether the edit mode really
        has been changed.  For proper saving and restoring of the selection
        this method should be called between calls to
        PrepareEditModeChange() and FinishEditModeChange().
        @return
            A return value of <TRUE/> indicates that the edit mode has
            changed.
    */
    bool ChangeEditMode (EditMode eEditMode);

    /** Finish the change of the edit mode.  Here we may select a page or
        restore a previously saved selection.
    */
    void FinishEditModeChange (void);

private:
    SlideSorterViewShell& mrViewShell;
    model::SlideSorterModel& mrModel;
    view::SlideSorterView& mrView;
    ::std::auto_ptr<PageSelector> mpPageSelector;
    ::std::auto_ptr<FocusManager> mpFocusManager;
    ::std::auto_ptr<SlotManager> mpSlotManager;
    ::std::auto_ptr<controller::Clipboard> mpClipboard;
    ::std::auto_ptr<ScrollBarManager> mpScrollBarManager;

    // The listener listens to UNO events and thus is a UNO object.
    // For proper life time management and at the same time free access to
    // the implementation object we use the ImplementationReference class.
    ::comphelper::ImplementationReference
        <controller::Listener,
        ::com::sun::star::uno::XInterface,
         ::com::sun::star::uno::XWeak>
        mpListener;

    int mnModelChangeLockCount;

    /** In this flag we remember whether a call to PreModelChange() has been
        made and one to PostModelChange() is pending.
    */
    bool mbPostModelChangePending;

    ::std::vector<Link> maSelectionChangeListeners;

    /** This array stores the indices of the  selected page descriptors at
        the time when the edit mode is switched to EM_MASTERPAGE.  With this
        we can restore the selection when switching back to EM_PAGE mode.
    */
    ::std::vector<SdPage*> maSelectionBeforeSwitch;
    /// The current page before the edit mode is switched to EM_MASTERPAGE.
    int mnCurrentPageBeforeSwitch;

    /** The master page to select after the edit mode is changed.  This
        member is used to pass the pointer from PrepareEditModeChange() to
        FinishEditModeChange().
    */
    SdPage* mpEditModeChangeMasterPage;

    /** This rectangle in the parent window encloses scroll bars and slide
        sorter window.  It is set when Resize() is called.
    */
    Rectangle maTotalWindowArea;

    /** When this flag is set then on the next call to Paint() the selection
        is moved into the visible area.
    */
    bool mbIsMakeSelectionVisiblePending;

    /** This counter is used to avoid processing of reentrant calls to
        Paint().
    */
    sal_Int32 mnPaintEntranceCount;

    /** Delete the given list of normal pages.  This method is a helper
        function for DeleteSelectedPages().
        @param rSelectedNormalPages
            A list of normal pages.  Supplying master pages is an error.
    */
    void DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedNormalPages);

    /** Delete the given list of master pages.  This method is a helper
        function for DeleteSelectedPages().
        @param rSelectedMasterPages
            A list of master pages.  Supplying normal pages is an error.
    */
    void DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedMasterPages);
};

} } } // end of namespace ::sd::slidesorter::controller

#endif
<commit_msg>INTEGRATION: CWS impressfunctions (1.11.42); FILE MERGED 2005/10/28 11:00:53 cl 1.11.42.1: #125341# reworked FuPoor classes to use refcounting<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: SlideSorterController.hxx,v $
 *
 *  $Revision: 1.12 $
 *
 *  last change: $Author: rt $ $Date: 2005-12-14 17:21:48 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef SD_SLIDESORTER_SLIDE_SORTER_CONTROLLER_HXX
#define SD_SLIDESORTER_SLIDE_SORTER_CONTROLLER_HXX

#include "ViewShell.hxx"

#ifndef _SFX_SHELL_HXX
#include <sfx2/shell.hxx>
#endif
#ifndef _VIEWFAC_HXX
#include <sfx2/viewfac.hxx>
#endif
#ifndef _LINK_HXX
#include <tools/link.hxx>
#endif
#ifndef _SV_GEN_HXX
#include <tools/gen.hxx>
#endif
#include <memory>
#include <comphelper/implementationreference.hxx>

class TabBar;

namespace sd { namespace slidesorter {
class SlideSorterViewShell;
} }

namespace sd { namespace slidesorter { namespace view {
class SlideSorterView;
} } }

namespace sd { namespace slidesorter { namespace model {
class SlideSorterModel;
class PageDescriptor;
} } }

namespace sd { namespace slidesorter { namespace controller {

class Clipboard;
class FocusManager;
class Listener;
class PageSelector;
class ScrollBarManager;
class SlotManager;

class SlideSorterController
{
public:
    /** Create a new controller for the slide sorter.
        @param pParentWindow
            The window that contains the controls of the new
            controller.
    */
    SlideSorterController (
        SfxViewFrame *pFrame,
        ::Window* pParentWindow,
        SlideSorterViewShell& rViewShell,
        model::SlideSorterModel& rModel,
        view::SlideSorterView& rView);

    /** Late initialization.  Call this method once a new new object has been
        created.
    */
    virtual void Init (void);

    virtual ~SlideSorterController (void);

    /** Place and size the scroll bars and the browser window so that the
        given rectangle is filled.
        @return
            The space occupied by the browser window is returned.
    */
    Rectangle Resize (const Rectangle& rAvailableSpace);

    /** Determine which of the UI elements--the scroll bars, the scroll bar
        filler, the actual slide sorter view--are visible and place them in
        the area last passed to Resize().
        @param bForce
            When <TRUE/> is given (<FALSE/> is the default) then the content
            window and with it the SlideSorterView is resized event when its
            size does not change (the size does change when the visibility
            of scroll bars changes.)
        @return
            Returns the space occupied by the browser window.
    */
    Rectangle Rearrange (bool bForce = false);

    SlideSorterViewShell& GetViewShell (void) const;
    model::SlideSorterModel& GetModel (void) const;
    view::SlideSorterView& GetView (void) const;

    /** Return the descriptor of the page that is rendered under the
        given position.
        @return
            Returns a pointer to a page descriptor instead of a
            reference because when no page is found at the position
            then NULL is returned to indicate this.
    */
    model::PageDescriptor* GetPageAt (const Point& rPixelPosition);

    /** Return the descriptor of the page that is associated to the page
        visible fade symbol at the given position.
        @return
            When the given position is not over a visible page fade symbol
            then NULL is returned.
    */
    model::PageDescriptor* GetFadePageAt (const Point& rPixelPosition);

    PageSelector& GetPageSelector (void);
    FocusManager& GetFocusManager (void);
    controller::Clipboard& GetClipboard (void);

    /** Return the object that manages the scroll bars.
    */
    ScrollBarManager& GetScrollBarManager (void);

    /** This method forwards the call to the SlideSorterView and executes
        pending operations like moving selected pages into the visible area.
    */
    void Paint (const Rectangle& rRect, ::sd::Window* pWin);

    /** The name of this method is taken from the ViewShell class.  It
        returns the page that (hopefully) has currently the attention of the
        user.
        @return
            When the slide sorter is not displayed in the center pane then
            the current page of the center pane view shell is returned.
            Other wise the focused page is returned or, if the focus
            indicator is not currently visible, the first selected page is
            returned.  If all that fails then NULL is returned.
    */
    SdPage* GetActualPage (void);

    void FuTemporary (SfxRequest& rRequest);
    void FuPermanent (SfxRequest& rRequest);
    void FuSupport (SfxRequest& rRequest);
    bool Command (
        const CommandEvent& rEvent,
        ::sd::Window* pWindow);

    void GetCtrlState (SfxItemSet &rSet);
    void GetMenuState (SfxItemSet &rSet);
    void GetStatusBarState (SfxItemSet& rSet);

    void ExecCtrl (SfxRequest& rRequest);
    void GetAttrState (SfxItemSet& rSet);
    void ExecStatusBar (SfxRequest& rRequest);

    /** Prepare for several model changes, i.e. prevent time-consuming and
        non-critical operations like repaints until UnlockModelChange() is
        called.  Ciritcal operations like releasing references to pages that
        do not exist anymore are executed.
    */
    void LockModelChange (void);

    /** Further calls to HandleModelChange() will result in a full featured
        update of model, view, and controller.  When HandleModelChange() has
        been called since the last LockModelChange() then this is done right
        away to bring the view up-to-date.
    */
    void UnlockModelChange (void);

    /** Create an object of this inner class to prevent updates due to model
        changes.
    */
    class ModelChangeLock
    {public:
        ModelChangeLock (SlideSorterController& rController);
        ~ModelChangeLock (void);
        void ModelHasChanged (void);
    private:
        SlideSorterController& mrController;
    };

    /** Prepare for a model change.  This method does all the things that
        need to be done _before_ the model changes, e.g. because they need
        access to the model data before the change.
    */
    void PreModelChange (void);

    /** Complete a model change.  This includes the recreation of data
        structures that depend on the model and the request for a repaint to
        show the changes.
    */
    void PostModelChange (void);

    /** Handle a change of the model, that is, handle the removal and
        insertion of whole pages or a change of the edit mode.

        This method is a convenience function that simply calls
        PreModelChange() and then PostModelChange().
    */
    void HandleModelChange (void);

    void DeleteSelectedPages (void);

    /** Move the maked pages to a position directly after the specified page.
    */
    bool MoveSelectedPages (USHORT nTargetPage);

    DECL_LINK(TabBarHandler, TabBar*);
    DECL_LINK(WindowEventHandler, VclWindowEvent*);

    /** Update the display of all pages.  This involves a redraw and
        releasing previews and caches.
    */
    void UpdateAllPages (void);

    /** Call this method after the selection has changed (possible several
        calls to the PageSelector) to invalidate the relevant slots and send
        appropriate events.
    */
    void SelectionHasChanged (bool bMakeSelectionVisible = true);

    enum SelectionHint { SH_FIRST, SH_LAST, SH_RECENT };

    /** Try to make all currently selected page objects visible, i.e. set
        the origin so that the page objects lie inside the visible area.
        When the selection is empty then the visible area is not modified.
        @param eSelectionHint
            This is an advice on which selected page object to handle with
            the highest priority when the whole selection does not fit in to
            the visible area.
        @return
            Returns the vertical translation of the visible area.  It is 0
            when no update of the visible area was done.
    */
    sal_Int32 MakeSelectionVisible (
        SelectionHint eSelectionHint = SH_RECENT);

    /** Modify the origin of the visible area so that the given rectangle
        comes into view.  This is done with the smallest change: no
        scrolling takes place when the given rectangle already lies in the
        visible area.  Otherwise either the top or the bottom of the given
        rectangle is aligned with the top or the bottom of the visible area.
        @return
            Returns the vertical translation of the visible area.  It is 0
            when no update of the visible area was done.
    */
    sal_Int32 MakeRectangleVisible (const Rectangle& rBox);

    /** Set the zoom factor.  The given value is clipped against an upper
        bound.
        @param nZoom
            An integer percent value, i.e. nZoom/100 is the actual zoom
            factor.
        */
    void SetZoom (long int nZoom);

    /** This factory method creates a selection function.
    */
    virtual FunctionReference CreateSelectionFunction (SfxRequest& rRequest);

    /** Add a listener that is called when the selection of the slide sorter
        changes.
        @param rListener
            When this method is called multiple times for the same listener
            the second and all following calls are ignored.  Each listener
            is added only once.
    */
    void AddSelectionChangeListener (const Link& rListener);

    /** Remove a listener that was called when the selection of the slide
        sorter changes.
        @param rListener
            It is save to pass a listener that was not added are has been
            removed previously.  Such calls are ignored.
    */
    void RemoveSelectionChangeListener (const Link& rListener);

    /** Prepare for a change of the edit mode.  Depending on the current
        edit mode we may save the selection so that it can be restored when
        later changing back to the current edit mode.
    */
    void PrepareEditModeChange (void);

    /** Set a new edit mode and return whether the edit mode really
        has been changed.  For proper saving and restoring of the selection
        this method should be called between calls to
        PrepareEditModeChange() and FinishEditModeChange().
        @return
            A return value of <TRUE/> indicates that the edit mode has
            changed.
    */
    bool ChangeEditMode (EditMode eEditMode);

    /** Finish the change of the edit mode.  Here we may select a page or
        restore a previously saved selection.
    */
    void FinishEditModeChange (void);

private:
    SlideSorterViewShell& mrViewShell;
    model::SlideSorterModel& mrModel;
    view::SlideSorterView& mrView;
    ::std::auto_ptr<PageSelector> mpPageSelector;
    ::std::auto_ptr<FocusManager> mpFocusManager;
    ::std::auto_ptr<SlotManager> mpSlotManager;
    ::std::auto_ptr<controller::Clipboard> mpClipboard;
    ::std::auto_ptr<ScrollBarManager> mpScrollBarManager;

    // The listener listens to UNO events and thus is a UNO object.
    // For proper life time management and at the same time free access to
    // the implementation object we use the ImplementationReference class.
    ::comphelper::ImplementationReference
        <controller::Listener,
        ::com::sun::star::uno::XInterface,
         ::com::sun::star::uno::XWeak>
        mpListener;

    int mnModelChangeLockCount;

    /** In this flag we remember whether a call to PreModelChange() has been
        made and one to PostModelChange() is pending.
    */
    bool mbPostModelChangePending;

    ::std::vector<Link> maSelectionChangeListeners;

    /** This array stores the indices of the  selected page descriptors at
        the time when the edit mode is switched to EM_MASTERPAGE.  With this
        we can restore the selection when switching back to EM_PAGE mode.
    */
    ::std::vector<SdPage*> maSelectionBeforeSwitch;
    /// The current page before the edit mode is switched to EM_MASTERPAGE.
    int mnCurrentPageBeforeSwitch;

    /** The master page to select after the edit mode is changed.  This
        member is used to pass the pointer from PrepareEditModeChange() to
        FinishEditModeChange().
    */
    SdPage* mpEditModeChangeMasterPage;

    /** This rectangle in the parent window encloses scroll bars and slide
        sorter window.  It is set when Resize() is called.
    */
    Rectangle maTotalWindowArea;

    /** When this flag is set then on the next call to Paint() the selection
        is moved into the visible area.
    */
    bool mbIsMakeSelectionVisiblePending;

    /** This counter is used to avoid processing of reentrant calls to
        Paint().
    */
    sal_Int32 mnPaintEntranceCount;

    /** Delete the given list of normal pages.  This method is a helper
        function for DeleteSelectedPages().
        @param rSelectedNormalPages
            A list of normal pages.  Supplying master pages is an error.
    */
    void DeleteSelectedNormalPages (const ::std::vector<SdPage*>& rSelectedNormalPages);

    /** Delete the given list of master pages.  This method is a helper
        function for DeleteSelectedPages().
        @param rSelectedMasterPages
            A list of master pages.  Supplying normal pages is an error.
    */
    void DeleteSelectedMasterPages (const ::std::vector<SdPage*>& rSelectedMasterPages);
};

} } } // end of namespace ::sd::slidesorter::controller

#endif
<|endoftext|>


<commit_before>/*
 * _DNNodometryTrain.cpp
 *
 *  Created on: May 17, 2017
 *      Author: yankai
 */

#include "_DNNGen_odometry.h"

namespace kai
{

_DNNGen_odometry::_DNNGen_odometry()
{
	m_pZED = NULL;
	m_nGen = 0;
	m_iGen = 0;
	m_dMinTot = 0;
	m_outDir = "";
	m_fNamePrefix = "";
	m_fNameList = "dnnOdomGen.txt";
	m_width = 398;
	m_height = 224;
	m_interval = 0;

	m_zedMinConfidence = 0;
	m_bCount = false;

	m_pPrev = NULL;
	m_pNext = NULL;
	m_pDepthPrev = NULL;
	m_pDepthNext = NULL;
	m_bResize = false;
	m_bCrop = false;
}

_DNNGen_odometry::~_DNNGen_odometry()
{
}

bool _DNNGen_odometry::init(void* pKiss)
{
	IF_F(!_ThreadBase::init(pKiss));
	Kiss* pK = (Kiss*) pKiss;
	pK->m_pInst = this;

	KISSm(pK,outDir);
	KISSm(pK,nGen);
	KISSm(pK,zedMinConfidence);
	KISSm(pK,dMinTot);
	KISSm(pK,fNamePrefix);
	KISSm(pK,fNameList);
	KISSm(pK,interval);

	KISSm(pK,bResize);
	KISSm(pK,width);
	KISSm(pK,height);

	KISSm(pK,bCrop);
	if (m_bCrop != 0)
	{
		F_ERROR_F(pK->v("cropX", &m_cropBB.x));
		F_ERROR_F(pK->v("cropY", &m_cropBB.y));
		F_ERROR_F(pK->v("cropW", &m_cropBB.width));
		F_ERROR_F(pK->v("cropH", &m_cropBB.height));
	}

	time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char strTime[128];
    strftime(strTime, sizeof(strTime), "_%F_%H-%M-%S", tm);

	string outFile = m_outDir + m_fNameList + strTime + ".odom";
	m_ofs.open(outFile.c_str(), ios::out | ios::app);

	m_pPrev = new Frame();
	m_pNext = new Frame();
	m_pDepthPrev = new Frame();
	m_pDepthNext = new Frame();

	return true;
}

bool _DNNGen_odometry::link(void)
{
	IF_F(!this->_ThreadBase::link());
	Kiss* pK = (Kiss*) m_pKiss;

	string iName;

	iName = "";
	F_ERROR_F(pK->v("_ZED", &iName));
	m_pZED = (_ZED*) (pK->root()->getChildInstByName(&iName));

	return true;
}

bool _DNNGen_odometry::start(void)
{
	m_bThreadON = true;
	int retCode = pthread_create(&m_threadID, 0, getUpdateThread, this);
	if (retCode != 0)
	{
		m_bThreadON = false;
		return false;
	}

	return true;
}

void _DNNGen_odometry::update(void)
{
	while (m_bThreadON)
	{
		this->autoFPSfrom();

		if(m_nGen > 0)
		{
			if(m_iGen >= m_nGen)
			{
				m_ofs.close();
				exit(0);
			}
		}

		sample();

		this->autoFPSto();
	}
}

void _DNNGen_odometry::sample(void)
{
	vDouble3 vT,vR,mT,mR;
	uint64_t dT;
	Mat dM1, dM2, tM;

	NULL_(m_pZED);
	IF_(!m_pZED->isOpened());

	int zedConfidence = m_pZED->getMotionDelta(&mT, &mR, &dT);

	if(zedConfidence < m_zedMinConfidence)
	{
		//zed tracking lost, reset
		m_bCount = false;
		return;
	}

	if(!m_bCount)
	{
		m_pPrev->update(m_pZED->bgr());
		m_pDepthPrev->update(m_pZED->depthNorm());
		m_bCount = true;
		return;
	}

	m_pNext->update(m_pZED->bgr());
	m_pDepthNext->update(m_pZED->depthNorm());

	Mat* pM1 = m_pPrev->getCMat();
	Mat* pM2 = m_pNext->getCMat();
	Mat* pD1 = m_pDepthPrev->getCMat();
	Mat* pD2 = m_pDepthNext->getCMat();

	m_bCount = false;

	//validate
	IF_(pM1->empty());
	IF_(pM1->empty());
	IF_(pD1->empty());
	IF_(pD2->empty());

	IF_(pM1->rows != pM2->rows);
	IF_(pM1->cols != pM2->cols);

    vT.x = mT.z;	//forward
    vT.y = mT.x;	//right
    vT.z = mT.y;	//down
    vR.x = mR.z;	//roll
    vR.y = mR.x;	//pitch
    vR.z = mR.y;	//yaw

    double dTot = abs(vT.x) + abs(vT.y) + abs(vT.z) + abs(vR.x) + abs(vR.y) + abs(vR.z);
    IF_(dTot < m_dMinTot);

    //reverse to make nearer pixel opaque and far pixel transparent
    *pD1 = 255 - *pD1;
    *pD2 = 255 - *pD2;

    Mat Mchan[3];
    vector<Mat> pChannels;

    cv::split(*pM1,Mchan);
	pChannels.push_back(Mchan[0]);
	pChannels.push_back(Mchan[1]);
	pChannels.push_back(Mchan[2]);
	pChannels.push_back(*pD1);
	merge(pChannels, dM1);

	pChannels.clear();
    cv::split(*pM2,Mchan);
	pChannels.push_back(Mchan[0]);
	pChannels.push_back(Mchan[1]);
	pChannels.push_back(Mchan[2]);
	pChannels.push_back(*pD2);
	merge(pChannels, dM2);

	//resize
	if(m_bResize)
	{
		cv::resize(dM1, tM, Size(m_width,m_height), 0, 0, INTER_LINEAR);
		dM1 = tM;
		cv::resize(dM2, tM, Size(m_width,m_height), 0, 0, INTER_LINEAR);
		dM2 = tM;
	}

    //crop
	if(m_bCrop)
	{
		tM = Mat(dM1, m_cropBB);
		dM1 = tM;
		tM = Mat(dM2, m_cropBB);
		dM2 = tM;
	}

	//save into list and file
	time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char strTime[128];
    strftime(strTime, sizeof(strTime), "_%F_%H-%M-%S_", tm);
    string fName = m_fNamePrefix + strTime + li2str(get_time_usec());
	m_ofs << fName << "\t" << vT.x << "\t" << vT.y << "\t" << vT.z
			 	   << "\t" << vR.x << "\t" << vR.y << "\t" << vR.z
				   << "\t" << zedConfidence << "\t" << dT
				   << "\t" << m_pZED->m_depthNormInt.x << "\t" << m_pZED->m_depthNormInt.y << endl;

	imwrite(m_outDir + fName + "_a.png", dM1);
	imwrite(m_outDir + fName + "_b.png", dM2);

	m_iGen++;
	LOG_I("Generated: "<< m_iGen);

	if(m_interval>0)
	{
		::sleep(m_interval);
	}

}

bool _DNNGen_odometry::draw(void)
{
	IF_F(!this->_ThreadBase::draw());
	Mat* pMat = ((Window*) this->m_pWindow)->getFrame()->getCMat();
	IF_F(pMat->empty());

	return true;
}

}
<commit_msg>Added dummy data for AP attitude in DNNodomGen<commit_after>/*
 * _DNNodometryTrain.cpp
 *
 *  Created on: May 17, 2017
 *      Author: yankai
 */

#include "_DNNGen_odometry.h"

namespace kai
{

_DNNGen_odometry::_DNNGen_odometry()
{
	m_pZED = NULL;
	m_nGen = 0;
	m_iGen = 0;
	m_dMinTot = 0;
	m_outDir = "";
	m_fNamePrefix = "";
	m_fNameList = "dnnOdomGen.txt";
	m_width = 398;
	m_height = 224;
	m_interval = 0;

	m_zedMinConfidence = 0;
	m_bCount = false;

	m_pPrev = NULL;
	m_pNext = NULL;
	m_pDepthPrev = NULL;
	m_pDepthNext = NULL;
	m_bResize = false;
	m_bCrop = false;
}

_DNNGen_odometry::~_DNNGen_odometry()
{
}

bool _DNNGen_odometry::init(void* pKiss)
{
	IF_F(!_ThreadBase::init(pKiss));
	Kiss* pK = (Kiss*) pKiss;
	pK->m_pInst = this;

	KISSm(pK,outDir);
	KISSm(pK,nGen);
	KISSm(pK,zedMinConfidence);
	KISSm(pK,dMinTot);
	KISSm(pK,fNamePrefix);
	KISSm(pK,fNameList);
	KISSm(pK,interval);

	KISSm(pK,bResize);
	KISSm(pK,width);
	KISSm(pK,height);

	KISSm(pK,bCrop);
	if (m_bCrop != 0)
	{
		F_ERROR_F(pK->v("cropX", &m_cropBB.x));
		F_ERROR_F(pK->v("cropY", &m_cropBB.y));
		F_ERROR_F(pK->v("cropW", &m_cropBB.width));
		F_ERROR_F(pK->v("cropH", &m_cropBB.height));
	}

	time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char strTime[128];
    strftime(strTime, sizeof(strTime), "_%F_%H-%M-%S", tm);

	string outFile = m_outDir + m_fNameList + strTime + ".odom";
	m_ofs.open(outFile.c_str(), ios::out | ios::app);

	m_pPrev = new Frame();
	m_pNext = new Frame();
	m_pDepthPrev = new Frame();
	m_pDepthNext = new Frame();

	return true;
}

bool _DNNGen_odometry::link(void)
{
	IF_F(!this->_ThreadBase::link());
	Kiss* pK = (Kiss*) m_pKiss;

	string iName;

	iName = "";
	F_ERROR_F(pK->v("_ZED", &iName));
	m_pZED = (_ZED*) (pK->root()->getChildInstByName(&iName));

	return true;
}

bool _DNNGen_odometry::start(void)
{
	m_bThreadON = true;
	int retCode = pthread_create(&m_threadID, 0, getUpdateThread, this);
	if (retCode != 0)
	{
		m_bThreadON = false;
		return false;
	}

	return true;
}

void _DNNGen_odometry::update(void)
{
	while (m_bThreadON)
	{
		this->autoFPSfrom();

		if(m_nGen > 0)
		{
			if(m_iGen >= m_nGen)
			{
				m_ofs.close();
				exit(0);
			}
		}

		sample();

		this->autoFPSto();
	}
}

void _DNNGen_odometry::sample(void)
{
	vDouble3 vT,vR,mT,mR;
	uint64_t dT;
	Mat dM1, dM2, tM;

	NULL_(m_pZED);
	IF_(!m_pZED->isOpened());

	int zedConfidence = m_pZED->getMotionDelta(&mT, &mR, &dT);

	if(zedConfidence < m_zedMinConfidence)
	{
		//zed tracking lost, reset
		m_bCount = false;
		return;
	}

	if(!m_bCount)
	{
		m_pPrev->update(m_pZED->bgr());
		m_pDepthPrev->update(m_pZED->depthNorm());
		m_bCount = true;
		return;
	}

	m_pNext->update(m_pZED->bgr());
	m_pDepthNext->update(m_pZED->depthNorm());

	Mat* pM1 = m_pPrev->getCMat();
	Mat* pM2 = m_pNext->getCMat();
	Mat* pD1 = m_pDepthPrev->getCMat();
	Mat* pD2 = m_pDepthNext->getCMat();

	m_bCount = false;

	//validate
	IF_(pM1->empty());
	IF_(pM1->empty());
	IF_(pD1->empty());
	IF_(pD2->empty());

	IF_(pM1->rows != pM2->rows);
	IF_(pM1->cols != pM2->cols);

    vT.x = mT.z;	//forward
    vT.y = mT.x;	//right
    vT.z = mT.y;	//down
    vR.x = mR.z;	//roll
    vR.y = mR.x;	//pitch
    vR.z = mR.y;	//yaw

    double dTot = abs(vT.x) + abs(vT.y) + abs(vT.z) + abs(vR.x) + abs(vR.y) + abs(vR.z);
    IF_(dTot < m_dMinTot);

    //reverse to make nearer pixel opaque and far pixel transparent
    *pD1 = 255 - *pD1;
    *pD2 = 255 - *pD2;

    Mat Mchan[3];
    vector<Mat> pChannels;

    cv::split(*pM1,Mchan);
	pChannels.push_back(Mchan[0]);
	pChannels.push_back(Mchan[1]);
	pChannels.push_back(Mchan[2]);
	pChannels.push_back(*pD1);
	merge(pChannels, dM1);

	pChannels.clear();
    cv::split(*pM2,Mchan);
	pChannels.push_back(Mchan[0]);
	pChannels.push_back(Mchan[1]);
	pChannels.push_back(Mchan[2]);
	pChannels.push_back(*pD2);
	merge(pChannels, dM2);

	//resize
	if(m_bResize)
	{
		cv::resize(dM1, tM, Size(m_width,m_height), 0, 0, INTER_LINEAR);
		dM1 = tM;
		cv::resize(dM2, tM, Size(m_width,m_height), 0, 0, INTER_LINEAR);
		dM2 = tM;
	}

    //crop
	if(m_bCrop)
	{
		tM = Mat(dM1, m_cropBB);
		dM1 = tM;
		tM = Mat(dM2, m_cropBB);
		dM2 = tM;
	}

	//save into list and file
	time_t t = time(NULL);
    struct tm *tm = localtime(&t);
    char strTime[128];
    strftime(strTime, sizeof(strTime), "_%F_%H-%M-%S_", tm);
    string fName = m_fNamePrefix + strTime + li2str(get_time_usec());
	m_ofs << fName << "\t" << vT.x << "\t" << vT.y << "\t" << vT.z
			 	   << "\t" << vR.x << "\t" << vR.y << "\t" << vR.z
				   << "\t" << zedConfidence << "\t" << dT
				   << "\t" << m_pZED->m_depthNormInt.x << "\t" << m_pZED->m_depthNormInt.y
				   << "\t" << 1000000 << "\t" << 1000000 << "\t" << 1000000	//rel atti from AP
				   << "\t" << 1000000 << "\t" << 1000000 << "\t" << 1000000	//abs atti from AP
				   << "\t" << 1000000						//height from AP
				   << endl;

	imwrite(m_outDir + fName + "_a.png", dM1);
	imwrite(m_outDir + fName + "_b.png", dM2);

	m_iGen++;
	LOG_I("Generated: "<< m_iGen);

	if(m_interval>0)
	{
		::sleep(m_interval);
	}

}

bool _DNNGen_odometry::draw(void)
{
	IF_F(!this->_ThreadBase::draw());
	Mat* pMat = ((Window*) this->m_pWindow)->getFrame()->getCMat();
	IF_F(pMat->empty());

	return true;
}

}
<|endoftext|>


<commit_before>// Copyright 2010-2013 Google
// 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.
#include <cstdio>
#include "flatzinc2/parser.h"
#include "flatzinc2/parser.tab.hh"

// Declare external functions in the flatzinc.tab.cc generated file.
extern int orfz_parse(operations_research::FzParserContext* parser,
                      operations_research::FzModel* model, bool* ok,
                      void* scanner);
extern int orfz_lex_init(void** scanner);
extern int orfz_lex_destroy(void* scanner);
extern void orfz_set_in(FILE* in_str, void* yyscanner);
// Declare external functions and structures in the flatzinc.yy.cc
// generated file.
struct yy_buffer_state;
extern yy_buffer_state* orfz__scan_bytes(const char* input, size_t size,
                                         void* scanner);
extern void orfz__delete_buffer(yy_buffer_state* b, void* scanner);

namespace operations_research {
// ----- public parsing API -----

bool ParseFlatzincFile(const std::string& filename, FzModel* const model) {
  // Init.
  FILE* const input = fopen(filename.c_str(), "r");
  if (input == nullptr) {
    LOG(INFO) << "Could not open file " << filename;
    return false;
  }
  FzParserContext context;
  bool ok = true;
  void* scanner = nullptr;
  orfz_lex_init(&scanner);
  orfz_set_in(input, scanner);
  // Parse.
  orfz_parse(&context, model, &ok, scanner);
  // Clean up.
  if (scanner != nullptr) {
    orfz_lex_destroy(scanner);
  }
  fclose(input);
  return ok;
}

bool ParseFlatzincString(const std::string& input, FzModel* const model) {
  // Init.
  FzParserContext context;
  bool ok = true;
  void* scanner = nullptr;
  orfz_lex_init(&scanner);
  yy_buffer_state* const string_buffer =
      orfz__scan_bytes(input.data(), input.size(), scanner);
  // Parse.
  orfz_parse(&context, model, &ok, scanner);
  // Clean up.
  if (string_buffer != nullptr) {
    orfz__delete_buffer(string_buffer, scanner);
  }
  if (scanner != nullptr) {
    orfz_lex_destroy(scanner);
  }
  return ok;
}
}  // namespace operations_research
<commit_msg>print parse time<commit_after>// Copyright 2010-2013 Google
// 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.
#include <cstdio>
#include "base/file.h"
#include "base/timer.h"
#include "flatzinc2/parser.h"
#include "flatzinc2/parser.tab.hh"

// Declare external functions in the flatzinc.tab.cc generated file.
extern int orfz_parse(operations_research::FzParserContext* parser,
                      operations_research::FzModel* model, bool* ok,
                      void* scanner);
extern int orfz_lex_init(void** scanner);
extern int orfz_lex_destroy(void* scanner);
extern void orfz_set_in(FILE* in_str, void* yyscanner);
// Declare external functions and structures in the flatzinc.yy.cc
// generated file.
struct yy_buffer_state;
extern yy_buffer_state* orfz__scan_bytes(const char* input, size_t size,
                                         void* scanner);
extern void orfz__delete_buffer(yy_buffer_state* b, void* scanner);

DECLARE_bool(fz_verbose);

namespace operations_research {
// ----- public parsing API -----

bool ParseFlatzincFile(const std::string& filename, FzModel* const model) {
  // Init.
  FILE* const input = fopen(filename.c_str(), "r");
  if (input == nullptr) {
    LOG(INFO) << "Could not open file " << filename;
    return false;
  }
  WallTimer timer;
  timer.Start();
  FzParserContext context;
  bool ok = true;
  void* scanner = nullptr;
  orfz_lex_init(&scanner);
  orfz_set_in(input, scanner);
  // Parse.
  orfz_parse(&context, model, &ok, scanner);
  // Clean up.
  if (scanner != nullptr) {
    orfz_lex_destroy(scanner);
  }
  fclose(input);
  FZVLOG << "Model " << filename << " parsed in " << timer.GetInMs() << " ms"
         << FZENDL;
  return ok;
}

bool ParseFlatzincString(const std::string& input, FzModel* const model) {
  // Init.
  FzParserContext context;
  bool ok = true;
  void* scanner = nullptr;
  orfz_lex_init(&scanner);
  yy_buffer_state* const string_buffer =
      orfz__scan_bytes(input.data(), input.size(), scanner);
  // Parse.
  orfz_parse(&context, model, &ok, scanner);
  // Clean up.
  if (string_buffer != nullptr) {
    orfz__delete_buffer(string_buffer, scanner);
  }
  if (scanner != nullptr) {
    orfz_lex_destroy(scanner);
  }
  return ok;
}
}  // namespace operations_research
<|endoftext|>