<commit_before>// This file is part of the dune-gdt project:
//   https://github.com/dune-community/dune-gdt
// Copyright 2010-2017 dune-gdt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//      or  GPL-2.0+ (http://opensource.org/licenses/gpl-license)
//          with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
//   Felix Schindler (2015 - 2017)
//   Rene Milk       (2016 - 2017)
//   Tobias Leibner  (2016)

#ifndef DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH
#define DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH

#if HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
#endif
#include <dune/grid/yaspgrid.hh>

#include <dune/xt/functions/constant.hh>
#include <dune/xt/functions/ESV2007.hh>
#include <dune/xt/grid/boundaryinfo.hh>
#include <dune/xt/grid/gridprovider/cube.hh>

#include <dune/gdt/test/stationary-testcase.hh>
#include <dune/gdt/test/grids.hh>

#include "base.hh"

namespace Dune {
namespace GDT {
namespace LinearElliptic {

// forward
template <class G, class R = double, int r = 1>
class ESV2007DdSubdomainsTestCase;

template <class E, class D, int d, class R, int r = 1>
class ESV2007Problem : public ProblemBase<E, D, d, R, r>
{
  static_assert(AlwaysFalse<E>::value, "Not available for these dimensions!");
};

template <class EntityImp, class DomainFieldImp, class RangeFieldImp>
class ESV2007Problem<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1>
    : public ProblemBase<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1>
{
  typedef ProblemBase<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> BaseType;
  typedef XT::Functions::ConstantFunction<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> ScalarConstantFunctionType;
  typedef XT::Functions::ConstantFunction<EntityImp, DomainFieldImp, 2, RangeFieldImp, 2, 2> MatrixConstantFunctionType;
  typedef XT::Functions::ESV2007::Testcase1Force<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> ForceType;

public:
  static const size_t default_integration_order = 2;

  static XT::Common::Configuration default_grid_cfg()
  {
    XT::Common::Configuration cfg;
    cfg["type"] = XT::Grid::cube_gridprovider_default_config()["type"];
    cfg["lower_left"] = "[-1 -1]";
    cfg["upper_right"] = "[1 1]";
    return cfg;
  }

  static XT::Common::Configuration default_boundary_info_cfg()
  {
    return XT::Grid::alldirichlet_boundaryinfo_default_config();
  }

  ESV2007Problem(const size_t integration_order = default_integration_order,
                 const XT::Common::Configuration& grd_cfg = default_grid_cfg(),
                 const XT::Common::Configuration& bnd_cfg = default_boundary_info_cfg())
    : BaseType(
          new ScalarConstantFunctionType(1, "diffusion_factor"),
          new MatrixConstantFunctionType(XT::Functions::internal::unit_matrix<RangeFieldImp, 2>(), "diffusion_tensor"),
          new ForceType(integration_order, "force"),
          new ScalarConstantFunctionType(0, "dirichlet"),
          new ScalarConstantFunctionType(0, "neumann"),
          grd_cfg,
          bnd_cfg)
  {
  }
}; // class ESV2007Problem< ..., 1 >

template <class G, class R = double, int r = 1>
class ESV2007TestCase
    : public Test::StationaryTestCase<G,
                                      LinearElliptic::ESV2007Problem<typename G::template Codim<0>::Entity,
                                                                     typename G::ctype,
                                                                     G::dimension,
                                                                     R,
                                                                     r>>
{
  typedef typename G::template Codim<0>::Entity E;
  typedef typename G::ctype D;
  static const size_t d = G::dimension;
  typedef XT::Functions::ESV2007::Testcase1ExactSolution<E, D, d, R, r> ExactSolutionType;

public:
  typedef LinearElliptic::ESV2007Problem<E, D, d, R, r> ProblemType;

private:
  typedef Test::StationaryTestCase<G, ProblemType> BaseType;

#if DXT_DISABLE_LARGE_TESTS

  template <class T, bool anything = true>
  struct Helper
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[4 4]";
      return cfg;
    }
  };

#else // DXT_DISABLE_LARGE_TESTS

  template <class T, bool anything = true>
  struct Helper
  {
    static_assert(AlwaysFalse<T>::value, "Please add a configuration for this grid type!");
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<Yasp2Grid, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      return cfg;
    }
  };

#if HAVE_DUNE_ALUGRID

  template <bool anything>
  struct Helper<AluConform2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[4 4]";
      cfg["num_refinements"] = "2";
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<AluCube2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      cfg["num_refinements"] = "1";
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<AluSimplex2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      return cfg;
    }
  };

#endif // HAVE_DUNE_ALUGRID
#endif // DXT_DISABLE_LARGE_TESTS

  static XT::Common::Configuration grid_cfg()
  {
    auto cfg = ProblemType::default_grid_cfg();
    cfg = Helper<typename std::decay<G>::type>::value(cfg);
    return cfg;
  }

public:
  ESV2007TestCase(const size_t num_refs =
#if DXT_DISABLE_LARGE_TESTS
                      1
#else
                      3
#endif
                  )
    : BaseType(grid_cfg(), num_refs)
    , problem_()
    , exact_solution_()
  {
  }

  const ProblemType& problem() const override final
  {
    return problem_;
  }

  void print_header(std::ostream& out = std::cout) const override final
  {
    out << "+==================================================================+\n"
        << "|+================================================================+|\n"
        << "||  Testcase ESV2007: smooth data, homogeneous dirichlet          ||\n"
        << "||  (see testcase 1, page 23 in Ern, Stephansen, Vohralik, 2007)  ||\n"
        << "|+----------------------------------------------------------------+|\n"
        << "||  domain = [-1, 1] x [-1, 1]                                    ||\n"
        << "||  diffusion = 1                                                 ||\n"
        << "||  force     = 1/2 pi^2 cos(1/2 pi x) cos(1/2 pi y)              ||\n"
        << "||  dirichlet = 0                                                 ||\n"
        << "||  exact solution = cos(1/2 pi x) cos(1/2 pi y)                  ||\n"
        << "|+================================================================+|\n"
        << "+==================================================================+" << std::endl;
  }

  bool provides_exact_solution() const override final
  {
    return true;
  }

  const ExactSolutionType& exact_solution() const override final
  {
    return exact_solution_;
  }

private:
  template <class G_, class R_, int r_>
  friend class ESV2007DdSubdomainsTestCase;

  const ProblemType problem_;
  const ExactSolutionType exact_solution_;
}; // class ESV2007TestCase

template <class G, class R, int r>
class ESV2007DdSubdomainsTestCase
    : public Test::StationaryTestCase<G,
                                      LinearElliptic::ESV2007Problem<typename G::template Codim<0>::Entity,
                                                                     typename G::ctype,
                                                                     G::dimension,
                                                                     R,
                                                                     r>,
                                      XT::Grid::DD::SubdomainGrid<G>>
{
  typedef typename G::template Codim<0>::Entity E;
  typedef typename G::ctype D;
  static const size_t d = G::dimension;
  typedef XT::Functions::ESV2007::Testcase1ExactSolution<E, D, d, R, r> ExactSolutionType;

public:
  typedef LinearElliptic::ESV2007Problem<E, D, d, R, r> ProblemType;

private:
  typedef Test::StationaryTestCase<G, ProblemType, XT::Grid::DD::SubdomainGrid<G>> BaseType;

  static XT::Common::Configuration grid_cfg()
  {
    auto cfg = ESV2007TestCase<G, R, r>::grid_cfg();
    cfg["type"] = XT::Grid::cube_dd_subdomains_gridprovider_id();
    cfg["num_partitions"] = "[1 1 1 1]";
    return cfg;
  }

public:
  ESV2007DdSubdomainsTestCase(const size_t num_refs =
#if DXT_DISABLE_LARGE_TESTS
                                  1
#else
                                  3
#endif
                              )
    : BaseType(grid_cfg(), num_refs)
    , problem_()
    , exact_solution_()
  {
  }

  const ProblemType& problem() const override final
  {
    return problem_;
  }

  void print_header(std::ostream& out = std::cout) const override final
  {
    out << "+==================================================================+\n"
        << "|+================================================================+|\n"
        << "||  Testcase ESV2007: smooth data, homogeneous dirichlet          ||\n"
        << "||    DD::SubdomainGrid variant                                   ||\n"
        << "||  (see testcase 1, page 23 in Ern, Stephansen, Vohralik, 2007)  ||\n"
        << "|+----------------------------------------------------------------+|\n"
        << "||  domain = [-1, 1] x [-1, 1]                                    ||\n"
        << "||  diffusion = 1                                                 ||\n"
        << "||  force     = 1/2 pi^2 cos(1/2 pi x) cos(1/2 pi y)              ||\n"
        << "||  dirichlet = 0                                                 ||\n"
        << "||  exact solution = cos(1/2 pi x) cos(1/2 pi y)                  ||\n"
        << "|+================================================================+|\n"
        << "+==================================================================+" << std::endl;
  }

  bool provides_exact_solution() const override final
  {
    return true;
  }

  const ExactSolutionType& exact_solution() const override final
  {
    return exact_solution_;
  }

private:
  const ProblemType problem_;
  const ExactSolutionType exact_solution_;
}; // class ESV2007DdSubdomainsTestCase

} // namespace LinearElliptic
} // namespace GDT
} // namespace Dune

#endif // DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH
<commit_msg>[test] fix grid_cfg<commit_after>// This file is part of the dune-gdt project:
//   https://github.com/dune-community/dune-gdt
// Copyright 2010-2017 dune-gdt developers and contributors. All rights reserved.
// License: Dual licensed as BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
//      or  GPL-2.0+ (http://opensource.org/licenses/gpl-license)
//          with "runtime exception" (http://www.dune-project.org/license.html)
// Authors:
//   Felix Schindler (2015 - 2017)
//   Rene Milk       (2016 - 2017)
//   Tobias Leibner  (2016)

#ifndef DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH
#define DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH

#if HAVE_DUNE_ALUGRID
#include <dune/alugrid/grid.hh>
#endif
#include <dune/grid/yaspgrid.hh>

#include <dune/xt/functions/constant.hh>
#include <dune/xt/functions/ESV2007.hh>
#include <dune/xt/grid/boundaryinfo.hh>
#include <dune/xt/grid/gridprovider/cube.hh>

#include <dune/gdt/test/stationary-testcase.hh>
#include <dune/gdt/test/grids.hh>

#include "base.hh"

