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

#ifndef MAPNIK_IMAGE_UTIL_HPP
#define MAPNIK_IMAGE_UTIL_HPP

// mapnik
#include <mapnik/config.hpp>
#include <mapnik/pixel_types.hpp>
#include <mapnik/image_compositing.hpp>

#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/optional.hpp>
#pragma GCC diagnostic pop

// stl
#include <string>
#include <exception>

namespace mapnik {

// fwd declares
class rgba_palette;
struct image_any;
template <typename T> class image;
struct image_view_any;
template <typename T> class image_view;
class color;

class image_writer_exception : public std::exception
{
private:
    std::string message_;
public:
    image_writer_exception(std::string const& message)
        : message_(message) {}

    ~image_writer_exception(){}

    virtual const char* what() const noexcept
    {
        return message_.c_str();
    }
};

template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
                              std::string const& filename,
                              std::string const& type);

template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
                              std::string const& filename,
                              std::string const& type,
                              rgba_palette const& palette);

// guess type from file extension
template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
                              std::string const& filename);

template <typename T>
MAPNIK_DECL void save_to_file(T const& image,
                              std::string const& filename,
                              rgba_palette const& palette);

template <typename T>
MAPNIK_DECL std::string save_to_string(T const& image,
                                       std::string const& type);

template <typename T>
MAPNIK_DECL std::string save_to_string(T const& image,
                                       std::string const& type,
                                       rgba_palette const& palette);

template <typename T>
MAPNIK_DECL void save_to_stream
(
    T const& image,
    std::ostream & stream,
    std::string const& type,
    rgba_palette const& palette
);

template <typename T>
MAPNIK_DECL void save_to_stream
(
    T const& image,
    std::ostream & stream,
    std::string const& type
);

// PREMULTIPLY ALPHA
MAPNIK_DECL bool premultiply_alpha(image_any & image);

template <typename T>
MAPNIK_DECL bool premultiply_alpha(T & image);

// DEMULTIPLY ALPHA
MAPNIK_DECL bool demultiply_alpha(image_any & image);

template <typename T>
MAPNIK_DECL bool demultiply_alpha(T & image);

// SET PREMULTIPLIED ALPHA
MAPNIK_DECL void set_premultiplied_alpha(image_any & image, bool status);

template <typename T>
MAPNIK_DECL void set_premultiplied_alpha(T & image, bool status);

// IS SOLID
MAPNIK_DECL bool is_solid (image_any const& image);
MAPNIK_DECL bool is_solid (image_view_any const& image);

template <typename T>
MAPNIK_DECL bool is_solid (T const& image);

// APPLY OPACITY
MAPNIK_DECL void apply_opacity (image_any & image, float opacity);

template <typename T>
MAPNIK_DECL void apply_opacity (T & image, float opacity);

// SET GRAYSCALE TO ALPHA
MAPNIK_DECL void set_grayscale_to_alpha (image_any & image);
MAPNIK_DECL void set_grayscale_to_alpha (image_any & image, color const& c);

template <typename T>
MAPNIK_DECL void set_grayscale_to_alpha (T & image);

template <typename T>
MAPNIK_DECL void set_grayscale_to_alpha (T & image, color const& c);

// SET COLOR TO ALPHA
MAPNIK_DECL void set_color_to_alpha (image_any & image, color const& c);

template <typename T>
MAPNIK_DECL void set_color_to_alpha (T & image, color const& c);

// FILL
template <typename T>
MAPNIK_DECL void fill (image_any & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<rgba8_t> & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray8_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray8s_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray16_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray16s_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray32_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray32s_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray32f_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray64_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray64s_t>  & data, T const&);

template <typename T>
MAPNIK_DECL void fill (image<gray64f_t> & data, T const&);

// CHECK BOUNDS
template <typename T>
inline bool check_bounds (T const& data, std::size_t x, std::size_t y)
{
    return (x < data.width() && y < data.height());
}

// COMPOSITE_PIXEL
MAPNIK_DECL void composite_pixel(image_any & data, composite_mode_e comp_op, std::size_t x, std::size_t y, unsigned c, unsigned cover, double opacity );

template <typename T>
MAPNIK_DECL void composite_pixel(T & data, composite_mode_e comp_op, std::size_t x, std::size_t y, unsigned c, unsigned cover, double opacity );

// SET PIXEL
template <typename T>
MAPNIK_DECL void set_pixel(image_any & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<rgba8_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray8_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray8s_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray16_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray16s_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray32_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray32s_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray32f_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray64_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray64s_t> & data, std::size_t x, std::size_t y, T const& val);

template <typename T>
MAPNIK_DECL void set_pixel(image<gray64f_t> & data, std::size_t x, std::size_t y, T const& val);

// GET PIXEL
template <typename T>
MAPNIK_DECL T get_pixel(image_any const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view_any const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<rgba8_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray8_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray8s_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray16_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray16s_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray32_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray32s_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray32f_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray64_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray64s_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image<gray64f_t> const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<rgba8_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray8_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray8s_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray16_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray16s_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32s_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray32f_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64s_t> > const& data, std::size_t x, std::size_t y);

template <typename T>
MAPNIK_DECL T get_pixel(image_view<image<gray64f_t> > const& data, std::size_t x, std::size_t y);

// VIEW TO OUTPUT STREAM
template <typename Out>
MAPNIK_DECL void view_to_stream (image_view_any const& view, Out & os);

// CREATE VIEW
MAPNIK_DECL image_view_any create_view (image_any const& data, std::size_t x, std::size_t y, std::size_t w, std::size_t h);

// COMPARE
template <typename T>
MAPNIK_DECL std::size_t compare(T const& im1, T const& im2, double threshold = 0.0, bool alpha = true);

inline bool is_png(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".png"));
}

inline bool is_jpeg(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".jpg")) ||
        boost::algorithm::iends_with(filename,std::string(".jpeg"));
}

inline bool is_tiff(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".tif")) ||
        boost::algorithm::iends_with(filename,std::string(".tiff"));
}

inline bool is_pdf(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".pdf"));
}

inline bool is_svg(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".svg"));
}

inline bool is_ps(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".ps"));
}

inline bool is_webp(std::string const& filename)
{
    return boost::algorithm::iends_with(filename,std::string(".webp"));
}

inline boost::optional<std::string> type_from_filename(std::string const& filename)

{
    using result_type = boost::optional<std::string>;
    if (is_png(filename)) return result_type("png");
    if (is_jpeg(filename)) return result_type("jpeg");
    if (is_tiff(filename)) return result_type("tiff");
    if (is_pdf(filename)) return result_type("pdf");
    if (is_svg(filename)) return result_type("svg");
    if (is_ps(filename)) return result_type("ps");
    if (is_webp(filename)) return result_type("webp");
    return result_type();
}

inline std::string guess_type( std::string const& filename )
{
    std::string::size_type idx = filename.find_last_of(".");
    if ( idx != std::string::npos ) {
        return filename.substr( idx + 1 );
    }
    return "<unknown>";
}

// add 1-px border around image - useful for debugging alignment issues
template <typename T>
void add_border(T & image)
{
    for (unsigned  x = 0; x < image.width();++x)
    {
        image(x,0) = 0xff0000ff; // red
        image(x,image.height()-1) = 0xff00ff00; //green
    }
    for (unsigned y = 0; y < image.height();++y)
    {
        image(0,y) = 0xff00ffff; //yellow
        image(image.width()-1,y) = 0xffff0000; // blue
    }
}
}

#endif // MAPNIK_IMAGE_UTIL_HPP


text:
// ***********************************************************************
//                      DO NOT EDIT THIS FILE !!!
// ***********************************************************************
//   This file is automatically generated from the grib_api templates. All
//   changes will be overridden. If you want to do permanent changes then
//   you should write them into the 'ParameterAerosolOpticalSettingsImpl.*' files.
// ***********************************************************************

#include "ParameterAerosolOpticalSettings.h"
#include "../../common/GeneralDefinitions.h"
#include "../../common/GeneralFunctions.h"
#include <boost/functional/hash.hpp>
#include <iostream>
#include <macgyver/Exception.h>