namespace Dune {
namespace GDT {
namespace LinearElliptic {

// forward
template <class G, class R = double, int r = 1>
class ESV2007DdSubdomainsTestCase;

template <class E, class D, int d, class R, int r = 1>
class ESV2007Problem : public ProblemBase<E, D, d, R, r>
{
  static_assert(AlwaysFalse<E>::value, "Not available for these dimensions!");
};

template <class EntityImp, class DomainFieldImp, class RangeFieldImp>
class ESV2007Problem<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1>
    : public ProblemBase<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1>
{
  typedef ProblemBase<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> BaseType;
  typedef XT::Functions::ConstantFunction<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> ScalarConstantFunctionType;
  typedef XT::Functions::ConstantFunction<EntityImp, DomainFieldImp, 2, RangeFieldImp, 2, 2> MatrixConstantFunctionType;
  typedef XT::Functions::ESV2007::Testcase1Force<EntityImp, DomainFieldImp, 2, RangeFieldImp, 1> ForceType;

public:
  static const size_t default_integration_order = 2;

  static XT::Common::Configuration default_grid_cfg()
  {
    XT::Common::Configuration cfg;
    cfg["type"] = XT::Grid::cube_gridprovider_default_config()["type"];
    cfg["lower_left"] = "[-1 -1]";
    cfg["upper_right"] = "[1 1]";
    return cfg;
  }

  static XT::Common::Configuration default_boundary_info_cfg()
  {
    return XT::Grid::alldirichlet_boundaryinfo_default_config();
  }

  ESV2007Problem(const size_t integration_order = default_integration_order,
                 const XT::Common::Configuration& grd_cfg = default_grid_cfg(),
                 const XT::Common::Configuration& bnd_cfg = default_boundary_info_cfg())
    : BaseType(
          new ScalarConstantFunctionType(1, "diffusion_factor"),
          new MatrixConstantFunctionType(XT::Functions::internal::unit_matrix<RangeFieldImp, 2>(), "diffusion_tensor"),
          new ForceType(integration_order, "force"),
          new ScalarConstantFunctionType(0, "dirichlet"),
          new ScalarConstantFunctionType(0, "neumann"),
          grd_cfg,
          bnd_cfg)
  {
  }
}; // class ESV2007Problem< ..., 1 >

template <class G, class R = double, int r = 1>
class ESV2007TestCase
    : public Test::StationaryTestCase<G,
                                      LinearElliptic::ESV2007Problem<typename G::template Codim<0>::Entity,
                                                                     typename G::ctype,
                                                                     G::dimension,
                                                                     R,
                                                                     r>>
{
  typedef typename G::template Codim<0>::Entity E;
  typedef typename G::ctype D;
  static const size_t d = G::dimension;
  typedef XT::Functions::ESV2007::Testcase1ExactSolution<E, D, d, R, r> ExactSolutionType;

public:
  typedef LinearElliptic::ESV2007Problem<E, D, d, R, r> ProblemType;

private:
  typedef Test::StationaryTestCase<G, ProblemType> BaseType;

#if DXT_DISABLE_LARGE_TESTS

  template <class T, bool anything = true>
  struct Helper
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[4 4]";
      cfg["num_refinements"] = "0";
      return cfg;
    }
  };

#else // DXT_DISABLE_LARGE_TESTS

  template <class T, bool anything = true>
  struct Helper
  {
    static_assert(AlwaysFalse<T>::value, "Please add a configuration for this grid type!");
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<Yasp2Grid, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      cfg["num_refinements"] = "0";
      return cfg;
    }
  };

#if HAVE_DUNE_ALUGRID

  template <bool anything>
  struct Helper<AluConform2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[4 4]";
      cfg["num_refinements"] = "2";
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<AluCube2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      cfg["num_refinements"] = "1";
      return cfg;
    }
  };

  template <bool anything>
  struct Helper<AluSimplex2dGridType, anything>
  {
    static XT::Common::Configuration value(XT::Common::Configuration cfg)
    {
      cfg["num_elements"] = "[8 8]";
      cfg["num_refinements"] = "0";
      return cfg;
    }
  };

#endif // HAVE_DUNE_ALUGRID
#endif // DXT_DISABLE_LARGE_TESTS

  static XT::Common::Configuration grid_cfg()
  {
    auto cfg = ProblemType::default_grid_cfg();
    cfg = Helper<typename std::decay<G>::type>::value(cfg);
    return cfg;
  }

public:
  ESV2007TestCase(const size_t num_refs =
#if DXT_DISABLE_LARGE_TESTS
                      1
#else
                      3
#endif
                  )
    : BaseType(grid_cfg(), num_refs)
    , problem_()
    , exact_solution_()
  {
  }

  const ProblemType& problem() const override final
  {
    return problem_;
  }

  void print_header(std::ostream& out = std::cout) const override final
  {
    out << "+==================================================================+\n"
        << "|+================================================================+|\n"
        << "||  Testcase ESV2007: smooth data, homogeneous dirichlet          ||\n"
        << "||  (see testcase 1, page 23 in Ern, Stephansen, Vohralik, 2007)  ||\n"
        << "|+----------------------------------------------------------------+|\n"
        << "||  domain = [-1, 1] x [-1, 1]                                    ||\n"
        << "||  diffusion = 1                                                 ||\n"
        << "||  force     = 1/2 pi^2 cos(1/2 pi x) cos(1/2 pi y)              ||\n"
        << "||  dirichlet = 0                                                 ||\n"
        << "||  exact solution = cos(1/2 pi x) cos(1/2 pi y)                  ||\n"
        << "|+================================================================+|\n"
        << "+==================================================================+" << std::endl;
  }

  bool provides_exact_solution() const override final
  {
    return true;
  }

  const ExactSolutionType& exact_solution() const override final
  {
    return exact_solution_;
  }

private:
  template <class G_, class R_, int r_>
  friend class ESV2007DdSubdomainsTestCase;

  const ProblemType problem_;
  const ExactSolutionType exact_solution_;
}; // class ESV2007TestCase

template <class G, class R, int r>
class ESV2007DdSubdomainsTestCase
    : public Test::StationaryTestCase<G,
                                      LinearElliptic::ESV2007Problem<typename G::template Codim<0>::Entity,
                                                                     typename G::ctype,
                                                                     G::dimension,
                                                                     R,
                                                                     r>,
                                      XT::Grid::DD::SubdomainGrid<G>>
{
  typedef typename G::template Codim<0>::Entity E;
  typedef typename G::ctype D;
  static const size_t d = G::dimension;
  typedef XT::Functions::ESV2007::Testcase1ExactSolution<E, D, d, R, r> ExactSolutionType;

public:
  typedef LinearElliptic::ESV2007Problem<E, D, d, R, r> ProblemType;

private:
  typedef Test::StationaryTestCase<G, ProblemType, XT::Grid::DD::SubdomainGrid<G>> BaseType;

  static XT::Common::Configuration grid_cfg()
  {
    auto cfg = ESV2007TestCase<G, R, r>::grid_cfg();
    cfg["type"] = XT::Grid::cube_dd_subdomains_gridprovider_id();
    cfg["num_partitions"] = "[1 1 1 1]";
    return cfg;
  }

public:
  ESV2007DdSubdomainsTestCase(const size_t num_refs =
#if DXT_DISABLE_LARGE_TESTS
                                  1
#else
                                  3
#endif
                              )
    : BaseType(grid_cfg(), num_refs)
    , problem_()
    , exact_solution_()
  {
  }

  const ProblemType& problem() const override final
  {
    return problem_;
  }

  void print_header(std::ostream& out = std::cout) const override final
  {
    out << "+==================================================================+\n"
        << "|+================================================================+|\n"
        << "||  Testcase ESV2007: smooth data, homogeneous dirichlet          ||\n"
        << "||    DD::SubdomainGrid variant                                   ||\n"
        << "||  (see testcase 1, page 23 in Ern, Stephansen, Vohralik, 2007)  ||\n"
        << "|+----------------------------------------------------------------+|\n"
        << "||  domain = [-1, 1] x [-1, 1]                                    ||\n"
        << "||  diffusion = 1                                                 ||\n"
        << "||  force     = 1/2 pi^2 cos(1/2 pi x) cos(1/2 pi y)              ||\n"
        << "||  dirichlet = 0                                                 ||\n"
        << "||  exact solution = cos(1/2 pi x) cos(1/2 pi y)                  ||\n"
        << "|+================================================================+|\n"
        << "+==================================================================+" << std::endl;
  }

  bool provides_exact_solution() const override final
  {
    return true;
  }

  const ExactSolutionType& exact_solution() const override final
  {
    return exact_solution_;
  }

private:
  const ProblemType problem_;
  const ExactSolutionType exact_solution_;
}; // class ESV2007DdSubdomainsTestCase

} // namespace LinearElliptic
} // namespace GDT
} // namespace Dune

#endif // DUNE_GDT_TESTS_LINEARELLIPTIC_PROBLEMS_ESV2007_HH
<|endoftext|>


<commit_before>/***************************************************************************
 *   Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 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 Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

#include "PreCompiled.h"
#ifndef _PreComp_
# include <QRegExp>
# include <QTextCharFormat>
#endif

#include "AbaqusHighlighter.h"

using namespace FemGui;

/**
 * Constructs a syntax highlighter.
 */
AbaqusHighlighter::AbaqusHighlighter(QObject* parent)
    : SyntaxHighlighter(parent)
{
}

/** Destroys this object. */
AbaqusHighlighter::~AbaqusHighlighter()
{
}

void AbaqusHighlighter::highlightBlock(const QString &text)
{
    // Find a syntax file for the Abaqus format here
    // http://notepad-plus.sourceforge.net/commun/userDefinedLang/userDefineLang_Abaqus.xml
    //
    enum { NormalState = -1, Definition, BeforeKey, InideKey, BeforeValue, InsideValue, Number };

    int state = NormalState;
    int start = 0;

    QColor keywordColor(102,0,227); // this->colorByType(SyntaxHighlighter::Keyword)
    QColor defnameColor(0,119,255); // this->colorByType(SyntaxHighlighter::Defname)
    QColor operateColor(153,0,102); // this->colorByType(SyntaxHighlighter::Operator)
    QColor valueColor(0,0,0); // this->colorByType(SyntaxHighlighter::String)
    QColor numberColor(0,127,127); // this->colorByType(SyntaxHighlighter::Number)
    QColor commentColor = this->colorByType(SyntaxHighlighter::Comment);

    for (int i = 0; i < text.length(); ++i) {
        // highlight the supported operators
        if (text[i] == QLatin1Char(',') || text[i] == QLatin1Char('=')) {
            setFormat(i, 1, operateColor);
        }

        if (state == Definition) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat keywordFormat;
                keywordFormat.setForeground(keywordColor);
                keywordFormat.setFontWeight(QFont::Bold);
                setFormat(start, i - start, keywordFormat);

                start = i;
                state = BeforeKey;
            }
        }
        else if (state == BeforeKey) {
            if (text[i].isLetterOrNumber()) {
                start = i;
                state = InideKey;
            }
        }
        else if (state == InideKey) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat keyFormat;
                keyFormat.setForeground(defnameColor);
                setFormat(start, i - start, keyFormat);

                start = i;
                state = BeforeValue;
            }
        }
        else if (state == BeforeValue) {
            if (text[i].isLetterOrNumber()) {
                start = i;
                state = InsideValue;
            }
        }
        else if (state == InsideValue) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat valueFormat;
                valueFormat.setForeground(valueColor);
                setFormat(start, i - start, valueFormat);

                start = i;
                state = BeforeKey;
            }
        }
        // Number
        else if (state == Number) {
            if (!text[i].isNumber()) {
                QTextCharFormat numberFormat;
                numberFormat.setForeground(numberColor);
                setFormat(start, i - start, numberFormat);

                start = i;
                state = NormalState;
            }
        }
        else if (text[i].isNumber()) {
            if (state == NormalState) {
                start = i;
                state = Number;
            }
        }
        // Comment lines
        else if (text.mid(i, 2) == QLatin1String("**")) {
            QTextCharFormat commentFormat;
            commentFormat.setForeground(commentColor);
            commentFormat.setFontItalic(true);
            setFormat(i, text.length() - i, commentFormat);
            break;
        }
        // Definition
        else if (text[i] == QLatin1Char('*')) {
            start = i;
            state = Definition;
        }
    }

    if (state == Definition) {
        QTextCharFormat keywordFormat;
        keywordFormat.setForeground(keywordColor);
        keywordFormat.setFontWeight(QFont::Bold);
        setFormat(start, text.length() - start, keywordFormat);
    }
    else if (state == InideKey) {
        QTextCharFormat keyFormat;
        keyFormat.setForeground(defnameColor);
        setFormat(start, text.length() - start, keyFormat);
    }
    else if (state == InsideValue) {
        QTextCharFormat valueFormat;
        valueFormat.setForeground(valueColor);
        setFormat(start, text.length() - start, valueFormat);
    }
    else if (state == Number) {
        QTextCharFormat numberFormat;
        numberFormat.setForeground(numberColor);
        setFormat(start, text.length() - start, numberFormat);
    }
}
<commit_msg>+ fix highlighting of words with numbers<commit_after>/***************************************************************************
 *   Copyright (c) 2015 Werner Mayer <wmayer[at]users.sourceforge.net>     *
 *                                                                         *
 *   This file is part of the FreeCAD CAx development system.              *
 *                                                                         *
 *   This library is free software; you can redistribute it and/or         *
 *   modify it under the terms of the GNU Library General Public           *
 *   License as published by the Free Software Foundation; either          *
 *   version 2 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 Library General Public License for more details.                  *
 *                                                                         *
 *   You should have received a copy of the GNU Library General Public     *
 *   License along with this library; see the file COPYING.LIB. If not,    *
 *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
 *   Suite 330, Boston, MA  02111-1307, USA                                *
 *                                                                         *
 ***************************************************************************/

#include "PreCompiled.h"
#ifndef _PreComp_
# include <QRegExp>
# include <QTextCharFormat>
#endif

#include "AbaqusHighlighter.h"

using namespace FemGui;

/**
 * Constructs a syntax highlighter.
 */
AbaqusHighlighter::AbaqusHighlighter(QObject* parent)
    : SyntaxHighlighter(parent)
{
}

/** Destroys this object. */
AbaqusHighlighter::~AbaqusHighlighter()
{
}

void AbaqusHighlighter::highlightBlock(const QString &text)
{
    // Find a syntax file for the Abaqus format here
    // http://notepad-plus.sourceforge.net/commun/userDefinedLang/userDefineLang_Abaqus.xml
    //
    enum { NormalState = -1, Definition, BeforeKey, InideKey, BeforeValue, InsideValue, Text, Number };

    int state = NormalState;
    int start = 0;

    QColor keywordColor(102,0,227); // this->colorByType(SyntaxHighlighter::Keyword)
    QColor defnameColor(0,119,255); // this->colorByType(SyntaxHighlighter::Defname)
    QColor operateColor(153,0,102); // this->colorByType(SyntaxHighlighter::Operator)
    QColor valueColor(0,0,0); // this->colorByType(SyntaxHighlighter::String)
    QColor numberColor(0,127,127); // this->colorByType(SyntaxHighlighter::Number)
    QColor commentColor = this->colorByType(SyntaxHighlighter::Comment);

    for (int i = 0; i < text.length(); ++i) {
        // highlight the supported operators
        if (text[i] == QLatin1Char(',') || text[i] == QLatin1Char('=')) {
            setFormat(i, 1, operateColor);
        }

        if (state == Definition) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat keywordFormat;
                keywordFormat.setForeground(keywordColor);
                keywordFormat.setFontWeight(QFont::Bold);
                setFormat(start, i - start, keywordFormat);

                start = i;
                state = BeforeKey;
            }
        }
        else if (state == BeforeKey) {
            if (text[i].isLetterOrNumber()) {
                start = i;
                state = InideKey;
            }
        }
        else if (state == InideKey) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat keyFormat;
                keyFormat.setForeground(defnameColor);
                setFormat(start, i - start, keyFormat);

                start = i;
                state = BeforeValue;
            }
        }
        else if (state == BeforeValue) {
            if (text[i].isLetterOrNumber()) {
                start = i;
                state = InsideValue;
            }
        }
        else if (state == InsideValue) {
            if (!text[i].isLetterOrNumber() && !text[i].isSpace()) {
                QTextCharFormat valueFormat;
                valueFormat.setForeground(valueColor);
                setFormat(start, i - start, valueFormat);

                start = i;
                state = BeforeKey;
            }
        }
        // Number
        else if (state == Number) {
            if (!text[i].isNumber() && text[i] != QLatin1Char('.')) {
                QTextCharFormat numberFormat;
                numberFormat.setForeground(numberColor);
                setFormat(start, i - start, numberFormat);

                start = i;
                state = NormalState;
            }
        }
        else if (text[i].isNumber() || text[i] == QLatin1Char('-')) {
            if (state == NormalState) {
                start = i;
                state = Number;
            }
        }
        // Comment lines
        else if (text.mid(i, 2) == QLatin1String("**")) {
            QTextCharFormat commentFormat;
            commentFormat.setForeground(commentColor);
            commentFormat.setFontItalic(true);
            setFormat(i, text.length() - i, commentFormat);
            break;
        }
        // Definition
        else if (text[i] == QLatin1Char('*')) {
            start = i;
            state = Definition;
        }
        else if (text[i].isLetterOrNumber()) {
            if (state == NormalState) {
                start = i;
                state = Text;
            }
        }
        else {
            state = NormalState;
        }
    }

    if (state == Definition) {
        QTextCharFormat keywordFormat;
        keywordFormat.setForeground(keywordColor);
        keywordFormat.setFontWeight(QFont::Bold);
        setFormat(start, text.length() - start, keywordFormat);
    }
    else if (state == InideKey) {
        QTextCharFormat keyFormat;
        keyFormat.setForeground(defnameColor);
        setFormat(start, text.length() - start, keyFormat);
    }
    else if (state == InsideValue) {
        QTextCharFormat valueFormat;
        valueFormat.setForeground(valueColor);
        setFormat(start, text.length() - start, valueFormat);
    }
    else if (state == Number) {
        QTextCharFormat numberFormat;
        numberFormat.setForeground(numberColor);
        setFormat(start, text.length() - start, numberFormat);
    }
}
<|endoftext|>


<commit_before>/*
 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the <organization> nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* Un-comment to use buffer instead of std out */
// #define USE_BUFFER_OUTPUT 1
#include <cstdlib>

#include "CppUTest/TestHarness.h"
#undef malloc
#undef free
#undef calloc
#undef realloc

#define  far  // eliminate "meaningless type qualifier" warning
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#undef far

#include "CppUTest/PlatformSpecificFunctions.h"

static jmp_buf test_exit_jmp_buf[10];
static int jmp_buf_index = 0;

#if USE_BUFFER_OUTPUT
    // Buffer for crude output routine
    #define BUFFER_SIZE 4096
    static char buffer [BUFFER_SIZE]; /* "never used" warning is OK */
    static int idx = 0;
#endif

/* The TI cl2000 compiler will compile this function with C++ linkage, unless
 * we specifically tell it to use C linkage again, in the function definiton.
 */
extern "C" int PlatformSpecificSetJmp(void (*function) (void* data), void* data)
{
    if (0 == setjmp(test_exit_jmp_buf[jmp_buf_index])) {
        jmp_buf_index++;
        function(data);
        jmp_buf_index--;
        return 1;
    }
    return 0;
}

void PlatformSpecificLongJmp()
{
    jmp_buf_index--;
    longjmp(test_exit_jmp_buf[jmp_buf_index], 1);
}

void PlatformSpecificRestoreJumpBuffer()
{
    jmp_buf_index--;
}

void PlatformSpecificRunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result)
{
   printf("-p isn' implemented for c2000. Running inside the process\b");
   shell->runOneTest(plugin, *result);
}

TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment()
{
    return TestOutput::eclipse;
}

///////////// Time in millis

extern "C" {

static long TimeInMillisImplementation()
{
    /* The TI c2000 platform does not have Posix support and thus lacks struct timespec.
     * Also, clock() always returns 0 in the simulator. Hence we work with struct tm.tm_hour
     * This has two consequences:
     *   (1) We need to sum up the part in order to get an "elapsed since" time value,
     *       rather than just using tm_sec.
     *   (2) There is a possibility of overflow, since we stop at the hour
     *   (3) Resolution is 1 s, even though we return ms.
     */
    time_t t        = time((time_t*)0);
    struct tm * ptm = gmtime(&t);
    long result = (long)
        ((ptm->tm_sec + ptm->tm_min * (time_t)60 + ptm->tm_hour * (time_t)3600) * (time_t)1000);
    return result;
}

long (*GetPlatformSpecificTimeInMillis)() = TimeInMillisImplementation;

}

extern "C" {

static const char* TimeStringImplementation()
{
    time_t tm = time(NULL);
    return ctime(&tm);
}

const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;

}

extern "C" int vsnprintf(char*, size_t, const char*, va_list); // not std::vsnprintf()

int PlatformSpecificVSNprintf(char *str, size_t size, const char* format, va_list args)
{
    return vsnprintf(str, size, format, args);
}

PlatformSpecificFile PlatformSpecificFOpen(const char* filename, const char* flag)
{
   return fopen(filename, flag);
}

void PlatformSpecificFPuts(const char* str, PlatformSpecificFile file)
{
   fputs(str, (FILE*)file);
}

void PlatformSpecificFClose(PlatformSpecificFile file)
{
   fclose((FILE*)file);
}

void PlatformSpecificFlush()
{
  fflush(stdout);
}

int PlatformSpecificPutchar(int c)
{
#if USE_BUFFER_OUTPUT
    if(idx < BUFFER_SIZE) {
        buffer[idx] = (char) c;
        idx++;
        /* "buffer[idx]" instead of "c" eliminates "never used" warning */
 		return (buffer[idx]);
    }
    else {
        return EOF;
    }
#else
    return putchar(c);
#endif
}

void* PlatformSpecificMalloc(size_t size)
{
   return (void*)far_malloc((unsigned long)size);
}

void* PlatformSpecificRealloc (void* memory, size_t size)
{
    return (void*)far_realloc((long)memory, (unsigned long)size);
}

void PlatformSpecificFree(void* memory)
{
    far_free((long)memory);
}

void* PlatformSpecificMemCpy(void* s1, const void* s2, size_t size)
{
    return (void*)far_memlcpy((long)s1, (long)s2, size);
}

void* PlatformSpecificMemset(void* mem, int c, size_t size)
{
    register unsigned long i = size;
    register long p = (long) mem;
    while (i--) *__farptr_to_word(p++) = c;
    return mem;
}