namespace SmartMet {
namespace GRIB2 {

/*! \brief The constructor of the class. */

ParameterAerosolOpticalSettings::ParameterAerosolOpticalSettings() {
  try {
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The destructor of the class. */

ParameterAerosolOpticalSettings::~ParameterAerosolOpticalSettings() {
}

/*! \brief The method reads and initializes all data related to the current object.

        \param memoryReader  This object controls the access to the memory mapped file.
*/

void ParameterAerosolOpticalSettings::read(MemoryReader &memoryReader) {
  try {
    mParameterCategory = memoryReader.read_UInt8_opt();
    mParameterNumber = memoryReader.read_UInt8_opt();
    mAerosolType = memoryReader.read_UInt16_opt();
    mTypeOfSizeInterval = memoryReader.read_UInt8_opt();
    mScaleFactorOfFirstSize = memoryReader.read_Int8_opt();
    mScaledValueOfFirstSize = memoryReader.read_Int32_opt();
    mScaleFactorOfSecondSize = memoryReader.read_Int8_opt();
    mScaledValueOfSecondSize = memoryReader.read_Int32_opt();
    mTypeOfWavelengthInterval = memoryReader.read_UInt8_opt();
    mScaleFactorOfFirstWavelength = memoryReader.read_Int8_opt();
    mScaledValueOfFirstWavelength = memoryReader.read_Int32_opt();
    mScaleFactorOfSecondWavelength = memoryReader.read_Int8_opt();
    mScaledValueOfSecondWavelength = memoryReader.read_Int32_opt();
    mTypeOfGeneratingProcess = memoryReader.read_UInt8_opt();
    mBackgroundProcess = memoryReader.read_UInt8_opt();
    mGeneratingProcessIdentifier = memoryReader.read_UInt8_opt();
    mHoursAfterDataCutoff = memoryReader.read_UInt16_opt();
    mMinutesAfterDataCutoff = memoryReader.read_UInt8_opt();
    mIndicatorOfUnitOfTimeRange = memoryReader.read_UInt8_opt();
    mForecastTime = memoryReader.read_Int32_opt();
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method writes all data related to the current object.

        \param dataWriter  This object is used for writing the object data.
*/

void ParameterAerosolOpticalSettings::write(DataWriter &dataWriter) {
  try {
    dataWriter << mParameterCategory;
    dataWriter << mParameterNumber;
    dataWriter << mAerosolType;
    dataWriter << mTypeOfSizeInterval;
    dataWriter << mScaleFactorOfFirstSize;
    dataWriter << mScaledValueOfFirstSize;
    dataWriter << mScaleFactorOfSecondSize;
    dataWriter << mScaledValueOfSecondSize;
    dataWriter << mTypeOfWavelengthInterval;
    dataWriter << mScaleFactorOfFirstWavelength;
    dataWriter << mScaledValueOfFirstWavelength;
    dataWriter << mScaleFactorOfSecondWavelength;
    dataWriter << mScaledValueOfSecondWavelength;
    dataWriter << mTypeOfGeneratingProcess;
    dataWriter << mBackgroundProcess;
    dataWriter << mGeneratingProcessIdentifier;
    dataWriter << mHoursAfterDataCutoff;
    dataWriter << mMinutesAfterDataCutoff;
    dataWriter << mIndicatorOfUnitOfTimeRange;
    dataWriter << mForecastTime;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method is used for collecting the current class attributeList.

    \param prefix         The prefix of the each attributeList parameter.
    \param attributeList  The attributeList storage.
*/

void ParameterAerosolOpticalSettings::getAttributeList(const std::string &prefix, T::AttributeList &attributeList) const {
  try {
    char name[300];
    sprintf(name, "%sParameterAerosolOpticalSettings.ParameterCategory", prefix.c_str());
    attributeList.addAttribute(name, toString(mParameterCategory));
    sprintf(name, "%sParameterAerosolOpticalSettings.ParameterNumber", prefix.c_str());
    attributeList.addAttribute(name, toString(mParameterNumber));
    sprintf(name, "%sParameterAerosolOpticalSettings.AerosolType", prefix.c_str());
    attributeList.addAttribute(name, toString(mAerosolType));
    sprintf(name, "%sParameterAerosolOpticalSettings.TypeOfSizeInterval", prefix.c_str());
    attributeList.addAttribute(name, toString(mTypeOfSizeInterval));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaleFactorOfFirstSize", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaleFactorOfFirstSize));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaledValueOfFirstSize", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaledValueOfFirstSize));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaleFactorOfSecondSize", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaleFactorOfSecondSize));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaledValueOfSecondSize", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaledValueOfSecondSize));
    sprintf(name, "%sParameterAerosolOpticalSettings.TypeOfWavelengthInterval", prefix.c_str());
    attributeList.addAttribute(name, toString(mTypeOfWavelengthInterval));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaleFactorOfFirstWavelength", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaleFactorOfFirstWavelength));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaledValueOfFirstWavelength", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaledValueOfFirstWavelength));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaleFactorOfSecondWavelength", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaleFactorOfSecondWavelength));
    sprintf(name, "%sParameterAerosolOpticalSettings.ScaledValueOfSecondWavelength", prefix.c_str());
    attributeList.addAttribute(name, toString(mScaledValueOfSecondWavelength));
    sprintf(name, "%sParameterAerosolOpticalSettings.TypeOfGeneratingProcess", prefix.c_str());
    attributeList.addAttribute(name, toString(mTypeOfGeneratingProcess));
    sprintf(name, "%sParameterAerosolOpticalSettings.BackgroundProcess", prefix.c_str());
    attributeList.addAttribute(name, toString(mBackgroundProcess));
    sprintf(name, "%sParameterAerosolOpticalSettings.GeneratingProcessIdentifier", prefix.c_str());
    attributeList.addAttribute(name, toString(mGeneratingProcessIdentifier));
    sprintf(name, "%sParameterAerosolOpticalSettings.HoursAfterDataCutoff", prefix.c_str());
    attributeList.addAttribute(name, toString(mHoursAfterDataCutoff));
    sprintf(name, "%sParameterAerosolOpticalSettings.MinutesAfterDataCutoff", prefix.c_str());
    attributeList.addAttribute(name, toString(mMinutesAfterDataCutoff));
    sprintf(name, "%sParameterAerosolOpticalSettings.IndicatorOfUnitOfTimeRange", prefix.c_str());
    attributeList.addAttribute(name, toString(mIndicatorOfUnitOfTimeRange));
    sprintf(name, "%sParameterAerosolOpticalSettings.ForecastTime", prefix.c_str());
    attributeList.addAttribute(name, toString(mForecastTime));
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method is used for getting attribute values by their names.

    \param attributeName  The name of the attribute.
    \param attributeValue The value of the attribute (string).
*/

bool ParameterAerosolOpticalSettings::getAttributeValue(const char *attributeName, std::string &attributeValue) const {
  try {
    if (attributeName == nullptr)
      return false;
    if (strcasecmp(attributeName, "ParameterCategory") == 0) {
      attributeValue = toString(mParameterCategory);
      return true;
    }
    if (strcasecmp(attributeName, "ParameterNumber") == 0) {
      attributeValue = toString(mParameterNumber);
      return true;
    }
    if (strcasecmp(attributeName, "AerosolType") == 0) {
      attributeValue = toString(mAerosolType);
      return true;
    }
    if (strcasecmp(attributeName, "TypeOfSizeInterval") == 0) {
      attributeValue = toString(mTypeOfSizeInterval);
      return true;
    }
    if (strcasecmp(attributeName, "ScaleFactorOfFirstSize") == 0) {
      attributeValue = toString(mScaleFactorOfFirstSize);
      return true;
    }
    if (strcasecmp(attributeName, "ScaledValueOfFirstSize") == 0) {
      attributeValue = toString(mScaledValueOfFirstSize);
      return true;
    }
    if (strcasecmp(attributeName, "ScaleFactorOfSecondSize") == 0) {
      attributeValue = toString(mScaleFactorOfSecondSize);
      return true;
    }
    if (strcasecmp(attributeName, "ScaledValueOfSecondSize") == 0) {
      attributeValue = toString(mScaledValueOfSecondSize);
      return true;
    }
    if (strcasecmp(attributeName, "TypeOfWavelengthInterval") == 0) {
      attributeValue = toString(mTypeOfWavelengthInterval);
      return true;
    }
    if (strcasecmp(attributeName, "ScaleFactorOfFirstWavelength") == 0) {
      attributeValue = toString(mScaleFactorOfFirstWavelength);
      return true;
    }
    if (strcasecmp(attributeName, "ScaledValueOfFirstWavelength") == 0) {
      attributeValue = toString(mScaledValueOfFirstWavelength);
      return true;
    }
    if (strcasecmp(attributeName, "ScaleFactorOfSecondWavelength") == 0) {
      attributeValue = toString(mScaleFactorOfSecondWavelength);
      return true;
    }
    if (strcasecmp(attributeName, "ScaledValueOfSecondWavelength") == 0) {
      attributeValue = toString(mScaledValueOfSecondWavelength);
      return true;
    }
    if (strcasecmp(attributeName, "TypeOfGeneratingProcess") == 0) {
      attributeValue = toString(mTypeOfGeneratingProcess);
      return true;
    }
    if (strcasecmp(attributeName, "BackgroundProcess") == 0) {
      attributeValue = toString(mBackgroundProcess);
      return true;
    }
    if (strcasecmp(attributeName, "GeneratingProcessIdentifier") == 0) {
      attributeValue = toString(mGeneratingProcessIdentifier);
      return true;
    }
    if (strcasecmp(attributeName, "HoursAfterDataCutoff") == 0) {
      attributeValue = toString(mHoursAfterDataCutoff);
      return true;
    }
    if (strcasecmp(attributeName, "MinutesAfterDataCutoff") == 0) {
      attributeValue = toString(mMinutesAfterDataCutoff);
      return true;
    }
    if (strcasecmp(attributeName, "IndicatorOfUnitOfTimeRange") == 0) {
      attributeValue = toString(mIndicatorOfUnitOfTimeRange);
      return true;
    }
    if (strcasecmp(attributeName, "ForecastTime") == 0) {
      attributeValue = toString(mForecastTime);
      return true;
    }
    return false;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method is used for checking if the attribute value matches to the given value.

    \param attributeName  The name of the attribute.
    \param attributeValue The value of the attribute (string).
*/

bool ParameterAerosolOpticalSettings::hasAttributeValue(const char *attributeName, const char *attributeValue) const {
  try {
    if (attributeName == nullptr || attributeValue == nullptr)
      return false;
    if (strcasecmp(attributeName, "ParameterCategory") == 0 && strcasecmp(attributeValue, toString(mParameterCategory).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ParameterNumber") == 0 && strcasecmp(attributeValue, toString(mParameterNumber).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "AerosolType") == 0 && strcasecmp(attributeValue, toString(mAerosolType).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "TypeOfSizeInterval") == 0 && strcasecmp(attributeValue, toString(mTypeOfSizeInterval).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaleFactorOfFirstSize") == 0 && strcasecmp(attributeValue, toString(mScaleFactorOfFirstSize).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaledValueOfFirstSize") == 0 && strcasecmp(attributeValue, toString(mScaledValueOfFirstSize).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaleFactorOfSecondSize") == 0 && strcasecmp(attributeValue, toString(mScaleFactorOfSecondSize).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaledValueOfSecondSize") == 0 && strcasecmp(attributeValue, toString(mScaledValueOfSecondSize).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "TypeOfWavelengthInterval") == 0 && strcasecmp(attributeValue, toString(mTypeOfWavelengthInterval).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaleFactorOfFirstWavelength") == 0 && strcasecmp(attributeValue, toString(mScaleFactorOfFirstWavelength).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaledValueOfFirstWavelength") == 0 && strcasecmp(attributeValue, toString(mScaledValueOfFirstWavelength).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaleFactorOfSecondWavelength") == 0 && strcasecmp(attributeValue, toString(mScaleFactorOfSecondWavelength).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ScaledValueOfSecondWavelength") == 0 && strcasecmp(attributeValue, toString(mScaledValueOfSecondWavelength).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "TypeOfGeneratingProcess") == 0 && strcasecmp(attributeValue, toString(mTypeOfGeneratingProcess).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "BackgroundProcess") == 0 && strcasecmp(attributeValue, toString(mBackgroundProcess).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "GeneratingProcessIdentifier") == 0 && strcasecmp(attributeValue, toString(mGeneratingProcessIdentifier).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "HoursAfterDataCutoff") == 0 && strcasecmp(attributeValue, toString(mHoursAfterDataCutoff).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "MinutesAfterDataCutoff") == 0 && strcasecmp(attributeValue, toString(mMinutesAfterDataCutoff).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "IndicatorOfUnitOfTimeRange") == 0 && strcasecmp(attributeValue, toString(mIndicatorOfUnitOfTimeRange).c_str()) == 0)
      return true;
    if (strcasecmp(attributeName, "ForecastTime") == 0 && strcasecmp(attributeValue, toString(mForecastTime).c_str()) == 0)
      return true;
    return false;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method prints the content of the current object into the given stream.

    \param ostream      The output stream.
    \param level        The print level (used when printing multi-level structures).
    \param optionFlags  The printing options expressed in flag-bits.
*/

void ParameterAerosolOpticalSettings::print(std::ostream &stream, uint level, uint optionFlags) const {
  try {
    stream << space(level) << "ParameterAerosolOpticalSettings\n";
    stream << space(level) << "- ParameterCategory = " << toString(mParameterCategory) << "\n";
    stream << space(level) << "- ParameterNumber = " << toString(mParameterNumber) << "\n";
    stream << space(level) << "- AerosolType = " << toString(mAerosolType) << "\n";
    stream << space(level) << "- TypeOfSizeInterval = " << toString(mTypeOfSizeInterval) << "\n";
    stream << space(level) << "- ScaleFactorOfFirstSize = " << toString(mScaleFactorOfFirstSize) << "\n";
    stream << space(level) << "- ScaledValueOfFirstSize = " << toString(mScaledValueOfFirstSize) << "\n";
    stream << space(level) << "- ScaleFactorOfSecondSize = " << toString(mScaleFactorOfSecondSize) << "\n";
    stream << space(level) << "- ScaledValueOfSecondSize = " << toString(mScaledValueOfSecondSize) << "\n";
    stream << space(level) << "- TypeOfWavelengthInterval = " << toString(mTypeOfWavelengthInterval) << "\n";
    stream << space(level) << "- ScaleFactorOfFirstWavelength = " << toString(mScaleFactorOfFirstWavelength) << "\n";
    stream << space(level) << "- ScaledValueOfFirstWavelength = " << toString(mScaledValueOfFirstWavelength) << "\n";
    stream << space(level) << "- ScaleFactorOfSecondWavelength = " << toString(mScaleFactorOfSecondWavelength) << "\n";
    stream << space(level) << "- ScaledValueOfSecondWavelength = " << toString(mScaledValueOfSecondWavelength) << "\n";
    stream << space(level) << "- TypeOfGeneratingProcess = " << toString(mTypeOfGeneratingProcess) << "\n";
    stream << space(level) << "- BackgroundProcess = " << toString(mBackgroundProcess) << "\n";
    stream << space(level) << "- GeneratingProcessIdentifier = " << toString(mGeneratingProcessIdentifier) << "\n";
    stream << space(level) << "- HoursAfterDataCutoff = " << toString(mHoursAfterDataCutoff) << "\n";
    stream << space(level) << "- MinutesAfterDataCutoff = " << toString(mMinutesAfterDataCutoff) << "\n";
    stream << space(level) << "- IndicatorOfUnitOfTimeRange = " << toString(mIndicatorOfUnitOfTimeRange) << "\n";
    stream << space(level) << "- ForecastTime = " << toString(mForecastTime) << "\n";
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method counts the hash value of the current object. */

T::Hash ParameterAerosolOpticalSettings::countHash() const {
  try {
    std::size_t seed = 0;
    if (mParameterCategory)
      boost::hash_combine(seed, *mParameterCategory);
    if (mParameterNumber)
      boost::hash_combine(seed, *mParameterNumber);
    if (mAerosolType)
      boost::hash_combine(seed, *mAerosolType);
    if (mTypeOfSizeInterval)
      boost::hash_combine(seed, *mTypeOfSizeInterval);
    if (mScaleFactorOfFirstSize)
      boost::hash_combine(seed, *mScaleFactorOfFirstSize);
    if (mScaledValueOfFirstSize)
      boost::hash_combine(seed, *mScaledValueOfFirstSize);
    if (mScaleFactorOfSecondSize)
      boost::hash_combine(seed, *mScaleFactorOfSecondSize);
    if (mScaledValueOfSecondSize)
      boost::hash_combine(seed, *mScaledValueOfSecondSize);
    if (mTypeOfWavelengthInterval)
      boost::hash_combine(seed, *mTypeOfWavelengthInterval);
    if (mScaleFactorOfFirstWavelength)
      boost::hash_combine(seed, *mScaleFactorOfFirstWavelength);
    if (mScaledValueOfFirstWavelength)
      boost::hash_combine(seed, *mScaledValueOfFirstWavelength);
    if (mScaleFactorOfSecondWavelength)
      boost::hash_combine(seed, *mScaleFactorOfSecondWavelength);
    if (mScaledValueOfSecondWavelength)
      boost::hash_combine(seed, *mScaledValueOfSecondWavelength);
    if (mTypeOfGeneratingProcess)
      boost::hash_combine(seed, *mTypeOfGeneratingProcess);
    if (mBackgroundProcess)
      boost::hash_combine(seed, *mBackgroundProcess);
    if (mGeneratingProcessIdentifier)
      boost::hash_combine(seed, *mGeneratingProcessIdentifier);
    if (mHoursAfterDataCutoff)
      boost::hash_combine(seed, *mHoursAfterDataCutoff);
    if (mMinutesAfterDataCutoff)
      boost::hash_combine(seed, *mMinutesAfterDataCutoff);
    if (mIndicatorOfUnitOfTimeRange)
      boost::hash_combine(seed, *mIndicatorOfUnitOfTimeRange);
    if (mForecastTime)
      boost::hash_combine(seed, *mForecastTime);
    return seed;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mParameterCategory} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getParameterCategory() const {
  try {
    return mParameterCategory;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mParameterNumber} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getParameterNumber() const {
  try {
    return mParameterNumber;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mAerosolType} attribute. */

const T::UInt16_opt &ParameterAerosolOpticalSettings::getAerosolType() const {
  try {
    return mAerosolType;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mTypeOfSizeInterval} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getTypeOfSizeInterval() const {
  try {
    return mTypeOfSizeInterval;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaleFactorOfFirstSize} attribute. */

const T::Int8_opt &ParameterAerosolOpticalSettings::getScaleFactorOfFirstSize() const {
  try {
    return mScaleFactorOfFirstSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaledValueOfFirstSize} attribute. */

const T::Int32_opt &ParameterAerosolOpticalSettings::getScaledValueOfFirstSize() const {
  try {
    return mScaledValueOfFirstSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaleFactorOfSecondSize} attribute. */

const T::Int8_opt &ParameterAerosolOpticalSettings::getScaleFactorOfSecondSize() const {
  try {
    return mScaleFactorOfSecondSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaledValueOfSecondSize} attribute. */

const T::Int32_opt &ParameterAerosolOpticalSettings::getScaledValueOfSecondSize() const {
  try {
    return mScaledValueOfSecondSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mTypeOfWavelengthInterval} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getTypeOfWavelengthInterval() const {
  try {
    return mTypeOfWavelengthInterval;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaleFactorOfFirstWavelength} attribute. */

const T::Int8_opt &ParameterAerosolOpticalSettings::getScaleFactorOfFirstWavelength() const {
  try {
    return mScaleFactorOfFirstWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaledValueOfFirstWavelength} attribute. */

const T::Int32_opt &ParameterAerosolOpticalSettings::getScaledValueOfFirstWavelength() const {
  try {
    return mScaledValueOfFirstWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaleFactorOfSecondWavelength} attribute. */

const T::Int8_opt &ParameterAerosolOpticalSettings::getScaleFactorOfSecondWavelength() const {
  try {
    return mScaleFactorOfSecondWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mScaledValueOfSecondWavelength} attribute. */

const T::Int32_opt &ParameterAerosolOpticalSettings::getScaledValueOfSecondWavelength() const {
  try {
    return mScaledValueOfSecondWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mTypeOfGeneratingProcess} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getTypeOfGeneratingProcess() const {
  try {
    return mTypeOfGeneratingProcess;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mBackgroundProcess} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getBackgroundProcess() const {
  try {
    return mBackgroundProcess;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mGeneratingProcessIdentifier} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getGeneratingProcessIdentifier() const {
  try {
    return mGeneratingProcessIdentifier;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mHoursAfterDataCutoff} attribute. */

const T::UInt16_opt &ParameterAerosolOpticalSettings::getHoursAfterDataCutoff() const {
  try {
    return mHoursAfterDataCutoff;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mMinutesAfterDataCutoff} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getMinutesAfterDataCutoff() const {
  try {
    return mMinutesAfterDataCutoff;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mIndicatorOfUnitOfTimeRange} attribute. */

const T::UInt8_opt &ParameterAerosolOpticalSettings::getIndicatorOfUnitOfTimeRange() const {
  try {
    return mIndicatorOfUnitOfTimeRange;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

/*! \brief The method returns the value of the {@link mForecastTime} attribute. */

const T::Int32_opt &ParameterAerosolOpticalSettings::getForecastTime() const {
  try {
    return mForecastTime;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setParameterCategory(T::UInt8_opt parameterCategory) {
  try {
    mParameterCategory = parameterCategory;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setParameterNumber(T::UInt8_opt parameterNumber) {
  try {
    mParameterNumber = parameterNumber;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setAerosolType(T::UInt16_opt aerosolType) {
  try {
    mAerosolType = aerosolType;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setTypeOfSizeInterval(T::UInt8_opt typeOfSizeInterval) {
  try {
    mTypeOfSizeInterval = typeOfSizeInterval;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaleFactorOfFirstSize(T::Int8_opt scaleFactorOfFirstSize) {
  try {
    mScaleFactorOfFirstSize = scaleFactorOfFirstSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaledValueOfFirstSize(T::Int32_opt scaledValueOfFirstSize) {
  try {
    mScaledValueOfFirstSize = scaledValueOfFirstSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaleFactorOfSecondSize(T::Int8_opt scaleFactorOfSecondSize) {
  try {
    mScaleFactorOfSecondSize = scaleFactorOfSecondSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaledValueOfSecondSize(T::Int32_opt scaledValueOfSecondSize) {
  try {
    mScaledValueOfSecondSize = scaledValueOfSecondSize;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setTypeOfWavelengthInterval(T::UInt8_opt typeOfWavelengthInterval) {
  try {
    mTypeOfWavelengthInterval = typeOfWavelengthInterval;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaleFactorOfFirstWavelength(T::Int8_opt scaleFactorOfFirstWavelength) {
  try {
    mScaleFactorOfFirstWavelength = scaleFactorOfFirstWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaledValueOfFirstWavelength(T::Int32_opt scaledValueOfFirstWavelength) {
  try {
    mScaledValueOfFirstWavelength = scaledValueOfFirstWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaleFactorOfSecondWavelength(T::Int8_opt scaleFactorOfSecondWavelength) {
  try {
    mScaleFactorOfSecondWavelength = scaleFactorOfSecondWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setScaledValueOfSecondWavelength(T::Int32_opt scaledValueOfSecondWavelength) {
  try {
    mScaledValueOfSecondWavelength = scaledValueOfSecondWavelength;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setTypeOfGeneratingProcess(T::UInt8_opt typeOfGeneratingProcess) {
  try {
    mTypeOfGeneratingProcess = typeOfGeneratingProcess;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setBackgroundProcess(T::UInt8_opt backgroundProcess) {
  try {
    mBackgroundProcess = backgroundProcess;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setGeneratingProcessIdentifier(T::UInt8_opt generatingProcessIdentifier) {
  try {
    mGeneratingProcessIdentifier = generatingProcessIdentifier;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setHoursAfterDataCutoff(T::UInt16_opt hoursAfterDataCutoff) {
  try {
    mHoursAfterDataCutoff = hoursAfterDataCutoff;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setMinutesAfterDataCutoff(T::UInt8_opt minutesAfterDataCutoff) {
  try {
    mMinutesAfterDataCutoff = minutesAfterDataCutoff;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setIndicatorOfUnitOfTimeRange(T::UInt8_opt indicatorOfUnitOfTimeRange) {
  try {
    mIndicatorOfUnitOfTimeRange = indicatorOfUnitOfTimeRange;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

void ParameterAerosolOpticalSettings::setForecastTime(T::Int32_opt forecastTime) {
  try {
    mForecastTime = forecastTime;
  } catch (...) {
    throw Fmi::Exception(BCP, "Operation failed", nullptr);
  }
}

} // namespace GRIB2
} // namespace SmartMet

ext: cpp

max_stars_repo_name: fmidev/smartmet-library-grid-files

max_issues_repo_name: fmidev/smartmet-library-grid-files

max_forks_repo_name: fmidev/smartmet-library-grid-files


text:
/* Copyright (c) 2020 - 2021, the adamantine authors.
 *
 * This file is subject to the Modified BSD License and may not be distributed
 * without copyright and license information. Please refer to the file LICENSE
 * for the text and further information on this license.
 */

#ifndef HEAT_SOURCE_HH
#define HEAT_SOURCE_HH

#include <BeamHeatSourceProperties.hh>
#include <ScanPath.hh>
#include <types.hh>

#include <deal.II/base/point.h>

namespace adamantine
{
/**
 * This is the base class for describing the functional form of a heat
 * source. It has a pure virtual "value" method that needs to be implemented in
 * a derived class.
 * NOTE: The coordinate system in this class is different than
 * for the finite element mesh. In this class, the first two components of a
 * dealii::Point<3> describe the position along the surface of the part. The
 * last component is the height through the thickness of the part from the base
 * plate. This is in opposition to the finite element mesh where the first and
 * last components of a dealii::Point<3> describe the position along the surface
 * of the part, and the second component is the thickness. That is, the last two
 * components are swapped between the two coordinate systems.
 */
template <int dim>
class HeatSource
{
public:
  /**
   * Default constructor. This constructor should only be used for non-beam heat
   * source.
   */
  HeatSource() = default;

  /**
   * Constructor.
   * \param[in] database requires the following entries:
   *   - absorption_efficiency: double in \f$[0,1]\f$
   *   - depth: double in \f$[0,\infty)\f$
   *   - diameter: double in \f$[0,\infty)\f$
   *   - max_power: double in \f$[0, \infty)\f$
   *   - input_file: name of the file that contains the scan path
   *     segments
   */
  HeatSource(boost::property_tree::ptree const &database)
      : _beam(database),
        // PropertyTreeInput sources.beam_X.scan_path_file
        // PropertyTreeInput sources.beam_X.scan_path_format
        _scan_path(database.get<std::string>("scan_path_file"),
                   database.get<std::string>("scan_path_file_format"))
  {
  }

  /**
   * Destructor.
   */
  virtual ~HeatSource() = default;

  /**
   * Compute the heat source at a given point at a given time given the current
   * height of the object being manufactured.
   */
  virtual double value(dealii::Point<dim> const &point, double const time,
                       double const height) const = 0;
  /**
   * Return the scan path for the heat source.
   */
  virtual ScanPath const &get_scan_path() const;

  /**
   * Compute the current height of the where the heat source meets the material
   * (i.e. the current scan path height).
   */
  virtual double get_current_height(double const time) const;

protected:
  /**
   * Structure of the physical properties of the beam heat source.
   */
  BeamHeatSourceProperties _beam;

  /**
   * The scan path for the heat source.
   */
  ScanPath _scan_path;
};

template <int dim>
inline ScanPath const &HeatSource<dim>::get_scan_path() const
{
  return _scan_path;
}

template <int dim>
inline double HeatSource<dim>::get_current_height(double const time) const
{
  return _scan_path.value(time)[2];
}

} // namespace adamantine

#endif

ext: hh

max_stars_repo_name: Rombur/adamantine

max_issues_repo_name: Rombur/adamantine

max_forks_repo_name: Rombur/adamantine


text:
/******************************************************************************

  This source file is part of the MongoChem project.

  Copyright 2011-2012 Kitware, Inc.

  This source code is released under the New BSD License, (the "License").

  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 "substructurefiltermodel.h"

#include <boost/make_shared.hpp>

#include <mongo/client/dbclient.h>

#include <chemkit/molecule.h>

namespace MongoChem {

using namespace mongo;

SubstructureFilterModel::SubstructureFilterModel(QObject *parent_)
  : QSortFilterProxyModel(parent_)
{
}

SubstructureFilterModel::~SubstructureFilterModel()
{
}

void SubstructureFilterModel::setIdentifier(const QString &identifier_)
{
  m_identifier = identifier_;

  std::string format;
  if (identifier_.startsWith("InChI="))
    format = "inchi";
  else
    format = "smiles";
  m_query.setMolecule(identifier_.toStdString(), format);
}

QString SubstructureFilterModel::identifier() const
{
  return m_identifier;
}

bool SubstructureFilterModel::filterAcceptsColumn(int, const QModelIndex &) const
{
  // Accept and display all columns.
  return true;
}

bool SubstructureFilterModel::filterAcceptsRow(int sourceRow,
                                               const QModelIndex &sourceParent) const
{
  if (!m_query.molecule() || m_query.molecule()->isEmpty())
    return false;

  // get the bson object for the row
  QModelIndex index_ = sourceModel()->index(sourceRow, 0, sourceParent);
  BSONObj *obj = static_cast<BSONObj *>(index_.internalPointer());
  if (!obj)
    return false;

  // get the molecule's inchi
  BSONElement elem = obj->getField("inchi");
  if (elem.eoo())
    return false;

  // create a molecule from the inchi formula
  chemkit::Molecule molecule(elem.str(), "inchi");

  // test the molecule against the query structure
  return m_query.matches(&molecule);
}

} // end MongoChem namespace

max_stars_repo_name: OpenChemistry/mongochem

max_issues_repo_name: OpenChemistry/mongochem

max_forks_repo_name: OpenChemistry/mongochem


text:
/*
 * plugin.cpp
 *
 *  Created on: Jan 25, 2019
 *      Author: iconmaster
 */

#include "session.hpp"
#include "error.hpp"
#include "util.hpp"

#include <string>
#include <iostream>
#include <fstream>
#include <sstream>
#include <boost/filesystem.hpp>
#include <cerrno>
#include <cstdlib>
#include <thread>
#include <boost/uuid/uuid_io.hpp>

#include <sys/capability.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <poll.h>
#include <fcntl.h>
#include <signal.h>
#include "../os/lib_classes.hpp"

using namespace std;
using namespace iconus;
using namespace boost::filesystem;

#include "build/os/header.cxx"
static string header((const char*)header_html, header_html_len);

extern "C" string iconus_getName() {
	return "OS Integration";
}

extern "C" string iconus_initHTML() {
	return header;
}

using Arg = Function::Arg;
constexpr Function::Role INPUT = Function::Role::INPUT;
constexpr Function::Role VARARG = Function::Role::VARARG;
constexpr Function::Role VARFLAG = Function::Role::VARFLAG;

extern "C" void iconus_initGlobalScope(GlobalScope& scope) {
	////////////////////////////
	// functions
	////////////////////////////
	scope.vars["system"] = ClassManagedFunction::create(
			{Arg("name"), Arg("args", VARARG)}, {},
			[](Execution& exe, Scope& scope, auto input, auto& args, auto& varargs, auto& varflags) {
		Object* result;
		exe.session.user.doAsUser([&]() {
			int stdoutLink[2];
			int stderrLink[2];
			int errorLink[2];
			int stdinLink[2];
			pid_t pid;
			int status;

			status = pipe(stdoutLink);
			if (status < 0) {
				throw Error("system: could not open pipe: "+string(strerror(errno)));
			}
			status = pipe(stderrLink);
			if (status < 0) {
				throw Error("system: could not open pipe: "+string(strerror(errno)));
			}
			status = pipe(errorLink);
			if (status < 0) {
				throw Error("system: could not open pipe: "+string(strerror(errno)));
			}
			status = pipe(stdinLink);
			if (status < 0) {
				throw Error("system: could not open pipe: "+string(strerror(errno)));
			}

			pid = fork();
			if (pid == -1) {
				throw Error("system: could not fork: "+string(strerror(errno)));
			} else if (pid == 0) {
				// child: drop all capabilities and run program
				int status;

				cap_t caps = cap_get_proc();
				if (!caps) {
					string errStr = "system: error in initializing capabilities: " + string(strerror(errno));
					write(errorLink[1], (const void*) errStr.c_str(), errStr.size());
					fsync(errorLink[1]);
					exit(1);
				}
				status = cap_clear(caps);
				if (status < 0) {
					string errStr = "system: error in clearing capabilities: " + string(strerror(errno));
					write(errorLink[1], (const void*) errStr.c_str(), errStr.size());
					fsync(errorLink[1]);
					exit(1);
				}
				status = cap_set_proc(caps);
				if (status < 0) {
					string errStr = "system: error in setting capabilities: " + string(strerror(errno));
					write(errorLink[1], (const void*) errStr.c_str(), errStr.size());
					fsync(errorLink[1]);
					exit(1);
				}
				cap_free(caps);

				dup2(stdinLink[0], STDIN_FILENO);
				dup2(stdoutLink[1], STDOUT_FILENO);
				dup2(stderrLink[1], STDERR_FILENO);

				close(stdinLink[0]); close(stdinLink[1]);
			    close(stdoutLink[0]); close(stdoutLink[1]);
			    close(stderrLink[0]); close(stderrLink[1]);
			    close(errorLink[0]);

			    const char* argv[varargs.size()+2];
			    argv[0] = ClassString::value(exe, args["name"]).c_str();
			    int i = 1;
			    for (Object* arg : varargs) {
			    	argv[i] = ClassString::value(exe, arg).c_str();
			    	i++;
			    }
			    argv[varargs.size()+1] = nullptr;

			    execvp(argv[0], (char* const*) argv);

				string errStr = "system: error in running program: " + string(strerror(errno));
				write(errorLink[1], (const void*) errStr.c_str(), errStr.size());
				fsync(errorLink[1]);
			    exit(1);
			} else {
				// parent: wait for child to complete and get output
				close(stdinLink[0]);
				close(stdoutLink[1]);
				close(stderrLink[1]);
				close(errorLink[1]);

				ClassSystemOutput::Instance* output = new ClassSystemOutput::Instance();

				constexpr int readLineEOF = 0;
				constexpr int readLinePartial = 1;
				constexpr int readLineFull = 2;

				const auto readLine = [readLineEOF,readLinePartial,readLineFull](int fd, string& s) {
					int nRead;
					while (true) {
						char c;
						errno = 0;
						nRead = read(fd, &c, 1);

						if (errno == EAGAIN || errno == EWOULDBLOCK) {
							return readLinePartial;
						} else if (nRead <= 0) {
							return readLineEOF;
						} else if (c == '\n') {
							return readLineFull;
						} else {
							s += c;
						}
					}
				};

				fcntl(stdoutLink[0], F_SETFL, fcntl(stdoutLink[0], F_GETFL) | O_NONBLOCK);
				fcntl(stderrLink[0], F_SETFL, fcntl(stderrLink[0], F_GETFL) | O_NONBLOCK);

				result = ClassSystemOutput::create(output);
				thread outputThread([=,&exe]() {
					int retCode, status;
					string outS{};
					string errS{};

					const int nFds = 3;
					struct pollfd fds[nFds] {
						{stdoutLink[0], POLLIN, 0},
						{stderrLink[0], POLLIN, 0},
						{errorLink[0], POLLIN, 0},
					};

					Map<string,string> inputMap;
					while (!exe.session.closed && !exe.completed) this_thread::yield();

					exe.getMessage(output->id, inputMap);
					while (true) {
						status = poll(fds, nFds, 0);

						if (exe.session.closed) {
							kill(pid, SIGKILL);
							return;
						}

						if (!inputMap.empty()) {
							auto doKill = inputMap.find("kill");
							if (doKill != inputMap.end()) {
								kill(pid, SIGKILL);
							} else {
								string& s = inputMap["input"];
								write(stdinLink[1], (const void*) s.c_str(), s.size());

								inputMap.clear();
								exe.getMessage(output->id, inputMap);
							}
						}

						if (status < 0) continue;

						if (fds[0].revents & POLLIN) { // stdoutLink
							Lock lock{result->mutex};
							int readLineRet;
							do {
								readLineRet = readLine(stdoutLink[0], outS);
								if (readLineRet != readLinePartial) {
									output->lines.emplace_back(false, outS);
									outS = "";

									Map<string,string> message{{"line",to_string(output->lines.size()-1)}, {"text", output->lines.back().text}};
									exe.sendMessage(output->id, message);
								}
							} while (readLineRet == readLineFull);
						} else if (fds[1].revents & POLLIN) { // stderrLink
							Lock lock{result->mutex};
							int readLineRet;
							do {
								readLineRet = readLine(stderrLink[0], errS);
								if (readLineRet != readLinePartial) {
									output->lines.emplace_back(true, errS);
									errS = "";

									Map<string,string> message{{"line",to_string(output->lines.size()-1)}, {"text", output->lines.back().text}, {"stderr", "true"}};
									exe.sendMessage(output->id, message);
								}
							} while (readLineRet == readLineFull);
						} else if (fds[2].revents & POLLIN) { // errorLink
							Lock lock{result->mutex};
							string s;
							int readLineRet;
							do {
								readLineRet = readLine(errorLink[0], s);
								if (readLineRet != readLinePartial) {
									Map<string,string> message{{"error", escapeHTML(s)}};
									exe.sendMessage(output->id, message);
									return;
								}
							} while (true);
						} else {
							pid_t isDone = waitpid(pid, &retCode, WNOHANG);
							if (isDone > 0) break;
						}
					}

					Lock lock{result->mutex};

					output->retCode = retCode;
					output->done = true;

					Map<string,string> message{{"done","true"}, {"code", to_string(retCode)}};
					exe.sendMessage(output->id, message);
				});
				outputThread.detach();
			}
		});
		return result;
			}
	);

	////////////////////////////
	// constants
	////////////////////////////
	scope.vars["<system-output>"] = ClassClass::create(&ClassSystemOutput::INSTANCE);

	scope.vars["ENV"] = ClassSpecialMap::create([](Execution& exe, Scope& scope, Object* input, auto& out) {
		exe.session.user.doAsUser([&]() {
			for (char** envp = environ; *envp; envp++) {
				string pair{*envp};
				size_t i = pair.find('=');
				if (i != string::npos) {
					out.emplace_back(ClassString::create(pair.substr(0, i)));
				}
			}
		});
	}, [](Execution& exe, Scope& scope, Object* input, Object* name) {
		const char* v;
		exe.session.user.doAsUser([&]() {
			string s = name->toString(exe);
			v = getenv(s.c_str());
		});
		return v ? ClassString::create(string(v)) : &ClassNil::NIL;
	}, [](Execution& exe, Scope& scope, Object* input, Object* name) {
		return true;
	}, [](Execution& exe, Scope& scope, Object* input, Object* name, Object* value) {
		exe.session.user.doAsUser([&]() {
			setenv(name->toString(exe).c_str(), value->toString(exe).c_str(), true);
		});
	});
}

extern "C" void iconus_initSession(Execution& exe) {
	////////////////////////////
	// renderers
	////////////////////////////
	exe.session.renderers.emplace_back("system output", [](Execution& exe, Object* ob) {
			return ob->clazz == &ClassSystemOutput::INSTANCE;
		}, [](Execution& exe, Object* ob) {
			Lock lock{ob->mutex};
			ClassSystemOutput::Instance& value = ClassSystemOutput::value(exe, ob);
			exe.idsRendered.insert(&value.id);

			ostringstream sb;
			sb << "
<img src onerror=\"onSystemOutputLoad('" << to_string(value.id) << "', this)\">
";

			for (const auto& line : value.lines) {
				sb << "<div" << (line.isErr ? " style=\"color: red;\"" : "") << ">" << escapeHTML(line.text) << endl << "
";
			}

			sb << "
";

			if (value.done) {
				sb << "(exited with code ";
				sb << value.retCode;
				sb << ")";
			} else {
				sb << "
";
				sb << "";
				sb << "<input type=\"text\" id=\"systemInput\" />";
				sb << "<button type=\"button\" id=\"sysOutKill\" onclick=\"onSystemOutputKill('" << to_string(value.id) << "')\">Kill</button>";
				sb << "
";
			}

			sb << "
";
			return sb.str();
	});
}


text:
#ifndef SHIFT_RENDER_VK_LAYER1_SWAPCHAIN_HPP
#define SHIFT_RENDER_VK_LAYER1_SWAPCHAIN_HPP

#include <boost/intrusive_ptr.hpp>
#include "shift/render/vk/shared.hpp"
#include "shift/render/vk/smart_ptr.hpp"
#include "shift/render/vk/layer1/semaphore.hpp"

namespace shift::render::vk::layer1
{
class instance;
class device;
class surface;
class image;

class swapchain
{
public:
  /// Default constructor.
  swapchain() = default;

  /// Constructor.
  swapchain(vk::layer1::device& device, vk::layer1::surface& surface,
            vk::extent_2d extent,
            std::uint32_t desired_number_of_swapchain_images,
            vk::layer1::swapchain* old_swapchain);

  swapchain(const swapchain&) = delete;

  /// Move constructor.
  swapchain(swapchain&& other) noexcept;

  /// Destructor.
  ~swapchain();

  swapchain& operator=(const swapchain&) = delete;

  /// Move assignment operator.
  swapchain& operator=(swapchain&& other) noexcept;

  ///
  vk::format surface_format() const noexcept;

  ///
  VkSwapchainKHR& handle() noexcept
  {
    return _swapchain;
  }

  ///
  const VkSwapchainKHR& handle() const noexcept
  {
    return _swapchain;
  }

  ///
  vk::extent_2d extent() const
  {
    return _extent;
  }

  ///
  std::uint32_t image_count() const;

  ///
  std::tuple<vk::result, std::uint32_t, VkSemaphore> acquire_next_image(
    std::uint64_t timeout, VkFence fence);

  ///
  vk::shared_ptr<vk::layer1::image> image(std::uint32_t swapchain_index) const;

private:
  vk::layer1::device* _device = nullptr;
  vk::layer1::surface* _surface = nullptr;
  VkSwapchainKHR _swapchain = nullptr;
  vk::extent_2d _extent;
  std::uint32_t _image_count = 0;
  std::uint32_t _semaphore_index = 0;
  vk::multi_buffered<VkImage> _image_handles = {nullptr, nullptr};
  vk::multi_buffered<vk::layer1::semaphore> _present_complete_semaphores;
};
}

#endif

ext: hpp

max_stars_repo_name: cspanier/shift

max_issues_repo_name: cspanier/shift

max_forks_repo_name: cspanier/shift


text:
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2013.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_IS_PAIR_HPP
#define BOOST_CONTAINER_CONTAINER_DETAIL_IS_PAIR_HPP

#ifndef BOOST_CONFIG_HPP
#  include <boost/config.hpp>
#endif

#if defined(BOOST_HAS_PRAGMA_ONCE)
#  pragma once
#endif

#include <boost/container/detail/config_begin.hpp>
#include <boost/container/detail/workaround.hpp>
#include <boost/container/detail/std_fwd.hpp>

#if defined(BOOST_MSVC) && (_CPPLIB_VER == 520)
//MSVC 2010 tuple marker
namespace std { namespace tr1 { struct _Nil; }}
#elif defined(BOOST_MSVC) && (_CPPLIB_VER == 540)
//MSVC 2012 tuple marker
namespace std { struct _Nil; }
#endif

namespace boost {
namespace tuples {

struct null_type;

template <
  class T0, class T1, class T2,
  class T3, class T4, class T5,
  class T6, class T7, class T8,
  class T9>
class tuple;

}  //namespace tuples {
}  //namespace boost {

namespace boost {
namespace container {

struct try_emplace_t{};

namespace dtl {

template <class T1, class T2>
struct pair;

template <class T>
struct is_pair
{
   static const bool value = false;
};

template <class T1, class T2>
struct is_pair< pair<T1, T2> >
{
   static const bool value = true;
};

template <class T1, class T2>
struct is_pair< std::pair<T1, T2> >
{
   static const bool value = true;
};

template <class T>
struct is_not_pair
{
   static const bool value = !is_pair<T>::value;
};

}  //namespace dtl {
}  //namespace container {
}  //namespace boost {

#include <boost/container/detail/config_end.hpp>

#endif   //#ifndef BOOST_CONTAINER_CONTAINER_DETAIL_IS_PAIR_HPP


text:
//
// Copyright (c) 2016-2019 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/beast
//

#include <boost/beast/core/buffers_range.hpp>
#include <boost/beast/core/flat_buffer.hpp>
#include <boost/beast/core/multi_buffer.hpp>
#include <boost/beast/core/read_size.hpp>
#include <boost/beast/core/string.hpp>
#include <boost/beast/_experimental/unit_test/suite.hpp>
#include <boost/asio/streambuf.hpp>
#include <algorithm>
#include <chrono>
#include <cstdlib>
#include <iomanip>
#include <utility>
#include <vector>

namespace boost {
namespace beast {

class buffers_test : public beast::unit_test::suite
{
public:
    using size_type = std::uint64_t;

    class timer
    {
        using clock_type =
            std::chrono::system_clock;

        clock_type::time_point when_;

    public:
        using duration =
            clock_type::duration;

        timer()
            : when_(clock_type::now())
        {
        }

        duration
        elapsed() const
        {
            return clock_type::now() - when_;
        }
    };

    inline
    size_type
    throughput(std::chrono::duration<
        double> const& elapsed, size_type items)
    {
        using namespace std::chrono;
        return static_cast<size_type>(
            1 / (elapsed/items).count());
    }

    template<class MutableBufferSequence>
    static
    std::size_t
    fill(MutableBufferSequence const& buffers)
    {
        std::size_t n = 0;
        for(auto b : beast::buffers_range_ref(buffers))
        {
            std::fill(
                static_cast<char*>(b.data()),
                static_cast<char*>(b.data()) +
                    b.size(), '\0');
            n += b.size();
        }
        return n;
    }

    template<class DynamicBuffer>
    size_type
    do_prepares(std::size_t repeat,
        std::size_t count, std::size_t size)
    {
        timer t;
        size_type total = 0;
        for(auto i = repeat; i--;)
        {
            DynamicBuffer b;
            for(auto j = count; j--;)
            {
                auto const n = fill(b.prepare(size));
                b.commit(n);
                total += n;
            }
        }
        return throughput(t.elapsed(), total);
    }

    template<class DynamicBuffer>
    size_type
    do_hints(std::size_t repeat,
        std::size_t count, std::size_t size)
    {
        timer t;
        size_type total = 0;
        for(auto i = repeat; i--;)
        {
            DynamicBuffer b;
            for(auto j = count; j--;)
            {
                for(auto remain = size; remain;)
                {
                    auto const n = fill(b.prepare(
                        read_size(b, remain)));
                    b.commit(n);
                    remain -= n;
                    total += n;
                }
            }
        }
        return throughput(t.elapsed(), total);
    }

    template<class DynamicBuffer>
    size_type
    do_random(std::size_t repeat,
        std::size_t count, std::size_t size)
    {
        timer t;
        size_type total = 0;
        for(auto i = repeat; i--;)
        {
            DynamicBuffer b;
            for(auto j = count; j--;)
            {
                auto const n = fill(b.prepare(
                    1 + (rand()%(2*size))));
                b.commit(n);
                total += n;
            }
        }
        return throughput(t.elapsed(), total);
    }

    static
    inline
    void
    do_trials_1(bool)
    {
    }

    template<class F0, class... FN>
    void
    do_trials_1(bool print, F0&& f, FN... fn)
    {
        timer t;
        using namespace std::chrono;
        static size_type constexpr den = 1024 * 1024;
        if(print)
        {
            log << std::right << std::setw(10) <<
                ((f() + (den / 2)) / den) << " MB/s";
            log.flush();
        }
        else
        {
            f();
        }
        do_trials_1(print, fn...);
    }

    template<class F0, class... FN>
    void
    do_trials(string_view name,
        std::size_t trials, F0&& f0, FN... fn)
    {
        using namespace std::chrono;
        // warm-up
        do_trials_1(false, f0, fn...);
        do_trials_1(false, f0, fn...);
        while(trials--)
        {
            timer t;
            log << std::left << std::setw(24) << name << ":";
            log.flush();
            do_trials_1(true, f0, fn...);
            log << "   " <<
                duration_cast<milliseconds>(t.elapsed()).count() << "ms";
            log << std::endl;
        }
    }

    void
    run() override
    {
        static std::size_t constexpr trials = 1;
        static std::size_t constexpr repeat = 250;
        std::vector<std::pair<std::size_t, std::size_t>> params;
        params.emplace_back(1024, 1024);
        params.emplace_back(512, 4096);
        params.emplace_back(256, 32768);
        log << std::endl;
        for(auto const& param : params)
        {
            auto const count = param.first;
            auto const size = param.second;
            auto const s = std::string("count=") + std::to_string(count) +
                ", size=" + std::to_string(size);
            log << std::left << std::setw(24) << s << " " <<
                std::right << std::setw(15) << "prepare" <<
                std::right << std::setw(15) << "with hint" <<
                std::right << std::setw(15) << "random" <<
                std::endl;
            do_trials("multi_buffer", trials,
                 [&](){ return do_prepares<multi_buffer>(repeat, count, size); }
                ,[&](){ return do_hints   <multi_buffer>(repeat, count, size); }
                ,[&](){ return do_random  <multi_buffer>(repeat, count, size); }
            );
            do_trials("flat_buffer", trials,
                 [&](){ return do_prepares<flat_buffer>(repeat, count, size); }
                ,[&](){ return do_hints   <flat_buffer>(repeat, count, size); }
                ,[&](){ return do_random  <flat_buffer>(repeat, count, size); }
            );
            do_trials("net::streambuf", trials,
                 [&](){ return do_prepares<net::streambuf>(repeat, count, size); }
                ,[&](){ return do_hints   <net::streambuf>(repeat, count, size); }
                ,[&](){ return do_random  <net::streambuf>(repeat, count, size); }
            );
            log << std::endl;
        }
        pass();
    }
};

BEAST_DEFINE_TESTSUITE(beast,benchmarks,buffers);

} // beast
} // boost


text:
/*=============================================================================
    Copyright (c) 2001-2003 Daniel Nuffer
    Copyright (c) 2001-2003 Hartmut Kaiser
    http://spirit.sourceforge.net/

    Use, modification and distribution is subject to the Boost Software
    License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt)
=============================================================================*/
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_assign_actor.hpp>
#include <boost/spirit/include/classic_escape_char.hpp>

#include <iostream>
#include <boost/detail/lightweight_test.hpp>
#include <cstdio>       // for sprintf

#if !defined(BOOST_NO_CWCHAR) && !defined(BOOST_NO_SWPRINTF)
# include <cwchar>      // for swprintf
#endif

///////////////////////////////////////////////////////////////////////////////
using namespace std;
using namespace BOOST_SPIRIT_CLASSIC_NS;

///////////////////////////////////////////////////////////////////////////////
int
main()
{
    char c;

    // testing good C escapes
    BOOST_TEST(parse("a", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == 'a');
    BOOST_TEST(parse("\\b", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\b');
    BOOST_TEST(parse("\\t", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\t');
    BOOST_TEST(parse("\\n", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\n');
    BOOST_TEST(parse("\\f", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\f');
    BOOST_TEST(parse("\\r", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\r');
    BOOST_TEST(parse("\\\"", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\"');
    BOOST_TEST(parse("\\'", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\'');
    BOOST_TEST(parse("\\\\", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\\');
    BOOST_TEST(parse("\\120", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\120');
    BOOST_TEST(parse("\\x2e", c_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\x2e');

    // test bad C escapes
    BOOST_TEST(!parse("\\z", c_escape_ch_p[assign_a(c)]).hit);

    // testing good lex escapes
    BOOST_TEST(parse("a", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == 'a');
    BOOST_TEST(parse("\\b", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\b');
    BOOST_TEST(parse("\\t", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\t');
    BOOST_TEST(parse("\\n", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\n');
    BOOST_TEST(parse("\\f", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\f');
    BOOST_TEST(parse("\\r", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\r');
    BOOST_TEST(parse("\\\"", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\"');
    BOOST_TEST(parse("\\'", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\'');
    BOOST_TEST(parse("\\\\", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\\');
    BOOST_TEST(parse("\\120", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\120');
    BOOST_TEST(parse("\\x2e", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\x2e');
    BOOST_TEST(parse("\\z", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == 'z');
    BOOST_TEST(parse("\\a", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == 'a');

    // test bad lex escapes
    BOOST_TEST(!parse("\\xz", lex_escape_ch_p[assign_a(c)]).hit);

    // test out of range octal escape
    BOOST_TEST(!parse("\\777", lex_escape_ch_p[assign_a(c)]).hit);

#if CHAR_MAX == 127
    BOOST_TEST(!parse("\\200", lex_escape_ch_p[assign_a(c)]).hit);

    BOOST_TEST(parse("\\177", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\177');
#elif CHAR_MAX == 255
    BOOST_TEST(!parse("\\400", lex_escape_ch_p[assign_a(c)]).hit);

    BOOST_TEST(parse("\\377", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\377');
#endif

    // test out of range hex escape
    BOOST_TEST(!parse("\\xFFF", lex_escape_ch_p[assign_a(c)]).hit);

#if CHAR_MAX == 127
    BOOST_TEST(!parse("\\X80", lex_escape_ch_p[assign_a(c)]).hit);

    BOOST_TEST(parse("\\X7F", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\x7f');
#elif CHAR_MAX == 255
    BOOST_TEST(!parse("\\X100", lex_escape_ch_p[assign_a(c)]).hit);

    BOOST_TEST(parse("\\XFf", lex_escape_ch_p[assign_a(c)]).full);
    BOOST_TEST(c == '\xff');
#endif

#ifndef BOOST_NO_CWCHAR

    // test wide chars
    typedef escape_char_parser<lex_escapes, wchar_t> wlep_t;
    wlep_t wlep = wlep_t();

    typedef escape_char_parser<c_escapes, wchar_t> wcep_t;
    wcep_t wcep = wcep_t();

    //wchar_t const* wstr = L"a\\b\\t\\n\\f\\r\\\"\\'\\\\\\120\\x2e";
    //wchar_t const* wend(wstr + wcslen(wstr));

    wchar_t wc;
    BOOST_TEST(parse(L"a", wcep[assign_a(wc)]).hit);
    BOOST_TEST(wc == L'a');
    BOOST_TEST(parse(L"\\b", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\b');
    BOOST_TEST(parse(L"\\t", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\t');
    BOOST_TEST(parse(L"\\n", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\n');
    BOOST_TEST(parse(L"\\f", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\f');
    BOOST_TEST(parse(L"\\r", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\r');
    BOOST_TEST(parse(L"\\\"", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\"');
    BOOST_TEST(parse(L"\\'", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\'');
    BOOST_TEST(parse(L"\\\\", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\\');
    BOOST_TEST(parse(L"\\120", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\120');
    BOOST_TEST(parse(L"\\x2e", wcep[assign_a(wc)]).full);
    BOOST_TEST(wc == L'\x2e');

    // test bad wc escapes
    BOOST_TEST(!parse(L"\\z", wcep[assign_a(wc)]).hit);

    // test out of range octal escape
    size_t const octmax_size = 16;
    wchar_t octmax[octmax_size];

#if !defined(BOOST_NO_SWPRINTF)
    swprintf(octmax, octmax_size,
      L"\\%lo", (unsigned long)(std::numeric_limits<wchar_t>::max)());
    BOOST_TEST(parse(octmax, wlep[assign_a(wc)]).full);
    //BOOST_TEST(lex_escape_ch_p[assign_a(wc)].parse(str, end));
    BOOST_TEST(wc == (std::numeric_limits<wchar_t>::max)());

    swprintf(octmax, octmax_size,
      L"\\%lo", (unsigned long)(std::numeric_limits<wchar_t>::max)() + 1);
    BOOST_TEST(!parse(octmax, wlep[assign_a(wc)]).hit);

    // test out of range hex escape
    size_t const hexmax_size = 16;
    wchar_t hexmax[hexmax_size];

    swprintf(hexmax, hexmax_size,
      L"\\x%lx", (unsigned long)(std::numeric_limits<wchar_t>::max)());
    BOOST_TEST(parse(hexmax, wlep[assign_a(wc)]).full);
    BOOST_TEST(wc == (std::numeric_limits<wchar_t>::max)());

    swprintf(hexmax, hexmax_size,
      L"\\x%lx", (unsigned long)(std::numeric_limits<wchar_t>::max)() + 1);
    BOOST_TEST(!parse(hexmax, wlep[assign_a(wc)]).hit);
#endif // !defined(BOOST_NO_SWPRINTF)

#endif

    return boost::report_errors();
}

max_stars_repo_name: randolphwong/mcsema

max_issues_repo_name: randolphwong/mcsema

max_forks_repo_name: randolphwong/mcsema


text: #include <boost/proto/transform/call.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
//  (C) Copyright Raffi Enficiaud 2018.
//  Distributed under the Boost Software License, Version 1.0.
//  (See accompanying file LICENSE_1_0.txt or copy at
//  http://www.boost.org/LICENSE_1_0.txt)

//  See http://www.boost.org/libs/test for the library home page.
//
//! @file
//! Allowing for suites with same name, ticket trac #12597
// *****************************************************************************

#define BOOST_TEST_MODULE test_clashing_names_suites_ok
#include <boost/test/unit_test.hpp>

BOOST_AUTO_TEST_SUITE( dummy_suite )
BOOST_AUTO_TEST_CASE( ts1 )
{
    BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()

BOOST_AUTO_TEST_SUITE( dummy_suite )
BOOST_AUTO_TEST_CASE( ts2 )
{
    BOOST_CHECK(true);
}
BOOST_AUTO_TEST_SUITE_END()

max_stars_repo_name: Jackarain/tinyrpc

max_issues_repo_name: avplayer/cxxrpc

max_forks_repo_name: avplayer/cxxrpc


text:
#include <boost/python.hpp>
#include <boost/cstdint.hpp>

#include <Magick++/Drawable.h>
#include <Magick++.h>

using namespace boost::python;

namespace  {

struct Magick_DrawableStrokeLineJoin_Wrapper: Magick::DrawableStrokeLineJoin
{
    Magick_DrawableStrokeLineJoin_Wrapper(PyObject* py_self_, Magick::LineJoin p0):
        Magick::DrawableStrokeLineJoin(p0), py_self(py_self_) {}

    PyObject* py_self;
};

}

void __DrawableStrokeLineJoin()
{
    class_< Magick::DrawableStrokeLineJoin, bases<Magick::DrawableBase>, boost::noncopyable, Magick_DrawableStrokeLineJoin_Wrapper >("DrawableStrokeLineJoin", init< Magick::LineJoin >())
        .def("linejoin", (void (Magick::DrawableStrokeLineJoin::*)(Magick::LineJoin) )&Magick::DrawableStrokeLineJoin::linejoin)
        .def("linejoin", (Magick::LineJoin (Magick::DrawableStrokeLineJoin::*)() const)&Magick::DrawableStrokeLineJoin::linejoin)
    ;
}

max_stars_repo_name: veryhappythings/pgmagick

max_issues_repo_name: veryhappythings/pgmagick

max_forks_repo_name: veryhappythings/pgmagick


text:
///////////////////////////////////////////////////////////////////////////////
// save_restore.hpp
//
//  Copyright 2008 Eric Niebler. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file
//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005
#define BOOST_XPRESSIVE_DETAIL_UTILITY_SAVE_RESTORE_HPP_EAN_10_04_2005

// MS compatible compilers support #pragma once
#if defined(_MSC_VER) && (_MSC_VER >= 1020)
# pragma once
#endif

#include <boost/noncopyable.hpp>

namespace boost { namespace xpressive { namespace detail
{

    template<typename T>
    struct save_restore
      : private noncopyable
    {
        explicit save_restore(T &t)
          : ref(t)
          , val(t)
        {
        }

        save_restore(T &t, T const &n)
          : ref(t)
          , val(t)
        {
            this->ref = n;
        }

        ~save_restore()
        {
            this->ref = this->val;
        }

        void restore()
        {
            this->ref = this->val;
        }

    private:
        T &ref;
        T const val;
    };

}}}

#endif