double PlatformSpecificFabs(double d)
{
   return fabs(d);
}

extern "C" {

static int IsNanImplementation(double d)
{
    return 0;
}

int (*PlatformSpecificIsNan)(double d) = IsNanImplementation;

}

static PlatformSpecificMutex DummyMutexCreate(void)
{
    FAIL("PlatformSpecificMutexCreate is not implemented");
    return 0;
}

static void DummyMutexLock(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexLock is not implemented");
}

static void DummyMutexUnlock(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexUnlock is not implemented");
}

static void DummyMutexDestroy(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexDestroy is not implemented");
}

PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void) = DummyMutexCreate;
void (*PlatformSpecificMutexLock)(PlatformSpecificMutex) = DummyMutexLock;
void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex) = DummyMutexUnlock;
void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex) = DummyMutexDestroy;

<commit_msg>Function pointer based interface (CL2000)<commit_after>/*
 * Copyright (c) 2007, Michael Feathers, James Grenning and Bas Vodde
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in the
 *       documentation and/or other materials provided with the distribution.
 *     * Neither the name of the <organization> nor the
 *       names of its contributors may be used to endorse or promote products
 *       derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE EARLIER MENTIONED AUTHORS ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/* Un-comment to use buffer instead of std out */
// #define USE_BUFFER_OUTPUT 1
#include <cstdlib>

#include "CppUTest/TestHarness.h"
#undef malloc
#undef free
#undef calloc
#undef realloc

#define  far  // eliminate "meaningless type qualifier" warning
#include <time.h>
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#undef far

#include "CppUTest/PlatformSpecificFunctions.h"

static jmp_buf test_exit_jmp_buf[10];
static int jmp_buf_index = 0;

#if USE_BUFFER_OUTPUT
    // Buffer for crude output routine
    #define BUFFER_SIZE 4096
    static char buffer [BUFFER_SIZE]; /* "never used" warning is OK */
    static int idx = 0;
#endif

TestOutput::WorkingEnvironment PlatformSpecificGetWorkingEnvironment()
{
    return TestOutput::eclipse;
}

static void C2000RunTestInASeperateProcess(UtestShell* shell, TestPlugin* plugin, TestResult* result)
{
   printf("-p isn' implemented for c2000. Running inside the process\b");
   shell->runOneTest(plugin, *result);
}

void (*PlatformSpecificRunTestInASeperateProcess)(UtestShell*, TestPlugin*, TestResult*) =
    C2000RunTestInASeperateProcess;

extern "C" {

static int C2000SetJmp(void (*function) (void* data), void* data)
{
    if (0 == setjmp(test_exit_jmp_buf[jmp_buf_index])) {
        jmp_buf_index++;
        function(data);
        jmp_buf_index--;
        return 1;
    }
    return 0;
}

static void  C2000LongJmp()
{
    jmp_buf_index--;
    longjmp(test_exit_jmp_buf[jmp_buf_index], 1);
}

static void  C2000RestoreJumpBuffer()
{
    jmp_buf_index--;
}

int (*PlatformSpecificSetJmp)(void (*function) (void*), void*) = C2000SetJmp;
void (*PlatformSpecificLongJmp)(void) = C2000LongJmp;
void (*PlatformSpecificRestoreJumpBuffer)(void) = C2000RestoreJumpBuffer;

static long C2000TimeInMillis()
{
    /* The TI c2000 platform does not have Posix support and thus lacks struct timespec.
     * Also, clock() always returns 0 in the simulator. Hence we work with struct tm.tm_hour
     * This has two consequences:
     *   (1) We need to sum up the part in order to get an "elapsed since" time value,
     *       rather than just using tm_sec.
     *   (2) There is a possibility of overflow, since we stop at the hour
     *   (3) Resolution is 1 s, even though we return ms.
     */
    time_t t        = time((time_t*)0);
    struct tm * ptm = gmtime(&t);
    long result = (long)
        ((ptm->tm_sec + ptm->tm_min * (time_t)60 + ptm->tm_hour * (time_t)3600) * (time_t)1000);
    return result;
}

static const char* TimeStringImplementation()
{
    time_t tm = time(NULL);
    return ctime(&tm);
}

long (*GetPlatformSpecificTimeInMillis)() = C2000TimeInMillis;
const char* (*GetPlatformSpecificTimeString)() = TimeStringImplementation;

extern int vsnprintf(char*, size_t, const char*, va_list); // not std::vsnprintf()

extern int (*PlatformSpecificVSNprintf)(char *, size_t, const char*, va_list) = vsnprintf;

PlatformSpecificFile C2000FOpen(const char* filename, const char* flag)
{
    return fopen(filename, flag);
}

static void C2000FPuts(const char* str, PlatformSpecificFile file)
{
   fputs(str, (FILE*)file);
}

static void C2000FClose(PlatformSpecificFile file)
{
   fclose((FILE*)file);
}

PlatformSpecificFile (*PlatformSpecificFOpen)(const char* filename, const char* flag) = C2000FOpen;
void (*PlatformSpecificFPuts)(const char* str, PlatformSpecificFile file) = C2000FPuts;
void (*PlatformSpecificFClose)(PlatformSpecificFile file) = C2000FClose;

static int CL2000Putchar(int c)
{
#if USE_BUFFER_OUTPUT
    if(idx < BUFFER_SIZE) {
        buffer[idx] = (char) c;
        idx++;
        /* "buffer[idx]" instead of "c" eliminates "never used" warning */
 		return (buffer[idx]);
    }
    else {
        return EOF;
    }
#else
    return putchar(c);
#endif
}

static void CL2000Flush()
{
  fflush(stdout);
}

extern int (*PlatformSpecificPutchar)(int c) = CL2000Putchar;
extern void (*PlatformSpecificFlush)(void) = CL2000Flush;

static void* C2000Malloc(size_t size)
{
   return (void*)far_malloc((unsigned long)size);
}

static void* C2000Realloc (void* memory, size_t size)
{
    return (void*)far_realloc((long)memory, (unsigned long)size);
}

static void C2000Free(void* memory)
{
    far_free((long)memory);
}

static void* C2000MemCpy(void* s1, const void* s2, size_t size)
{
    return (void*)far_memlcpy((long)s1, (long)s2, size);
}

static void* C2000Memset(void* mem, int c, size_t size)
{
    register unsigned long i = size;
    register long p = (long) mem;
    while (i--) *__farptr_to_word(p++) = c;
    return mem;
}

void* (*PlatformSpecificMalloc)(size_t size) = C2000Malloc;
void* (*PlatformSpecificRealloc)(void* memory, size_t size) = C2000Realloc;
void (*PlatformSpecificFree)(void* memory) = C2000Free;
void* (*PlatformSpecificMemCpy)(void* s1, const void* s2, size_t size) = C2000MemCpy;
void* (*PlatformSpecificMemset)(void* mem, int c, size_t size) = C2000Memset;

/*
double PlatformSpecificFabs(double d)
{
   return fabs(d);
}
*/
double (*PlatformSpecificFabs)(double) = fabs;

static int IsNanImplementation(double d)
{
    return 0;
}

int (*PlatformSpecificIsNan)(double d) = IsNanImplementation;

static PlatformSpecificMutex DummyMutexCreate(void)
{
    FAIL("PlatformSpecificMutexCreate is not implemented");
    return 0;
}

static void DummyMutexLock(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexLock is not implemented");
}

static void DummyMutexUnlock(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexUnlock is not implemented");
}

static void DummyMutexDestroy(PlatformSpecificMutex mtx)
{
    FAIL("PlatformSpecificMutexDestroy is not implemented");
}

PlatformSpecificMutex (*PlatformSpecificMutexCreate)(void) = DummyMutexCreate;
void (*PlatformSpecificMutexLock)(PlatformSpecificMutex) = DummyMutexLock;
void (*PlatformSpecificMutexUnlock)(PlatformSpecificMutex) = DummyMutexUnlock;
void (*PlatformSpecificMutexDestroy)(PlatformSpecificMutex) = DummyMutexDestroy;

}<|endoftext|>


<commit_before>
#include <ros/ros.h>
#include <gps_cartesian_grid/FixToPoint.h>
#include <tf2_ros/transform_broadcaster.h>
#include <geometry_msgs/TransformStamped.h>
#include <GeographicLib/LocalCartesian.hpp>

class GpsCartesianGridNode
{
public:
	GpsCartesianGridNode();
private:
	geometry_msgs::Point fixToPoint(sensor_msgs::NavSatFix gps_fix);
	bool fixToPointServiceCall(gps_cartesian_grid::FixToPoint::Request &req, gps_cartesian_grid::FixToPoint::Response &point);
	void newNavSatFix(sensor_msgs::NavSatFix newFix){gps_fix_ = newFix;  publishTf();}
	void publishTf();
	ros::NodeHandle nh_, private_nh_;

	// for service
	ros::ServiceServer fixToPointService_;

	// for tf
	tf2_ros::TransformBroadcaster tf_broadcaster_;
	std::string global_frame_, robot_frame_;

	std::string gps_topic_;
	ros::Subscriber gps_sub_;
	sensor_msgs::NavSatFix gps_fix_;

	// thirdparty GeographicLib
	GeographicLib::LocalCartesian grid_;
};

GpsCartesianGridNode::GpsCartesianGridNode() : nh_(),
		private_nh_("~"),
		grid_(0,0,0) // need to init to SOMETHING since its statically allocated.  will reset later when actual values are read.
{
	// setup origin
	double lat, lon, alt;
	if(!private_nh_.getParam("origin_latitude", lat) || !private_nh_.getParam("origin_longitude", lon))
	{
		ROS_FATAL("GPS Cartesian Grid cannot function without origin.  Either latitude, longitude, or both are missing");
	}

	private_nh_.param("origin_altitude", alt, 0.0);
	private_nh_.param("global_frame", global_frame_, std::string("/world"));
	private_nh_.param("robot_frame", robot_frame_, std::string("base_link"));

	private_nh_.param("gps_fix_topic", gps_topic_, std::string("fix"));

	grid_.Reset(lat,lon,alt);

	fixToPointService_ = nh_.advertiseService("fix_to_point", &GpsCartesianGridNode::fixToPointServiceCall, this);
	gps_sub_ = nh_.subscribe(gps_topic_, 10, &GpsCartesianGridNode::newNavSatFix, this);
}

geometry_msgs::Point GpsCartesianGridNode::fixToPoint(sensor_msgs::NavSatFix gps_fix)
{
	geometry_msgs::Point point;
	grid_.Forward(gps_fix.latitude, gps_fix.longitude, gps_fix.altitude, point.x,  point.y,  point.z);
	return point;
}

bool GpsCartesianGridNode::fixToPointServiceCall(gps_cartesian_grid::FixToPoint::Request &req,
		gps_cartesian_grid::FixToPoint::Response &point)
{
	point.cartesian = fixToPoint(req.gps_fix);
	return true;
}

void GpsCartesianGridNode::publishTf()
{
	geometry_msgs::TransformStamped transformStamped;

	transformStamped.header.stamp = ros::Time::now();
	transformStamped.header.frame_id = global_frame_;
	transformStamped.child_frame_id = robot_frame_;

	geometry_msgs::Point point = fixToPoint(gps_fix_);
	transformStamped.transform.translation.x = point.x;
	transformStamped.transform.translation.y = point.y;
	transformStamped.transform.translation.z = point.z;

	/*
	tf2::Quaternion q;
	q.setRPY(0, 0, msg->theta);
	transformStamped.transform.rotation.x = q.x();
	transformStamped.transform.rotation.y = q.y();
	transformStamped.transform.rotation.z = q.z();
	transformStamped.transform.rotation.w = q.w();
	*/

	tf_broadcaster_.sendTransform(transformStamped);
}

int main(int argc, char **argv)
{
	ros::init(argc, argv, "gps_cartesian_grid_node");
	ros::spin();
	return 0;
}
<commit_msg>Added IMU subscription for perfoming the rotational part of the tf transform.  IMU callback now triggers transform broadcast, instead of GPS, because it should be far more recent.<commit_after>
#include <ros/ros.h>
#include <gps_cartesian_grid/FixToPoint.h>
#include <tf2_ros/transform_broadcaster.h>
#include <sensor_msgs/Imu.h>
#include <geometry_msgs/TransformStamped.h>
#include <GeographicLib/LocalCartesian.hpp>

class GpsCartesianGridNode
{
public:
	GpsCartesianGridNode();
private:
	geometry_msgs::Point fixToPoint(sensor_msgs::NavSatFix gps_fix);
	bool fixToPointServiceCall(gps_cartesian_grid::FixToPoint::Request &req, gps_cartesian_grid::FixToPoint::Response &point);
	void newNavSatFix(sensor_msgs::NavSatFix newFix){gps_fix_ = newFix;}
	void newImuData(sensor_msgs::Imu newImu){imu_ = newImu;  publishTf();}
	void publishTf();
	ros::NodeHandle nh_, private_nh_;

	// for service
	ros::ServiceServer fixToPointService_;

	// for tf
	tf2_ros::TransformBroadcaster tf_broadcaster_;
	std::string global_frame_, robot_frame_;

	std::string gps_topic_, imu_topic_;
	ros::Subscriber gps_sub_, imu_sub_;
	sensor_msgs::NavSatFix gps_fix_;
	sensor_msgs::Imu imu_;

	// thirdparty GeographicLib
	GeographicLib::LocalCartesian grid_;
};

GpsCartesianGridNode::GpsCartesianGridNode() : nh_(),
		private_nh_("~"),
		grid_(0,0,0) // need to init to SOMETHING since its statically allocated.  will reset later when actual values are read.
{
	// setup origin
	double lat, lon, alt;
	if(!private_nh_.getParam("origin_latitude", lat) || !private_nh_.getParam("origin_longitude", lon))
	{
		ROS_FATAL("GPS Cartesian Grid cannot function without origin.  Either latitude, longitude, or both are missing");
	}

	private_nh_.param("origin_altitude", alt, 0.0);
	private_nh_.param("global_frame", global_frame_, std::string("/world"));
	private_nh_.param("robot_frame", robot_frame_, std::string("base_link"));

	private_nh_.param("gps_fix_topic", gps_topic_, std::string("fix"));
	private_nh_.param("imu_topic", imu_topic_, std::string("imu/data"));

	grid_.Reset(lat,lon,alt);

	fixToPointService_ = nh_.advertiseService("fix_to_point", &GpsCartesianGridNode::fixToPointServiceCall, this);
	gps_sub_ = nh_.subscribe(gps_topic_, 1, &GpsCartesianGridNode::newNavSatFix, this);
	imu_sub_ = nh_.subscribe(imu_topic_, 1, &GpsCartesianGridNode::newImuData, this);
}

geometry_msgs::Point GpsCartesianGridNode::fixToPoint(sensor_msgs::NavSatFix gps_fix)
{
	geometry_msgs::Point point;
	grid_.Forward(gps_fix.latitude, gps_fix.longitude, gps_fix.altitude, point.x,  point.y,  point.z);
	return point;
}

bool GpsCartesianGridNode::fixToPointServiceCall(gps_cartesian_grid::FixToPoint::Request &req,
		gps_cartesian_grid::FixToPoint::Response &point)
{
	point.cartesian = fixToPoint(req.gps_fix);
	return true;
}

void GpsCartesianGridNode::publishTf()
{
	geometry_msgs::TransformStamped transformStamped;

	transformStamped.header.stamp = ros::Time::now();
	transformStamped.header.frame_id = global_frame_;
	transformStamped.child_frame_id = robot_frame_;

	geometry_msgs::Point point = fixToPoint(gps_fix_);
	transformStamped.transform.translation.x = point.x;
	transformStamped.transform.translation.y = point.y;
	transformStamped.transform.translation.z = point.z;

	/*
	tf2::Quaternion q;
	q.setRPY(0, 0, msg->theta);
	*/
	transformStamped.transform.rotation.x = imu_.orientation.x;
	transformStamped.transform.rotation.y = imu_.orientation.y;
	transformStamped.transform.rotation.z = imu_.orientation.z;
	transformStamped.transform.rotation.w = imu_.orientation.w;

	tf_broadcaster_.sendTransform(transformStamped);
}

int main(int argc, char **argv)
{
	ros::init(argc, argv, "gps_cartesian_grid_node");
	ros::spin();
	return 0;
}
<|endoftext|>


<commit_before><commit_msg>Fix used uninitialized warning in os_x11.cpp<commit_after><|endoftext|>


<commit_before>//
//  libavg - Media Playback Engine.
//  Copyright (C) 2003-2011 Ulrich von Zadow
//
//  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 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//

#include "Filtercolorize.h"
#include "Filtergrayscale.h"
#include "Pixel24.h"

#include "../base/Exception.h"

namespace avg {

// From Foley, van Dam p. 596 incl. addendum fixes.
unsigned char hls_value(float n1, float n2, float hue)
{
  if (hue>360)
    hue-=360;
  if (hue<0)
    hue+=360;

  float rv;
  if (hue<60)
    rv = n1+(n2-n1)*hue/60;
  else if (hue<180)
    rv = n2;
  else if (hue<240)
    rv = n1+(n2-n1)*(240-hue)/60;
  else
    rv = n1;

  return (unsigned char)(rv*255);
}

Pixel24 hls2rgb (float h, float l, float s)
{
    float m1, m2;
    l /= 255;
    s /= 100;
    // Warning: Foley, van Dam has a typo on the next line!
    m2 = (l<=0.5f)?(l*(1.0f+s)):(l+s-l*s);
    m1 = 2.0f*l-m2;
    if (s<0.001f) {
        return Pixel24((unsigned char)(l*255), (unsigned char)(l*255),
                (unsigned char)(l*255));
    } else {
        return Pixel24(hls_value(m1,m2,h+120),
                hls_value(m1,m2,h),
                hls_value(m1,m2,h-120));
    }
}

FilterColorize::FilterColorize(float hue, float saturation)
  : m_Hue(hue),
    m_Saturation(saturation)
{
}

FilterColorize::~FilterColorize()
{

}

void FilterColorize::applyInPlace(BitmapPtr pBmp)
{
    BitmapPtr pTempBmp (FilterGrayscale().apply(pBmp));
    Pixel24 colorTable[256];
    for (int i=0; i<256; i++) {
        colorTable[i] = hls2rgb(m_Hue, float(i), m_Saturation);
    }

    unsigned char * pSrcLine = pTempBmp->getPixels();
    unsigned char * pDestLine = pBmp->getPixels();
    IntPoint size = pTempBmp->getSize();
    for (int y = 0; y < size.y; ++y) {
        unsigned char * pSrcPixel = pSrcLine;
        switch (pBmp->getPixelFormat()) {
            case R8G8B8A8:
            case R8G8B8X8:
                {
                    Pixel32 * pDestPixel = (Pixel32 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case R8G8B8:
                {
                    Pixel24 * pDestPixel = (Pixel24 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case B8G8R8A8:
            case B8G8R8X8:
                {
                    Pixel32 * pDestPixel = (Pixel32 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case B8G8R8:
                {
                    Pixel24 * pDestPixel = (Pixel24 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            default:
                AVG_ASSERT(false);
        }
        pSrcLine = pSrcLine + pTempBmp->getStride();
        pDestLine = pDestLine + pBmp->getStride();
    }
}

}

<commit_msg>Possible fix for Lion testgraphics crash.<commit_after>//
//  libavg - Media Playback Engine.
//  Copyright (C) 2003-2011 Ulrich von Zadow
//
//  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 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
//  Current versions can be found at www.libavg.de
//

#include "Filtercolorize.h"
#include "Filtergrayscale.h"
#include "Pixel24.h"

#include "../base/Exception.h"

namespace avg {

// From Foley, van Dam p. 596 incl. addendum fixes.
unsigned char hls_value(float n1, float n2, float hue)
{
  if (hue>360)
    hue-=360;
  if (hue<0)
    hue+=360;

  float rv;
  if (hue<60)
    rv = n1+(n2-n1)*hue/60;
  else if (hue<180)
    rv = n2;
  else if (hue<240)
    rv = n1+(n2-n1)*(240-hue)/60;
  else
    rv = n1;

  return (unsigned char)(rv*255);
}

Pixel24 hls2rgb (float h, float l, float s)
{
    float m1, m2;
    l /= 255;
    s /= 100;
    // Warning: Foley, van Dam has a typo on the next line!
    m2 = (l<=0.5f)?(l*(1.0f+s)):(l+s-l*s);
    m1 = 2.0f*l-m2;
    if (s<0.001f) {
        return Pixel24((unsigned char)(l*255), (unsigned char)(l*255),
                (unsigned char)(l*255));
    } else {
        return Pixel24(hls_value(m1,m2,h+120),
                hls_value(m1,m2,h),
                hls_value(m1,m2,h-120));
    }
}

FilterColorize::FilterColorize(float hue, float saturation)
  : m_Hue(hue),
    m_Saturation(saturation)
{
}

FilterColorize::~FilterColorize()
{

}

void FilterColorize::applyInPlace(BitmapPtr pBmp)
{
    BitmapPtr pTempBmp (FilterGrayscale().apply(pBmp));
    Pixel32 colorTable[256];
    for (int i=0; i<256; i++) {
        colorTable[i] = hls2rgb(m_Hue, float(i), m_Saturation);
    }

    unsigned char * pSrcLine = pTempBmp->getPixels();
    unsigned char * pDestLine = pBmp->getPixels();
    IntPoint size = pTempBmp->getSize();
    for (int y = 0; y < size.y; ++y) {
        unsigned char * pSrcPixel = pSrcLine;
        switch (pBmp->getPixelFormat()) {
            case R8G8B8A8:
            case R8G8B8X8:
                {
                    Pixel32 * pDestPixel = (Pixel32 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case R8G8B8:
                {
                    Pixel24 * pDestPixel = (Pixel24 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case B8G8R8A8:
            case B8G8R8X8:
                {
                    Pixel32 * pDestPixel = (Pixel32 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            case B8G8R8:
                {
                    Pixel24 * pDestPixel = (Pixel24 *)pDestLine;
                    for (int x = 0; x < size.x; ++x) {
                        *pDestPixel = colorTable[*pSrcPixel];
                        ++pSrcPixel;
                        ++pDestPixel;
                    }
                }
                break;
            default:
                AVG_ASSERT(false);
        }
        pSrcLine = pSrcLine + pTempBmp->getStride();
        pDestLine = pDestLine + pBmp->getStride();
    }
}

}

<|endoftext|>


<commit_before>#include "bochs.h"

bx_iodebug_c bx_iodebug;

// Constructor
bx_iodebug_c::bx_iodebug_c( void )
{
  put("IODEBUG");
  settype(IODEBUGLOG);
}

// Destructor
bx_iodebug_c::~bx_iodebug_c( void )
{
}

int bx_iodebug_c::init( bx_devices_c *d )
{
  BX_IODEBUG_THIS devices = d;
  BX_IODEBUG_THIS devices->register_io_read_handler(this, read_handler, 0x8A00,"BOCHS IODEBUG");
  BX_IODEBUG_THIS devices->register_io_read_handler(this, read_handler, 0x8A01,"BOCHS IODEBUG");

  BX_IODEBUG_THIS devices->register_io_write_handler(this, write_handler, 0x8A00,"BOCHS IODEBUG");
  BX_IODEBUG_THIS devices->register_io_write_handler(this, write_handler, 0x8A01,"BOCHS IODEBUG");
  fprintf( stderr, "IODEBUG initialized\n");

  return(1);
}

Bit32u bx_iodebug_c::read_handler(void *this_ptr, Bit32u addr, unsigned io_len)
{
  bx_iodebug_c *class_ptr = (bx_iodebug_c *) this_ptr;
  return( class_ptr->read(addr, io_len) );
}

Bit32u bx_iodebug_c::read( Bit32u addr, unsigned io_len )
{
  return(0x8A00);
}

void bx_iodebug_c::write_handler(void *this_ptr, Bit32u addr, Bit32u dvalue, unsigned io_len)
{
  bx_iodebug_c *class_ptr = (bx_iodebug_c *) this_ptr;
  class_ptr->write( addr, dvalue, io_len );
}

void bx_iodebug_c::write( Bit32u addr, Bit32u dvalue, unsigned int io_len )
{
  fprintf(stderr, "IODEBUG addr: %4x\tdvalue: %8x\tio_len: %8x\n", (unsigned int)addr, (unsigned int)dvalue, io_len);
}
<commit_msg>Added range_test function, partly completed write_mem and read_mem<commit_after>#include "bochs.h"

bx_iodebug_c bx_iodebug;

// Constructor
bx_iodebug_c::bx_iodebug_c( void )
{
  put("IODEBUG");
  settype(IODEBUGLOG);
  memset(&s, 0, sizeof(s));
}

// Destructor
bx_iodebug_c::~bx_iodebug_c( void )
{
}

int bx_iodebug_c::init( bx_devices_c *d )
{
  int i;

  BX_IODEBUG_THIS devices = d;
  BX_IODEBUG_THIS devices->register_io_read_handler(this, read_handler, 0x8A00,"BOCHS IODEBUG");
  BX_IODEBUG_THIS devices->register_io_read_handler(this, read_handler, 0x8A01,"BOCHS IODEBUG");

  BX_IODEBUG_THIS devices->register_io_write_handler(this, write_handler, 0x8A00,"BOCHS IODEBUG");
  BX_IODEBUG_THIS devices->register_io_write_handler(this, write_handler, 0x8A01,"BOCHS IODEBUG");
  fprintf( stderr, "IODEBUG initialized\n");

  BX_IODEBUG_THIS s.enabled = 0;
  BX_IODEBUG_THIS s.register_select = 0;
  for(i=0;i<BX_IODEBUG_MAX_AREAS;i++) {
    BX_IODEBUG_THIS s.monitored_mem_areas_start[i] = 0;
    BX_IODEBUG_THIS s.monitored_mem_areas_end[i] = 0;
  }

  return(1);
}

Bit32u bx_iodebug_c::read_handler(void *this_ptr, Bit32u addr, unsigned io_len)
{
  bx_iodebug_c *class_ptr = (bx_iodebug_c *) this_ptr;
  return( class_ptr->read(addr, io_len) );
}

Bit32u bx_iodebug_c::read( Bit32u addr, unsigned io_len )
{

  if(BX_IODEBUG_THIS s.enabled) return(0x8A00);
  return(0);
}

void bx_iodebug_c::write_handler(void *this_ptr, Bit32u addr, Bit32u dvalue, unsigned io_len)
{
  bx_iodebug_c *class_ptr = (bx_iodebug_c *) this_ptr;
  class_ptr->write( addr, dvalue, io_len );
}

void bx_iodebug_c::write( Bit32u addr, Bit32u dvalue, unsigned int io_len )
{

  fprintf(stderr, "IODEBUG addr: %4x\tdvalue: %8x\tio_len: %8x\n", (unsigned int)addr, (unsigned int)dvalue, io_len);

  if( addr == 0x8A00 && dvalue == 0x8A00 )
  {
    if( BX_IODEBUG_THIS s.enabled )
      fprintf( stderr, "IODEBUG device already activated\n");
    else
    {
      BX_IODEBUG_THIS s.enabled=1;
      fprintf( stderr, "IODEBUG device activated\n");
    }
  }

  else if ( BX_IODEBUG_THIS s.enabled )
  {

    // Register Select port
    if( addr == 0x8A00 )
    {
      if( dvalue == 0x8AFF )
      {
        BX_IODEBUG_THIS s.enabled = 0;
	fprintf( stderr, "IODEBUG device deactivated\n");
      }
      fprintf( stderr, "IODEBUG register selected: %8x\n", dvalue);
      BX_IODEBUG_THIS s.register_select = dvalue;
    }

    // Data port
    else
    {
      fprintf( stderr, "IODEBUG value written to register %2x: %8x\n", BX_IODEBUG_THIS s.register_select, dvalue);
    }
  }
}

void bx_iodebug_c::mem_write( BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
{
  Bit32u data32;
  Bit16u data16;
  Bit8u  data8;

  int area;
  if( !BX_IODEBUG_THIS s.enabled ) return;

  // Device is enabled, testing address ranges
  if( area = BX_IODEBUG_THIS range_test( addr, len ) )
  {
    area--;
    fprintf( stderr,
             "IODEBUG write to monitored memory area %i\n\trange start: %8x\trange end: %8x\n\taddress accessed: %8x\tdata written: ",
	     area,
	     BX_IODEBUG_THIS s.monitored_mem_areas_start[area],
	     BX_IODEBUG_THIS s.monitored_mem_areas_end[area],
	     (unsigned int)addr);
    data32 = * (Bit32u *)data;
    data16 = (Bit16u)data32;
    data8  = (Bit8u)data32;

    switch(len)
    {
      case(1):
        fprintf(stderr,"%2x\n", (unsigned int)data8);
	break;

      case(2):
        fprintf(stderr,"%4x\n", (unsigned int)data16);
	break;

      case(4):
        fprintf(stderr,"%8x\n", (unsigned int)data32);
	break;

      default:
        fprintf(stderr, "unsupported write size\n");
    }
  }
}

void bx_iodebug_c::mem_read( BX_CPU_C *cpu, Bit32u addr, unsigned len, void *data)
{
  if( !BX_IODEBUG_THIS s.enabled ) return;

  // Device is enabled, testing address range
}

unsigned int bx_iodebug_c::range_test( Bit32u addr, unsigned int len )
{
  int i;
  for(i=0;i<BX_IODEBUG_MAX_AREAS;i++)
  {
    if( BX_IODEBUG_THIS s.monitored_mem_areas_start[i] ||
        BX_IODEBUG_THIS s.monitored_mem_areas_end[i] )
    {
      if( (addr+len-1) < BX_IODEBUG_THIS s.monitored_mem_areas_start[i] )
        continue;
      if( addr > BX_IODEBUG_THIS s.monitored_mem_areas_end[i] )
        return(++i);
    }
  }
}
<|endoftext|>


<commit_before>
#include "numerics/чебышёв_series.hpp"

#include <vector>

#include "geometry/serialization.hpp"
#include "glog/logging.h"
#include "numerics/fixed_arrays.hpp"
#include "numerics/newhall.mathematica.cpp"

namespace principia {

using geometry::DoubleOrQuantityOrMultivectorSerializer;

namespace numerics {

template<typename Vector>
ЧебышёвSeries<Vector>::ЧебышёвSeries(std::vector<Vector> const& coefficients,
                                     Instant const& t_min,
                                     Instant const& t_max)
    : coefficients_(coefficients),
      degree_(static_cast<int>(coefficients_.size()) - 1),
      t_min_(t_min),
      t_max_(t_max) {
  CHECK_LE(0, degree_) << "Degree must be at least 0";
  CHECK_LT(t_min_, t_max_) << "Time interval must not be empty";
  // Precomputed to save operations at the expense of some accuracy loss.
  Time const duration = t_max_ - t_min_;
  t_mean_ = t_min_ + 0.5 * duration;
  two_over_duration_ = 2 / duration;
}

template<typename Vector>
ЧебышёвSeries<Vector>::ЧебышёвSeries(ЧебышёвSeries&& other)
    : coefficients_(std::move(other.coefficients_)),
      degree_(std::move(other.degree_)),
      t_min_(std::move(other.t_min_)),
      t_max_(std::move(other.t_max_)),
      t_mean_(std::move(other.t_mean_)),
      two_over_duration_(std::move(other.two_over_duration_)) {}

template<typename Vector>
ЧебышёвSeries<Vector>& ЧебышёвSeries<Vector>::operator=(
    ЧебышёвSeries&& other) {
  coefficients_ = std::move(other.coefficients_);
  degree_ = other.degree_;
  t_min_ = std::move(other.t_min_);
  t_max_ = std::move(other.t_max_);
  t_mean_ = std::move(other.t_mean_);
  two_over_duration_ = std::move(other.two_over_duration_);
  return *this;
}

template<typename Vector>
bool ЧебышёвSeries<Vector>::operator==(ЧебышёвSeries const& right) const {
  return coefficients_ == right.coefficients_ &&
         t_min_ == right.t_min_ &&
         t_max_ == right.t_max_;
}

template<typename Vector>
bool ЧебышёвSeries<Vector>::operator!=(ЧебышёвSeries const& right) const {
  return !ЧебышёвSeries<Vector>::operator==(right);
}

template<typename Vector>
Instant const& ЧебышёвSeries<Vector>::t_min() const {
  return t_min_;
}

template<typename Vector>
Instant const& ЧебышёвSeries<Vector>::t_max() const {
  return t_max_;
}

template<typename Vector>
Vector const& ЧебышёвSeries<Vector>::last_coefficient() const {
  return coefficients_[degree_];
}

template<typename Vector>
Vector ЧебышёвSeries<Vector>::Evaluate(Instant const& t) const {
  double const scaled_t = (t - t_mean_) * two_over_duration_;
  double const two_scaled_t = scaled_t + scaled_t;
  // We have to allow |scaled_t| to go slightly out of [-1, 1] because of
  // computation errors.  But if it goes too far, something is broken.
  // TODO(phl): This should use DCHECK but these macros don't work because the
  // Principia projects don't define NDEBUG.
#ifdef _DEBUG
  CHECK_LE(scaled_t, 1.1);
  CHECK_GE(scaled_t, -1.1);
#endif

  Vector b_kplus2 = coefficients_[degree_];
  if (degree_ == 0) {
    return b_kplus2;
  }
  if (degree_ == 1) {
    return coefficients_[0] + scaled_t * b_kplus2;
  }
  Vector b_kplus1 = coefficients_[degree_ - 1] + two_scaled_t * b_kplus2;
  Vector b_k;
  for (int k = degree_ - 2; k >= 1; --k) {
    b_k = coefficients_[k] + two_scaled_t * b_kplus1 - b_kplus2;
    b_kplus2 = b_kplus1;
    b_kplus1 = b_k;
  }
  return coefficients_[0] + scaled_t * b_kplus1 - b_kplus2;

//#define CLENSHAW_STEP1(n) \
//  bnplus2 = coefficients_[n];
//#define CLENSHAW_STEP2(n, nplus1) \
//  bnplus1 = coefficients_[n] + two_scaled_t * bnplus2;
//#define CLENSHAW_STEP3(n, nplus1, nplus2) \
//  bn = coefficients_[n] + two_scaled_t * bnplus1 - bnplus2;  \
//  bnplus2 = bnplus1; \
//  bnplus1 = bn;
}

template<typename Vector>
Variation<Vector> ЧебышёвSeries<Vector>::EvaluateDerivative(
    Instant const& t) const {
  double const scaled_t = (t - t_mean_) * two_over_duration_;
  double const two_scaled_t = scaled_t + scaled_t;
  // We have to allow |scaled_t| to go slightly out of [-1, 1] because of
  // computation errors.  But if it goes too far, something is broken.
  // TODO(phl): See above.
#ifdef _DEBUG
  CHECK_LE(scaled_t, 1.1);
  CHECK_GE(scaled_t, -1.1);
#endif

  Vector b_kplus2_vector{};
  Vector b_kplus1_vector{};
  Vector* b_kplus2 = &b_kplus2_vector;
  Vector* b_kplus1 = &b_kplus1_vector;
  Vector* const& b_k = b_kplus2;  // An overlay.
  for (int k = degree_ - 1; k >= 1; --k) {
    *b_k = coefficients_[k + 1] * (k + 1) +
           two_scaled_t * *b_kplus1 - *b_kplus2;
    Vector* const last_b_k = b_k;
    b_kplus2 = b_kplus1;
    b_kplus1 = last_b_k;
  }
  return (coefficients_[1] + two_scaled_t * *b_kplus1 - *b_kplus2) *
             two_over_duration_;
}

template<typename Vector>
void ЧебышёвSeries<Vector>::WriteToMessage(
    not_null<serialization::ЧебышёвSeries*> const message) const {
  using Serializer = DoubleOrQuantityOrMultivectorSerializer<
                          Vector,
                          serialization::ЧебышёвSeries::Coefficient>;

  for (auto const& coefficient : coefficients_) {
    Serializer::WriteToMessage(coefficient, message->add_coefficient());
  }
  t_min_.WriteToMessage(message->mutable_t_min());
  t_max_.WriteToMessage(message->mutable_t_max());
}

template<typename Vector>
ЧебышёвSeries<Vector> ЧебышёвSeries<Vector>::ReadFromMessage(
    serialization::ЧебышёвSeries const& message) {
  using Serializer = DoubleOrQuantityOrMultivectorSerializer<
                          Vector,
                          serialization::ЧебышёвSeries::Coefficient>;

  std::vector<Vector> coefficients;
  coefficients.reserve(message.coefficient_size());
  for (auto const& coefficient : message.coefficient()) {
    coefficients.push_back(Serializer::ReadFromMessage(coefficient));
  }
  return ЧебышёвSeries(coefficients,
                       Instant::ReadFromMessage(message.t_min()),
                       Instant::ReadFromMessage(message.t_max()));
}

template<typename Vector>
ЧебышёвSeries<Vector> ЧебышёвSeries<Vector>::NewhallApproximation(
    int const degree,
    std::vector<Vector> const& q,
    std::vector<Variation<Vector>> const& v,
    Instant const& t_min,
    Instant const& t_max) {
  // Only supports 8 divisions for now.
  int const kDivisions = 8;
  CHECK_EQ(kDivisions + 1, q.size());
  CHECK_EQ(kDivisions + 1, v.size());

  Time const duration_over_two = 0.5 * (t_max - t_min);

  // Tricky.  The order in Newhall's matrices is such that the entries for the
  // largest time occur first.
  FixedVector<Vector, 2 * kDivisions + 2> qv;
  for (int i = 0, j = 2 * kDivisions;
       i < kDivisions + 1 && j >= 0;
       ++i, j -= 2) {
    qv[j] = q[i];
    qv[j + 1] = v[i] * duration_over_two;
  }

  std::vector<Vector> coefficients;
  coefficients.reserve(degree);
  switch (degree) {
    case 3:
      coefficients = newhall_c_matrix_degree_3_divisions_8_w04 * qv;
      break;
    case 4:
      coefficients = newhall_c_matrix_degree_4_divisions_8_w04 * qv;
      break;
    case 5:
      coefficients = newhall_c_matrix_degree_5_divisions_8_w04 * qv;
      break;
    case 6:
      coefficients = newhall_c_matrix_degree_6_divisions_8_w04 * qv;
      break;
    case 7:
      coefficients = newhall_c_matrix_degree_7_divisions_8_w04 * qv;
      break;
    case 8:
      coefficients = newhall_c_matrix_degree_8_divisions_8_w04 * qv;
      break;
    case 9:
      coefficients = newhall_c_matrix_degree_9_divisions_8_w04 * qv;
      break;
    case 10:
      coefficients = newhall_c_matrix_degree_10_divisions_8_w04 * qv;
      break;
    case 11:
      coefficients = newhall_c_matrix_degree_11_divisions_8_w04 * qv;
      break;
    case 12:
      coefficients = newhall_c_matrix_degree_12_divisions_8_w04 * qv;
      break;
    case 13:
      coefficients = newhall_c_matrix_degree_13_divisions_8_w04 * qv;
      break;
    case 14:
      coefficients = newhall_c_matrix_degree_14_divisions_8_w04 * qv;
      break;
    case 15:
      coefficients = newhall_c_matrix_degree_15_divisions_8_w04 * qv;
      break;
    case 16:
      coefficients = newhall_c_matrix_degree_16_divisions_8_w04 * qv;
      break;
    case 17:
      coefficients = newhall_c_matrix_degree_17_divisions_8_w04 * qv;
      break;
    default:
      LOG(FATAL) << "Unexpected degree " << degree;
      break;
  }
  CHECK_EQ(degree + 1, coefficients.size());
  return ЧебышёвSeries(coefficients, t_min, t_max);
}

}  // namespace numerics
}  // namespace principia
<commit_msg>Switch and simple loop.<commit_after>
#include "numerics/чебышёв_series.hpp"

#include <vector>

#include "geometry/serialization.hpp"
#include "glog/logging.h"
#include "numerics/fixed_arrays.hpp"
#include "numerics/newhall.mathematica.cpp"

namespace principia {

using geometry::DoubleOrQuantityOrMultivectorSerializer;

namespace numerics {

template<typename Vector>
ЧебышёвSeries<Vector>::ЧебышёвSeries(std::vector<Vector> const& coefficients,
                                     Instant const& t_min,
                                     Instant const& t_max)
    : coefficients_(coefficients),
      degree_(static_cast<int>(coefficients_.size()) - 1),
      t_min_(t_min),
      t_max_(t_max) {
  CHECK_LE(0, degree_) << "Degree must be at least 0";
  CHECK_LT(t_min_, t_max_) << "Time interval must not be empty";
  // Precomputed to save operations at the expense of some accuracy loss.
  Time const duration = t_max_ - t_min_;
  t_mean_ = t_min_ + 0.5 * duration;
  two_over_duration_ = 2 / duration;
}

template<typename Vector>
ЧебышёвSeries<Vector>::ЧебышёвSeries(ЧебышёвSeries&& other)
    : coefficients_(std::move(other.coefficients_)),
      degree_(std::move(other.degree_)),
      t_min_(std::move(other.t_min_)),
      t_max_(std::move(other.t_max_)),
      t_mean_(std::move(other.t_mean_)),
      two_over_duration_(std::move(other.two_over_duration_)) {}

template<typename Vector>
ЧебышёвSeries<Vector>& ЧебышёвSeries<Vector>::operator=(
    ЧебышёвSeries&& other) {
  coefficients_ = std::move(other.coefficients_);
  degree_ = other.degree_;
  t_min_ = std::move(other.t_min_);
  t_max_ = std::move(other.t_max_);
  t_mean_ = std::move(other.t_mean_);
  two_over_duration_ = std::move(other.two_over_duration_);
  return *this;
}

template<typename Vector>
bool ЧебышёвSeries<Vector>::operator==(ЧебышёвSeries const& right) const {
  return coefficients_ == right.coefficients_ &&
         t_min_ == right.t_min_ &&
         t_max_ == right.t_max_;
}

template<typename Vector>
bool ЧебышёвSeries<Vector>::operator!=(ЧебышёвSeries const& right) const {
  return !ЧебышёвSeries<Vector>::operator==(right);
}

template<typename Vector>
Instant const& ЧебышёвSeries<Vector>::t_min() const {
  return t_min_;
}

template<typename Vector>
Instant const& ЧебышёвSeries<Vector>::t_max() const {
  return t_max_;
}

template<typename Vector>
Vector const& ЧебышёвSeries<Vector>::last_coefficient() const {
  return coefficients_[degree_];
}

template<typename Vector>
Vector ЧебышёвSeries<Vector>::Evaluate(Instant const& t) const {
  double const scaled_t = (t - t_mean_) * two_over_duration_;
  double const two_scaled_t = scaled_t + scaled_t;
  // We have to allow |scaled_t| to go slightly out of [-1, 1] because of
  // computation errors.  But if it goes too far, something is broken.
  // TODO(phl): This should use DCHECK but these macros don't work because the
  // Principia projects don't define NDEBUG.
#ifdef _DEBUG
  CHECK_LE(scaled_t, 1.1);
  CHECK_GE(scaled_t, -1.1);
#endif

  Vector const c0 = coefficients_[0];
  switch (degree_) {
  case 0:
    return c0;
  case 1:
    return c0 + scaled_t * coefficients_[1];
  default:
    Vector b_kplus2 = coefficients_[degree_];
    Vector b_kplus1 = coefficients_[degree_ - 1] + two_scaled_t * b_kplus2;
    Vector b_k;
    for (int k = degree_ - 2; k >= 1; --k) {
      b_k = coefficients_[k] + two_scaled_t * b_kplus1 - b_kplus2;
      b_kplus2 = b_kplus1;
      b_kplus1 = b_k;
    }
    return c0 + scaled_t * b_kplus1 - b_kplus2;
  }

//#define CLENSHAW_STEP1(n) \
//  bnplus2 = coefficients_[n];
//#define CLENSHAW_STEP2(n, nplus1) \
//  bnplus1 = coefficients_[n] + two_scaled_t * bnplus2;
//#define CLENSHAW_STEP3(n, nplus1, nplus2) \
//  bn = coefficients_[n] + two_scaled_t * bnplus1 - bnplus2;  \
//  bnplus2 = bnplus1; \
//  bnplus1 = bn;
}

template<typename Vector>
Variation<Vector> ЧебышёвSeries<Vector>::EvaluateDerivative(
    Instant const& t) const {
  double const scaled_t = (t - t_mean_) * two_over_duration_;
  double const two_scaled_t = scaled_t + scaled_t;
  // We have to allow |scaled_t| to go slightly out of [-1, 1] because of
  // computation errors.  But if it goes too far, something is broken.
  // TODO(phl): See above.
#ifdef _DEBUG
  CHECK_LE(scaled_t, 1.1);
  CHECK_GE(scaled_t, -1.1);
#endif

  Vector b_kplus2_vector{};
  Vector b_kplus1_vector{};
  Vector* b_kplus2 = &b_kplus2_vector;
  Vector* b_kplus1 = &b_kplus1_vector;
  Vector* const& b_k = b_kplus2;  // An overlay.
  for (int k = degree_ - 1; k >= 1; --k) {
    *b_k = coefficients_[k + 1] * (k + 1) +
           two_scaled_t * *b_kplus1 - *b_kplus2;
    Vector* const last_b_k = b_k;
    b_kplus2 = b_kplus1;
    b_kplus1 = last_b_k;
  }
  return (coefficients_[1] + two_scaled_t * *b_kplus1 - *b_kplus2) *
             two_over_duration_;
}

template<typename Vector>
void ЧебышёвSeries<Vector>::WriteToMessage(
    not_null<serialization::ЧебышёвSeries*> const message) const {
  using Serializer = DoubleOrQuantityOrMultivectorSerializer<
                          Vector,
                          serialization::ЧебышёвSeries::Coefficient>;

  for (auto const& coefficient : coefficients_) {
    Serializer::WriteToMessage(coefficient, message->add_coefficient());
  }
  t_min_.WriteToMessage(message->mutable_t_min());
  t_max_.WriteToMessage(message->mutable_t_max());
}

template<typename Vector>
ЧебышёвSeries<Vector> ЧебышёвSeries<Vector>::ReadFromMessage(
    serialization::ЧебышёвSeries const& message) {
  using Serializer = DoubleOrQuantityOrMultivectorSerializer<
                          Vector,
                          serialization::ЧебышёвSeries::Coefficient>;

  std::vector<Vector> coefficients;
  coefficients.reserve(message.coefficient_size());
  for (auto const& coefficient : message.coefficient()) {
    coefficients.push_back(Serializer::ReadFromMessage(coefficient));
  }
  return ЧебышёвSeries(coefficients,
                       Instant::ReadFromMessage(message.t_min()),
                       Instant::ReadFromMessage(message.t_max()));
}

template<typename Vector>
ЧебышёвSeries<Vector> ЧебышёвSeries<Vector>::NewhallApproximation(
    int const degree,
    std::vector<Vector> const& q,
    std::vector<Variation<Vector>> const& v,
    Instant const& t_min,
    Instant const& t_max) {
  // Only supports 8 divisions for now.
  int const kDivisions = 8;
  CHECK_EQ(kDivisions + 1, q.size());
  CHECK_EQ(kDivisions + 1, v.size());

  Time const duration_over_two = 0.5 * (t_max - t_min);

  // Tricky.  The order in Newhall's matrices is such that the entries for the
  // largest time occur first.
  FixedVector<Vector, 2 * kDivisions + 2> qv;
  for (int i = 0, j = 2 * kDivisions;
       i < kDivisions + 1 && j >= 0;
       ++i, j -= 2) {
    qv[j] = q[i];
    qv[j + 1] = v[i] * duration_over_two;
  }

  std::vector<Vector> coefficients;
  coefficients.reserve(degree);
  switch (degree) {
    case 3:
      coefficients = newhall_c_matrix_degree_3_divisions_8_w04 * qv;
      break;
    case 4:
      coefficients = newhall_c_matrix_degree_4_divisions_8_w04 * qv;
      break;
    case 5:
      coefficients = newhall_c_matrix_degree_5_divisions_8_w04 * qv;
      break;
    case 6:
      coefficients = newhall_c_matrix_degree_6_divisions_8_w04 * qv;
      break;
    case 7:
      coefficients = newhall_c_matrix_degree_7_divisions_8_w04 * qv;
      break;
    case 8:
      coefficients = newhall_c_matrix_degree_8_divisions_8_w04 * qv;
      break;
    case 9:
      coefficients = newhall_c_matrix_degree_9_divisions_8_w04 * qv;
      break;
    case 10:
      coefficients = newhall_c_matrix_degree_10_divisions_8_w04 * qv;
      break;
    case 11:
      coefficients = newhall_c_matrix_degree_11_divisions_8_w04 * qv;
      break;
    case 12:
      coefficients = newhall_c_matrix_degree_12_divisions_8_w04 * qv;
      break;
    case 13:
      coefficients = newhall_c_matrix_degree_13_divisions_8_w04 * qv;
      break;
    case 14:
      coefficients = newhall_c_matrix_degree_14_divisions_8_w04 * qv;
      break;
    case 15:
      coefficients = newhall_c_matrix_degree_15_divisions_8_w04 * qv;
      break;
    case 16:
      coefficients = newhall_c_matrix_degree_16_divisions_8_w04 * qv;
      break;
    case 17:
      coefficients = newhall_c_matrix_degree_17_divisions_8_w04 * qv;
      break;
    default:
      LOG(FATAL) << "Unexpected degree " << degree;
      break;
  }
  CHECK_EQ(degree + 1, coefficients.size());
  return ЧебышёвSeries(coefficients, t_min, t_max);
}

}  // namespace numerics
}  // namespace principia
<|endoftext|>


<commit_before>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2014      Levente Kurusa <levex@linux.com>
//

#include "GeoUriParser.h"
#include <QString>

#include "MarbleDebug.h"

namespace Marble {

GeoUriParser::GeoUriParser( const QString& geoUri )
    : m_geoUri( geoUri ),
      m_coordinates()
{
}

void GeoUriParser::setGeoUri( const QString &geoUri )
{
    m_geoUri = geoUri;
    m_coordinates = GeoDataCoordinates();
}

QString GeoUriParser::geoUri() const
{
    return m_geoUri;
}

GeoDataCoordinates GeoUriParser::coordinates() const
{
    return m_coordinates;
}

bool GeoUriParser::parse()
{
    if ( m_geoUri.isEmpty() ) {
        return false;
    }

    QString const floatRegexp = "[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?";

    QRegExp geoUriRegexp( "(?:geo:)(" + floatRegexp + "),(" + floatRegexp + "),?(" + floatRegexp + ")?(?:\;crs\=)?(.*)?(?:[\,\;]u\=)?(\d+)?" , Qt::CaseSensitive, QRegExp::RegExp2 );

    if ( geoUriRegexp.indexIn( m_geoUri ) > -1 && geoUriRegexp.captureCount() > 1 ) {
        double const lat = geoUriRegexp.capturedTexts()[1].toDouble();
        double const lon = geoUriRegexp.capturedTexts()[2].toDouble();
        double const alt = geoUriRegexp.captureCount() > 2 ? geoUriRegexp.capturedTexts()[3].toDouble() : 0.0;

        if ( geoUriRegexp.captureCount() > 3 ) {
            mDebug() << "Captured crs or u parameter, but those are not supported by Marble (yet).";
        }
        GeoDataCoordinates const coordinates( lon, lat, alt, GeoDataCoordinates::Degree );
        if ( coordinates.isValid() ) {
            m_coordinates = coordinates;
            return true;
        }
    }
    return false;
}

}
<commit_msg>Escape backslashes<commit_after>//
// This file is part of the Marble Virtual Globe.
//
// This program is free software licensed under the GNU LGPL. You can
// find a copy of this license in LICENSE.txt in the top directory of
// the source code.
//
// Copyright 2014      Levente Kurusa <levex@linux.com>
//

#include "GeoUriParser.h"
#include <QString>

#include "MarbleDebug.h"

namespace Marble {

GeoUriParser::GeoUriParser( const QString& geoUri )
    : m_geoUri( geoUri ),
      m_coordinates()
{
}

void GeoUriParser::setGeoUri( const QString &geoUri )
{
    m_geoUri = geoUri;
    m_coordinates = GeoDataCoordinates();
}

QString GeoUriParser::geoUri() const
{
    return m_geoUri;
}

GeoDataCoordinates GeoUriParser::coordinates() const
{
    return m_coordinates;
}

bool GeoUriParser::parse()
{
    if ( m_geoUri.isEmpty() ) {
        return false;
    }

    QString const floatRegexp = "[-+]?[0-9]*\\.?[0-9]+(?:[eE][-+]?[0-9]+)?";

    QRegExp geoUriRegexp( "(?:geo:)(" + floatRegexp + "),(" + floatRegexp + "),?(" + floatRegexp + ")?(?:\\;crs\\=)?(.*)?(?:[\\,\\;]u\\=)?(\\d+)?" , Qt::CaseSensitive, QRegExp::RegExp2 );

    if ( geoUriRegexp.indexIn( m_geoUri ) > -1 && geoUriRegexp.captureCount() > 1 ) {
        double const lat = geoUriRegexp.capturedTexts()[1].toDouble();
        double const lon = geoUriRegexp.capturedTexts()[2].toDouble();
        double const alt = geoUriRegexp.captureCount() > 2 ? geoUriRegexp.capturedTexts()[3].toDouble() : 0.0;

        if ( geoUriRegexp.captureCount() > 3 ) {
            mDebug() << "Captured crs or u parameter, but those are not supported by Marble (yet).";
        }
        GeoDataCoordinates const coordinates( lon, lat, alt, GeoDataCoordinates::Degree );
        if ( coordinates.isValid() ) {
            m_coordinates = coordinates;
            return true;
        }
    }
    return false;
}

}
<|endoftext|>


<commit_before>/*
 * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org)
 *
 * 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 <vector>
#include <votca/csg/boundarycondition.h>

namespace votca {
namespace csg {

double BoundaryCondition::BoxVolume() const {
  return std::abs(_box.determinant());
}

}  // namespace csg
}  // namespace votca
<commit_msg>method exception specifier made consistent with method in header<commit_after>/*
 * Copyright 2009-2019 The VOTCA Development Team (http://www.votca.org)
 *
 * 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 <vector>
#include <votca/csg/boundarycondition.h>

namespace votca {
namespace csg {

double BoundaryCondition::BoxVolume() const noexcept {
  return std::abs(_box.determinant());
}

}  // namespace csg
}  // namespace votca
<|endoftext|>