<commit_before>// Virvo - Virtual Reality Volume Rendering
// Copyright (C) 1999-2003 University of Stuttgart, 2004-2005 Brown University
// Contact: Jurgen P. Schulze, jschulze@ucsd.edu
//
// This file is part of Virvo.
//
// Virvo 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 (see license.txt); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#include "vvcompress.h"
#include "vvcompressedvector.h"

#ifdef HAVE_CONFIG_H
#include "vvconfig.h"
#endif

#ifdef HAVE_PNG

#include <assert.h>
#include <memory.h>
#include <png.h>

#ifdef _MSC_VER
#pragma warning(disable: 4324) // structure was padded due to __declspec(align())
#pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
#endif

namespace
{

static void PNGErrorCallback(png_structp png_ptr, png_const_charp msg)
{
    fprintf(stderr, "PNG error: \"%s\"\n", msg);

    longjmp(png_jmpbuf(png_ptr), 1);
}

static void PNGWarningCallback(png_structp /*png_ptr*/, png_const_charp /*msg*/)
{
}

struct PNGIO
{
    std::vector<unsigned char>& buffer;
    std::size_t start;

    inline PNGIO(std::vector<unsigned char>& buffer)
        : buffer(buffer)
        , start(0)
    {
    }
};

struct PNGWriteContext
{
    png_structp png;
    png_infop info;

    inline PNGWriteContext()
        : png(0)
        , info(0)
    {
    }

    inline ~PNGWriteContext()
    {
        png_destroy_write_struct(&png, &info);
    }
};

static void PNGWriteFunc(png_structp png, png_bytep data, png_size_t len)
{
    PNGIO* out = (PNGIO*)png_get_io_ptr(png);

    out->buffer.reserve(out->buffer.size() + len);
    out->buffer.insert(out->buffer.end(), data, data + len);
}

struct PNGReadContext
{
    png_structp png;
    png_infop info;

    inline PNGReadContext() : png(0), info(0)
    {
    }

    inline ~PNGReadContext()
    {
        png_destroy_read_struct(&png, &info, 0);
    }
};

static void PNGReadFunc(png_structp png, png_bytep data, png_size_t len)
{
    PNGIO* in = (PNGIO*)png_get_io_ptr(png);

    // Read some bytes
    memcpy(data, &in->buffer[in->start], len);

    // Offset the pointer
    in->start += len;
}

static int PNGMapBitDepth(virvo::PixelFormatInfo const& info)
{
    // Components must all have the same size in bits.
    // NOTE: Might not catch all invalid image formats...
    if ((info.size % info.components) != 0)
        return -1;

    int bit_depth = 8 * info.size / info.components;

    // Bit depth larger than 16 are not handled by libpng
    if (bit_depth > 16)
        return -1;

    return bit_depth;
}

static int PNGMapColorType(virvo::PixelFormatInfo const& info)
{
    switch (info.components)
    {
    case 1:
        return PNG_COLOR_TYPE_GRAY;
    case 2:
        return PNG_COLOR_TYPE_GRAY_ALPHA;
    case 3:
        return PNG_COLOR_TYPE_RGB;
    case 4:
        return PNG_COLOR_TYPE_RGB_ALPHA;
    }

    return -1; // Not handling paletted images...
}

static bool PNGGetImageInfo(virvo::PixelFormat format, int& bit_depth, int& color_type)
{
    virvo::PixelFormatInfo info = mapPixelFormat(format);

    // Get the size in bits of each component
    bit_depth = PNGMapBitDepth(info);

    // Get the color type
    color_type = PNGMapColorType(info);

    return bit_depth > 0 && color_type >= 0;
}

} // namespace

bool virvo::encodePNG(std::vector<unsigned char>& data, PNGOptions const& options)
{
    int bit_depth   = 0;
    int color_type  = 0;

    // Check if its possible to encode the image...
    if (!PNGGetImageInfo(options.format, bit_depth, color_type))
        return false;

    PNGWriteContext context;

    // Allocate and initialize png_ptr struct for writing, and any other memory
    context.png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, PNGErrorCallback, PNGWarningCallback);

    if (context.png == 0)
        return false;

    // Allocate and initialize the info structure
    context.info = png_create_info_struct(context.png);

    if (context.info == 0)
        return false;

    std::vector<unsigned char> compressed;

    PNGIO out(compressed);

    // Set error handling.
    if (setjmp(png_jmpbuf(context.png)))
        return false;

    // Replace the default data output functions with a user supplied one(s).
    // If buffered output is not used, then output_flush_fn can be set to NULL.
    // If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
    // output_flush_fn will be ignored (and thus can be NULL).
    png_set_write_fn(context.png, reinterpret_cast<void*>(&out), PNGWriteFunc, 0);

    // Set the library compression level.
    //
    // Currently, valid values range from 0 - 9, corresponding directly to the zlib compression
    // levels 0 - 9 (0 - no compression, 9 - "maximal" compression).
    // Note that tests have shown that zlib compression levels 3-6 usually perform as well as
    // level 9 for PNG images, and do considerably fewer caclulations. In the future,
    // these values may not correspond directly to the zlib compression levels.
    png_set_compression_level(context.png, options.compression_level);

    // Set the image information here.
    png_set_IHDR(context.png, context.info, options.w, options.h, bit_depth, color_type,
        PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

    // TODO:
    // png_set_sBIT(...)

    // TODO:
    // png_set_gAMA(...)

    // TODO:
    // png_set_bKGD(...)

    // Writes all the PNG information before the image.
    png_write_info_before_PLTE(context.png, context.info);

    // Write the image data
    for (int y = 0; y < options.h; y++)
    {
        png_bytep row_ptr = &data[y * options.pitch];
        png_write_rows(context.png, &row_ptr, 1);
    }

    png_write_end(context.png, context.info);

    // Update the data
    data.swap(compressed);

    return true;
}

bool virvo::decodePNG(std::vector<unsigned char>& data, PNGOptions& options)
{
    PNGReadContext context;

    // Create and initialize the png_struct with the desired error handler
    // functions.  If you want to use the default stderr and longjump method,
    // you can supply NULL for the last three parameters.  We also supply the
    // the compiler header file version, so that we know if the application
    // was compiled with a compatible version of the library.
    context.png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0/*user-data*/, PNGErrorCallback, PNGWarningCallback);

    if (context.png == 0)
        return false;

    // Allocate/initialize the memory for image information.
    context.info = png_create_info_struct(context.png);

    if (context.info == 0)
        return false;

    // Create the output buffer
    std::vector<unsigned char> uncompressed;

    // Create a wrapper for the input buffer
    PNGIO in(data);

    // Set error handling if you are using the setjmp/longjmp method (this is
    // the normal method of doing things with libpng).  REQUIRED unless you
    // set up your own error handlers in the png_create_read_struct() earlier.
    if (setjmp(png_jmpbuf(context.png)))
        return false;

    // Set the read function
    png_set_read_fn(context.png, (void*)&in, PNGReadFunc);

    // The call to png_read_info() gives us all of the information from the
    // PNG file before the first IDAT (image data chunk).
    png_read_info(context.png, context.info);

    png_uint_32 w = 0;
    png_uint_32 h = 0;
    int bit_depth = 0;
    int color_type = 0;

    png_get_IHDR(context.png, context.info, &w, &h, &bit_depth, &color_type, 0, 0, 0);

    //
    // TODO:
    // Check against the values given in the options or simply modify the options???
    //

    //
    // From here down we are concerned with colortables and pixels
    //
    // Expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
    // transparency chunks to alpha channel; strip 16-bit-per-sample
    // images to 8 bits per sample; and convert grayscale to RGB[A]
    //

    // paletted images are expanded to RGB
    if (color_type == PNG_COLOR_TYPE_PALETTE)
    {
        png_set_expand(context.png);
    }

    // grayscale images of bit-depth less than 8 are expanded
    // to 8-bit images and tRNS chunks are expanded to alpha channels
    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
    {
        png_set_expand(context.png);
    }

    // expand transparency chunks to alpha channel
    if (png_get_valid(context.png, context.info, PNG_INFO_tRNS))
    {
        png_set_tRNS_to_alpha(context.png);
    }

    // TODO:
    // png_set_strip_16

    // TODO:
    // png_set_gray_to_rgb

    // TODO:
    // png_set_bgr

    // TODO:
    // png_[s,g]et_gAMA

    // TODO:
    // png_[s,g]et_bKGD

    //
    // After the transformations have been registered update png_info_ptr data
    // Get again width, height and channels
    //

    png_read_update_info(context.png, context.info);

    w           = png_get_image_width(context.png, context.info);
    h           = png_get_image_height(context.png, context.info);
    bit_depth   = png_get_bit_depth(context.png, context.info);
    color_type  = png_get_color_type(context.png, context.info);

    //
    // TODO:
    // - Check for correct image dimension/format...
    // - Store the correct pixel format in options...
    //

    assert( options.w >= 0 && static_cast<png_uint_32>(options.w) == w );
    assert( options.h >= 0 && static_cast<png_uint_32>(options.h) == h );

    // Create the image buffer
    uncompressed.resize(options.pitch * options.h);

    // Read the image
    for (int y = 0; y < options.h; y++)
    {
        png_bytep row = &uncompressed[y * options.pitch];
        png_read_rows(context.png, &row, &row, 1);
    }

    png_read_end(context.png, context.info);

    // Update the image data.
    data.swap(uncompressed);

    return true;
}

#else // HAVE_PNG

bool virvo::encodePNG(std::vector<unsigned char>& /*data*/, PNGOptions const& /*options*/)
{
    return false;
}

bool virvo::decodePNG(std::vector<unsigned char>& /*data*/, PNGOptions& /*options*/)
{
    return false;
}

#endif // !HAVE_PNG

bool virvo::encodePNG(CompressedVector& data, PNGOptions const& options)
{
    if (data.getCompressionType() != Compress_None)
        return false;

    if (encodePNG(data.vector(), options))
    {
        data.setCompressionType(Compress_PNG);
        return true;
    }

    return false;
}

bool virvo::decodePNG(CompressedVector& data, PNGOptions& options)
{
    if (data.getCompressionType() != Compress_PNG)
        return false;

    if (decodePNG(data.vector(), options))
    {
        data.setCompressionType(Compress_None);
        return true;
    }

    return false;
}
<commit_msg>Disable -Wclobbered for PNG de-/compression methods<commit_after>// Virvo - Virtual Reality Volume Rendering
// Copyright (C) 1999-2003 University of Stuttgart, 2004-2005 Brown University
// Contact: Jurgen P. Schulze, jschulze@ucsd.edu
//
// This file is part of Virvo.
//
// Virvo 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 (see license.txt); if not, write to the
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#include "vvcompress.h"
#include "vvcompressedvector.h"

#ifdef HAVE_CONFIG_H
#include "vvconfig.h"
#endif

#ifdef HAVE_PNG

#include <assert.h>
#include <memory.h>
#include <png.h>

#ifdef _MSC_VER
#pragma warning(disable: 4324) // structure was padded due to __declspec(align())
#pragma warning(disable: 4611) // interaction between '_setjmp' and C++ object destruction is non-portable
#endif

#ifdef __GNUC__
#pragma GCC diagnostic ignored "-Wclobbered"
#endif

namespace
{

static void PNGErrorCallback(png_structp png_ptr, png_const_charp msg)
{
    fprintf(stderr, "PNG error: \"%s\"\n", msg);

    longjmp(png_jmpbuf(png_ptr), 1);
}

static void PNGWarningCallback(png_structp /*png_ptr*/, png_const_charp /*msg*/)
{
}

struct PNGIO
{
    std::vector<unsigned char>& buffer;
    std::size_t start;

    inline PNGIO(std::vector<unsigned char>& buffer)
        : buffer(buffer)
        , start(0)
    {
    }
};

struct PNGWriteContext
{
    png_structp png;
    png_infop info;

    inline PNGWriteContext()
        : png(0)
        , info(0)
    {
    }

    inline ~PNGWriteContext()
    {
        png_destroy_write_struct(&png, &info);
    }
};

static void PNGWriteFunc(png_structp png, png_bytep data, png_size_t len)
{
    PNGIO* out = (PNGIO*)png_get_io_ptr(png);

    out->buffer.reserve(out->buffer.size() + len);
    out->buffer.insert(out->buffer.end(), data, data + len);
}

struct PNGReadContext
{
    png_structp png;
    png_infop info;

    inline PNGReadContext() : png(0), info(0)
    {
    }

    inline ~PNGReadContext()
    {
        png_destroy_read_struct(&png, &info, 0);
    }
};

static void PNGReadFunc(png_structp png, png_bytep data, png_size_t len)
{
    PNGIO* in = (PNGIO*)png_get_io_ptr(png);

    // Read some bytes
    memcpy(data, &in->buffer[in->start], len);

    // Offset the pointer
    in->start += len;
}

static int PNGMapBitDepth(virvo::PixelFormatInfo const& info)
{
    // Components must all have the same size in bits.
    // NOTE: Might not catch all invalid image formats...
    if ((info.size % info.components) != 0)
        return -1;

    int bit_depth = 8 * info.size / info.components;

    // Bit depth larger than 16 are not handled by libpng
    if (bit_depth > 16)
        return -1;

    return bit_depth;
}

static int PNGMapColorType(virvo::PixelFormatInfo const& info)
{
    switch (info.components)
    {
    case 1:
        return PNG_COLOR_TYPE_GRAY;
    case 2:
        return PNG_COLOR_TYPE_GRAY_ALPHA;
    case 3:
        return PNG_COLOR_TYPE_RGB;
    case 4:
        return PNG_COLOR_TYPE_RGB_ALPHA;
    }

    return -1; // Not handling paletted images...
}

static bool PNGGetImageInfo(virvo::PixelFormat format, int& bit_depth, int& color_type)
{
    virvo::PixelFormatInfo info = mapPixelFormat(format);

    // Get the size in bits of each component
    bit_depth = PNGMapBitDepth(info);

    // Get the color type
    color_type = PNGMapColorType(info);

    return bit_depth > 0 && color_type >= 0;
}

} // namespace

bool virvo::encodePNG(std::vector<unsigned char>& data, PNGOptions const& options)
{
    int bit_depth   = 0;
    int color_type  = 0;

    // Check if its possible to encode the image...
    if (!PNGGetImageInfo(options.format, bit_depth, color_type))
        return false;

    PNGWriteContext context;

    // Allocate and initialize png_ptr struct for writing, and any other memory
    context.png = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, PNGErrorCallback, PNGWarningCallback);

    if (context.png == 0)
        return false;

    // Allocate and initialize the info structure
    context.info = png_create_info_struct(context.png);

    if (context.info == 0)
        return false;

    std::vector<unsigned char> compressed;

    PNGIO out(compressed);

    // Set error handling.
    if (setjmp(png_jmpbuf(context.png)))
        return false;

    // Replace the default data output functions with a user supplied one(s).
    // If buffered output is not used, then output_flush_fn can be set to NULL.
    // If PNG_WRITE_FLUSH_SUPPORTED is not defined at libpng compile time
    // output_flush_fn will be ignored (and thus can be NULL).
    png_set_write_fn(context.png, reinterpret_cast<void*>(&out), PNGWriteFunc, 0);

    // Set the library compression level.
    //
    // Currently, valid values range from 0 - 9, corresponding directly to the zlib compression
    // levels 0 - 9 (0 - no compression, 9 - "maximal" compression).
    // Note that tests have shown that zlib compression levels 3-6 usually perform as well as
    // level 9 for PNG images, and do considerably fewer caclulations. In the future,
    // these values may not correspond directly to the zlib compression levels.
    png_set_compression_level(context.png, options.compression_level);

    // Set the image information here.
    png_set_IHDR(context.png, context.info, options.w, options.h, bit_depth, color_type,
        PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);

    // TODO:
    // png_set_sBIT(...)

    // TODO:
    // png_set_gAMA(...)

    // TODO:
    // png_set_bKGD(...)

    // Writes all the PNG information before the image.
    png_write_info_before_PLTE(context.png, context.info);

    // Write the image data
    for (int y = 0; y < options.h; y++)
    {
        png_bytep row_ptr = &data[y * options.pitch];
        png_write_rows(context.png, &row_ptr, 1);
    }

    png_write_end(context.png, context.info);

    // Update the data
    data.swap(compressed);

    return true;
}

bool virvo::decodePNG(std::vector<unsigned char>& data, PNGOptions& options)
{
    PNGReadContext context;

    // Create and initialize the png_struct with the desired error handler
    // functions.  If you want to use the default stderr and longjump method,
    // you can supply NULL for the last three parameters.  We also supply the
    // the compiler header file version, so that we know if the application
    // was compiled with a compatible version of the library.
    context.png = png_create_read_struct(PNG_LIBPNG_VER_STRING, 0/*user-data*/, PNGErrorCallback, PNGWarningCallback);

    if (context.png == 0)
        return false;

    // Allocate/initialize the memory for image information.
    context.info = png_create_info_struct(context.png);

    if (context.info == 0)
        return false;

    // Create the output buffer
    std::vector<unsigned char> uncompressed;

    // Create a wrapper for the input buffer
    PNGIO in(data);

    // Set error handling if you are using the setjmp/longjmp method (this is
    // the normal method of doing things with libpng).  REQUIRED unless you
    // set up your own error handlers in the png_create_read_struct() earlier.
    if (setjmp(png_jmpbuf(context.png)))
        return false;

    // Set the read function
    png_set_read_fn(context.png, (void*)&in, PNGReadFunc);

    // The call to png_read_info() gives us all of the information from the
    // PNG file before the first IDAT (image data chunk).
    png_read_info(context.png, context.info);

    png_uint_32 w = 0;
    png_uint_32 h = 0;
    int bit_depth = 0;
    int color_type = 0;

    png_get_IHDR(context.png, context.info, &w, &h, &bit_depth, &color_type, 0, 0, 0);

    //
    // TODO:
    // Check against the values given in the options or simply modify the options???
    //

    //
    // From here down we are concerned with colortables and pixels
    //
    // Expand palette images to RGB, low-bit-depth grayscale images to 8 bits,
    // transparency chunks to alpha channel; strip 16-bit-per-sample
    // images to 8 bits per sample; and convert grayscale to RGB[A]
    //

    // paletted images are expanded to RGB
    if (color_type == PNG_COLOR_TYPE_PALETTE)
    {
        png_set_expand(context.png);
    }

    // grayscale images of bit-depth less than 8 are expanded
    // to 8-bit images and tRNS chunks are expanded to alpha channels
    if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
    {
        png_set_expand(context.png);
    }

    // expand transparency chunks to alpha channel
    if (png_get_valid(context.png, context.info, PNG_INFO_tRNS))
    {
        png_set_tRNS_to_alpha(context.png);
    }

    // TODO:
    // png_set_strip_16

    // TODO:
    // png_set_gray_to_rgb

    // TODO:
    // png_set_bgr

    // TODO:
    // png_[s,g]et_gAMA

    // TODO:
    // png_[s,g]et_bKGD

    //
    // After the transformations have been registered update png_info_ptr data
    // Get again width, height and channels
    //

    png_read_update_info(context.png, context.info);

    w           = png_get_image_width(context.png, context.info);
    h           = png_get_image_height(context.png, context.info);
    bit_depth   = png_get_bit_depth(context.png, context.info);
    color_type  = png_get_color_type(context.png, context.info);

    //
    // TODO:
    // - Check for correct image dimension/format...
    // - Store the correct pixel format in options...
    //

    assert( options.w >= 0 && static_cast<png_uint_32>(options.w) == w );
    assert( options.h >= 0 && static_cast<png_uint_32>(options.h) == h );

    // Create the image buffer
    uncompressed.resize(options.pitch * options.h);

    // Read the image
    for (int y = 0; y < options.h; y++)
    {
        png_bytep row = &uncompressed[y * options.pitch];
        png_read_rows(context.png, &row, &row, 1);
    }

    png_read_end(context.png, context.info);

    // Update the image data.
    data.swap(uncompressed);

    return true;
}

#else // HAVE_PNG

bool virvo::encodePNG(std::vector<unsigned char>& /*data*/, PNGOptions const& /*options*/)
{
    return false;
}

bool virvo::decodePNG(std::vector<unsigned char>& /*data*/, PNGOptions& /*options*/)
{
    return false;
}

#endif // !HAVE_PNG

bool virvo::encodePNG(CompressedVector& data, PNGOptions const& options)
{
    if (data.getCompressionType() != Compress_None)
        return false;

    if (encodePNG(data.vector(), options))
    {
        data.setCompressionType(Compress_PNG);
        return true;
    }

    return false;
}

bool virvo::decodePNG(CompressedVector& data, PNGOptions& options)
{
    if (data.getCompressionType() != Compress_PNG)
        return false;

    if (decodePNG(data.vector(), options))
    {
        data.setCompressionType(Compress_None);
        return true;
    }

    return false;
}
<|endoftext|>


<commit_before>#include "Customs/LightScript.hpp"
#include "Globals/EngineGlobals.hpp"

const int middlePosition = 2middlePosition

LightScript::LightScript(GameObject *owner) : Script(owner) {}

/**
    @brief that function starts the light script. Create the animation,
    position, the animator and the input.
*/
void LightScript::Start() {
    // Create animations, define position and animator by gameobject.
    CreateAnimations();
    position = GetOwner()->GetPosition();
    animator = (Animator *)GetOwner()->GetComponent("Animator");
    input = InputSystem::GetInstance();
    // Not affected by zoom.
    GetOwner()->SetZoomProportion(Vector(0, 0));
}

/**
    @brief that function creates the animations of the light script. Create the
    light image, the light animation and animator.
*/
void LightScript::CreateAnimations(){
    // Instantiating lightimage by image file and define its positons.
    auto lightImage = new Image("assets/luz.png",0,0,682, 512);

    // Instantiating light animation by gameobject components, image and play state.
    auto lightAnimation = new Animation(GetOwner(),lightImage );

    // Setting frames of light animation.
    lightAnimation->AddFrame(new Frame(0,0, 682, 512));

    // Instantiating animator, and setting its animation.
    auto lightAnimator = new Animator(GetOwner());
    lightAnimator->AddAnimation("lightAnimation", lightAnimation);
}

/**
    @brief that function updates the components of the light script. Create the player
    and get his instance, currante scene and object ("NakedMan")
*/
void LightScript::ComponentUpdate() {
    // Defining player.
    player = SceneManager::GetInstance()->GetCurrentScene()->GetGameObject("NakedMan");
    // Check for the player and its animator and input state.
    if (player) {
        if (play==1) {
            animator->PlayAnimation("lightAnimation");
        }

        if (input->GetKeyDown(INPUT_Y) && play==0) {
            play=1;
        }

        else if (input->GetKeyDown(INPUT_Y) && play==1) {
            play=0;
        }

    }
}

/**
    @brief that function fixs the components update of the light script. Check if
    there is a player and get his position x and y.
*/
void LightScript::FixedComponentUpdate() {
    // Check for the player's state, and if is true, sets its x and y positions.
    if (player) {
        position->m_x = player->GetPosition()->m_x - GetOwner()->GetWidth() / middlePosition + 40;
        position->m_y = player->GetPosition()->m_y - GetOwner()->GetHeight() / middlePosition + 40;
    }
}
<commit_msg>Fix error on ligthScript.cpp<commit_after>#include "Customs/LightScript.hpp"
#include "Globals/EngineGlobals.hpp"

const int middlePosition = 2;

LightScript::LightScript(GameObject *owner) : Script(owner) {}

/**
    @brief that function starts the light script. Create the animation,
    position, the animator and the input.
*/
void LightScript::Start() {
    // Create animations, define position and animator by gameobject.
    CreateAnimations();
    position = GetOwner()->GetPosition();
    animator = (Animator *)GetOwner()->GetComponent("Animator");
    input = InputSystem::GetInstance();
    // Not affected by zoom.
    GetOwner()->SetZoomProportion(Vector(0, 0));
}

/**
    @brief that function creates the animations of the light script. Create the
    light image, the light animation and animator.
*/
void LightScript::CreateAnimations(){
    // Instantiating lightimage by image file and define its positons.
    auto lightImage = new Image("assets/luz.png",0,0,682, 512);

    // Instantiating light animation by gameobject components, image and play state.
    auto lightAnimation = new Animation(GetOwner(),lightImage );

    // Setting frames of light animation.
    lightAnimation->AddFrame(new Frame(0,0, 682, 512));

    // Instantiating animator, and setting its animation.
    auto lightAnimator = new Animator(GetOwner());
    lightAnimator->AddAnimation("lightAnimation", lightAnimation);
}

/**
    @brief that function updates the components of the light script. Create the player
    and get his instance, currante scene and object ("NakedMan")
*/
void LightScript::ComponentUpdate() {
    // Defining player.
    player = SceneManager::GetInstance()->GetCurrentScene()->GetGameObject("NakedMan");
    // Check for the player and its animator and input state.
    if (player) {
        if (play==1) {
            animator->PlayAnimation("lightAnimation");
        }

        if (input->GetKeyDown(INPUT_Y) && play==0) {
            play=1;
        }

        else if (input->GetKeyDown(INPUT_Y) && play==1) {
            play=0;
        }

    }
}

/**
    @brief that function fixs the components update of the light script. Check if
    there is a player and get his position x and y.
*/
void LightScript::FixedComponentUpdate() {
    // Check for the player's state, and if is true, sets its x and y positions.
    if (player) {
        position->m_x = player->GetPosition()->m_x - GetOwner()->GetWidth() / middlePosition + 40;
        position->m_y = player->GetPosition()->m_y - GetOwner()->GetHeight() / middlePosition + 40;
    }
}
<|endoftext|>


<commit_before>/*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
#ifndef __CTF_HPP__
#define __CTF_HPP__

#include "mpi.h"
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <complex>
#include <assert.h>

#define CTF_VERSION 134

#include "../src/interface/tensor.h"
#include "../src/interface/idx_tensor.h"
#include "../src/interface/timer.h"
#include "../src/interface/back_comp.h"

#endif

<commit_msg>incremented version to 1.35<commit_after>/*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
#ifndef __CTF_HPP__
#define __CTF_HPP__

#include "mpi.h"
#include <stdio.h>
#include <stdint.h>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <complex>
#include <assert.h>

#define CTF_VERSION 135

#include "../src/interface/tensor.h"
#include "../src/interface/idx_tensor.h"
#include "../src/interface/timer.h"
#include "../src/interface/back_comp.h"

#endif

<|endoftext|>


<commit_before>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// 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.

#ifndef URI_HPP
#define URI_HPP

#include <gsl.h>
#include <unordered_map>

namespace uri {

  /**
   * Representation of RFC 3986 URI's.
   * Ref. https://tools.ietf.org/html/rfc3986
   **/
  class URI {
  private:
    /** Non-owning pointer-size type */
    struct Span_t {
      size_t begin;
      size_t end;

      Span_t(const size_t b = 0U, const size_t e = 0U) noexcept
        : begin{b}
        , end{e}
      {}
    }; //< struct Span_t

  public:
    /*
     * Default constructor
     */
    URI() = default;

    /*
     * Default copy and move constructors
     */
    URI(URI&) = default;
    URI(URI&&) = default;

    /*
     * Default destructor
     */
    ~URI() = default;

    /*
     * Default assignment operators
     */
    URI& operator=(const URI&) = default;
    URI& operator=(URI&&) = default;

    //
    // We might do a span-based constructor later.
    // URI(gsl::span<const char>);
    //

    /**
     * @brief Construct using a C-String
     *
     * @param uri : A C-String representing a uri
     */
    URI(const char* uri);

    /**
     * @brief Construct using a string
     *
     * @param uri : A string representing a uri
     */
    URI(const std::string& uri);

    ///////////////////////////////////////////////
    //----------RFC-specified URI parts----------//
    ///////////////////////////////////////////////

    /**
     * @brief Get userinfo.
     *
     * E.g. 'username@'...
     *
     * @return The user's information
     */
    std::string userinfo() const;

    /**
     * @brief Get host.
     *
     * E.g. 'includeos.org', '10.0.0.42' etc.
     *
     * @return The host's information
     */
    std::string host() const;

    /**
     * @brief Get the raw port number in decimal character representation.
     *
     * @return The raw port number as a string
     */
    std::string port_str() const;

    /**
     * @brief Get numeric port number.
     *
     * @warning The RFC doesn't specify dimension. This funcion will truncate
     * any overflowing digits.
     *
     * @return The numeric port number as a 16-bit number
     */
    uint16_t port() const noexcept;

    /**
     * @brief Get the path.
     *
     * E.g. /pictures/logo.png
     *
     * @return The path information
     */
    std::string path() const;

    /**
     * @brief Get the complete unparsed query string.
     *
     * @return The complete unparsed query string
     */
    std::string query() const;

    /**
     * @brief Get the fragment part.
     *
     * E.g. "...#anchor1"
     *
     * @return the fragment part
     */
    std::string fragment() const;

    /**
     * @brief Get the URI-decoded value of a query-string key.
     *
     * @param key : The key to find the associated value
     *
     * @return The key's associated value
     *
     * @example For the query: "?name=Bjarne%20Stroustrup",
     * query("name") returns "Bjarne Stroustrup"
     */
    std::string query(const std::string& key);

    /**
     * @brief Get a string representation of this
     * class
     *
     * @return - A string representation
     */
    std::string to_string() const;

    /**
     * @brief Operator to transform this class
     * into string form
     */
    operator std::string () const;

  private:
    /*
     * A copy of the data representing a uri
     */
    std::string uri_str_;

    uint16_t port_;

    Span_t uri_data_;
    Span_t userinfo_;
    Span_t host_;
    Span_t port_str_;
    Span_t path_;
    Span_t query_;
    Span_t fragment_;

    static const Span_t zero_span_;

    std::unordered_map<std::string,std::string> queries_;

    /**
     * @brief Parse the given string representing a uri
     * into its given parts according to RFC 3986
     *
     * @param uri : The string representing a uri
     */
    void parse(const std::string& uri);

  }; // class uri::URI

  std::ostream& operator<< (std::ostream&, const URI&);

} // namespace uri

#endif
<commit_msg>Added documentation for uri::operator<<(std::ostream&, const URI&)<commit_after>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// 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.

#ifndef URI_HPP
#define URI_HPP

#include <gsl.h>
#include <unordered_map>

namespace uri {

  /**
   * Representation of RFC 3986 URI's.
   * Ref. https://tools.ietf.org/html/rfc3986
   **/
  class URI {
  private:
    /** Non-owning pointer-size type */
    struct Span_t {
      size_t begin;
      size_t end;

      Span_t(const size_t b = 0U, const size_t e = 0U) noexcept
        : begin{b}
        , end{e}
      {}
    }; //< struct Span_t

  public:
    /*
     * Default constructor
     */
    URI() = default;

    /*
     * Default copy and move constructors
     */
    URI(URI&) = default;
    URI(URI&&) = default;

    /*
     * Default destructor
     */
    ~URI() = default;

    /*
     * Default assignment operators
     */
    URI& operator=(const URI&) = default;
    URI& operator=(URI&&) = default;

    //
    // We might do a span-based constructor later.
    // URI(gsl::span<const char>);
    //

    /**
     * @brief Construct using a C-String
     *
     * @param uri : A C-String representing a uri
     */
    URI(const char* uri);

    /**
     * @brief Construct using a string
     *
     * @param uri : A string representing a uri
     */
    URI(const std::string& uri);

    ///////////////////////////////////////////////
    //----------RFC-specified URI parts----------//
    ///////////////////////////////////////////////

    /**
     * @brief Get userinfo.
     *
     * E.g. 'username@'...
     *
     * @return The user's information
     */
    std::string userinfo() const;

    /**
     * @brief Get host.
     *
     * E.g. 'includeos.org', '10.0.0.42' etc.
     *
     * @return The host's information
     */
    std::string host() const;

    /**
     * @brief Get the raw port number in decimal character representation.
     *
     * @return The raw port number as a string
     */
    std::string port_str() const;

    /**
     * @brief Get numeric port number.
     *
     * @warning The RFC doesn't specify dimension. This funcion will truncate
     * any overflowing digits.
     *
     * @return The numeric port number as a 16-bit number
     */
    uint16_t port() const noexcept;

    /**
     * @brief Get the path.
     *
     * E.g. /pictures/logo.png
     *
     * @return The path information
     */
    std::string path() const;

    /**
     * @brief Get the complete unparsed query string.
     *
     * @return The complete unparsed query string
     */
    std::string query() const;

    /**
     * @brief Get the fragment part.
     *
     * E.g. "...#anchor1"
     *
     * @return the fragment part
     */
    std::string fragment() const;

    /**
     * @brief Get the URI-decoded value of a query-string key.
     *
     * @param key : The key to find the associated value
     *
     * @return The key's associated value
     *
     * @example For the query: "?name=Bjarne%20Stroustrup",
     * query("name") returns "Bjarne Stroustrup"
     */
    std::string query(const std::string& key);

    /**
     * @brief Get a string representation of this
     * class
     *
     * @return - A string representation
     */
    std::string to_string() const;

    /**
     * @brief Operator to transform this class
     * into string form
     */
    operator std::string () const;

  private:
    /*
     * A copy of the data representing a uri
     */
    std::string uri_str_;

    uint16_t port_;

    Span_t uri_data_;
    Span_t userinfo_;
    Span_t host_;
    Span_t port_str_;
    Span_t path_;
    Span_t query_;
    Span_t fragment_;

    static const Span_t zero_span_;

    std::unordered_map<std::string,std::string> queries_;

    /**
     * @brief Parse the given string representing a uri
     * into its given parts according to RFC 3986
     *
     * @param uri : The string representing a uri
     */
    void parse(const std::string& uri);

  }; // class uri::URI

  /**
   * @brief Operator to stream the contents of a {URI}
   * to the specified output stream device
   *
   * @param output_device : The output stream device
   * @param uri : The {URI} to send to the output stream
   *
   * @return A reference to the specified output stream device
   */
  std::ostream& operator<< (std::ostream& output_device, const URI& uri);

} // namespace uri

#endif
<|endoftext|>


<commit_before>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// 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.

#ifndef URI_HPP
#define URI_HPP

#include <gsl.h>
#include <unordered_map>

namespace uri {

  /**
   * Representation of RFC 3986 URI's.
   * Ref. https://tools.ietf.org/html/rfc3986
   **/
  class URI {
  public:
    /*
     * Default constructor
     */
    URI() = default;

    /*
     * Default copy and move constructors
     */
    URI(URI&) = default;
    URI(URI&&) = default;

    /*
     * Default destructor
     */
    ~URI() = default;

    /*
     * Default assignment operators
     */
    URI& operator=(const URI&) = default;
    URI& operator=(URI&&) = default;

    //
    // We might do a span-based constructor later.
    // URI(gsl::span<const char>);
    //

    /**
     * @brief Construct using a C-String
     *
     * @param uri : A C-String representing a uri
     */
    URI(const char* uri);

    /**
     * @brief Construct using a {std::string}
     *
     * @param uri : A {std::string} representing a uri
     */
    URI(const std::string& uri);

    ///////////////////////////////////////////////
    //----------RFC-specified URI parts----------//
    ///////////////////////////////////////////////

    /**
     * @brief Get scheme.
     *
     * E.g. 'http', 'file', 'ftp' etc.
     *
     * @return The scheme
     */
    const std::string& scheme() const;

    /**
     * @brief Get userinfo.
     *
     * E.g. 'username@'...
     *
     * @return The user's information
     */
    const std::string& userinfo() const;

    /**
     * @brief Get host.
     *
     * E.g. 'includeos.org', '10.0.0.42' etc.
     *
     * @return The host's information
     */
    const std::string& host() const;

    /**
     * @brief Get the raw port number in decimal character representation.
     *
     * @return The raw port number as a string
     */
    const std::string& port_str() const;

    /**
     * @brief Get numeric port number.
     *
     * @warning The RFC doesn't specify dimension. This funcion will truncate
     * any overflowing digits.
     *
     * @return The numeric port number as a 16-bit number
     */
    uint16_t port() const noexcept;

    /**
     * @brief Get the path.
     *
     * E.g. /pictures/logo.png
     *
     * @return The path information
     */
    const std::string& path() const;

    /**
     * @brief Get the complete unparsed query string.
     *
     * @return The complete unparsed query string
     */
    const std::string& query() const;

    /**
     * @brief Get the fragment part.
     *
     * E.g. "...#anchor1"
     *
     * @return the fragment part
     */
    const std::string& fragment() const;

    /**
     * @brief Get the URI-decoded value of a query-string key.
     *
     * @param key : The key to find the associated value
     *
     * @return The key's associated value
     *
     * @example For the query: "?name=Bjarne%20Stroustrup",
     * query("name") returns "Bjarne Stroustrup"
     */
    const std::string& query(const std::string& key);

    /**
     * @brief Get a string representation of this
     * class
     *
     * @return - A string representation
     */
    std::string to_string() const;

    /**
     * @brief Operator to transform this class
     * into string form
     */
    operator std::string () const;

  private:
    mutable uint16_t port_;

    std::string scheme_;
    std::string userinfo_;
    std::string host_;
    std::string port_str_;
    std::string path_;
    std::string query_;
    std::string fragment_;

    std::unordered_map<std::string,std::string> queries_;

    /**
     * @brief Parse the given {std::string} representing a uri
     * into its given parts according to RFC 3986
     *
     * @param uri : The {std::string} representing a uri
     */
    void parse(const std::string& uri);

    /**
     * @brief Load queries into the map
     */
    void load_queries();

  }; // class uri::URI

  /**
   * @brief Operator to stream the contents of a {URI}
   * to the specified output stream device
   *
   * @param output_device : The output stream device
   * @param uri : The {URI} to send to the output stream
   *
   * @return A reference to the specified output stream device
   */
  std::ostream& operator<< (std::ostream& output_device, const URI& uri);

} // namespace uri

#endif //< URI_HPP
<commit_msg>Added back member to support URI::to_string()<commit_after>// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// 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.

#ifndef URI_HPP
#define URI_HPP

#include <gsl.h>
#include <unordered_map>

namespace uri {

  /**
   * Representation of RFC 3986 URI's.
   * Ref. https://tools.ietf.org/html/rfc3986
   **/
  class URI {
  public:
    /*
     * Default constructor
     */
    URI() = default;

    /*
     * Default copy and move constructors
     */
    URI(URI&) = default;
    URI(URI&&) = default;

    /*
     * Default destructor
     */
    ~URI() = default;

    /*
     * Default assignment operators
     */
    URI& operator=(const URI&) = default;
    URI& operator=(URI&&) = default;

    //
    // We might do a span-based constructor later.
    // URI(gsl::span<const char>);
    //

    /**
     * @brief Construct using a C-String
     *
     * @param uri : A C-String representing a uri
     */
    URI(const char* uri);

    /**
     * @brief Construct using a {std::string}
     *
     * @param uri : A {std::string} representing a uri
     */
    URI(const std::string& uri);

    ///////////////////////////////////////////////
    //----------RFC-specified URI parts----------//
    ///////////////////////////////////////////////

    /**
     * @brief Get scheme.
     *
     * E.g. 'http', 'file', 'ftp' etc.
     *
     * @return The scheme
     */
    const std::string& scheme() const;

    /**
     * @brief Get userinfo.
     *
     * E.g. 'username@'...
     *
     * @return The user's information
     */
    const std::string& userinfo() const;

    /**
     * @brief Get host.
     *
     * E.g. 'includeos.org', '10.0.0.42' etc.
     *
     * @return The host's information
     */
    const std::string& host() const;

    /**
     * @brief Get the raw port number in decimal character representation.
     *
     * @return The raw port number as a string
     */
    const std::string& port_str() const;

    /**
     * @brief Get numeric port number.
     *
     * @warning The RFC doesn't specify dimension. This funcion will truncate
     * any overflowing digits.
     *
     * @return The numeric port number as a 16-bit number
     */
    uint16_t port() const noexcept;

    /**
     * @brief Get the path.
     *
     * E.g. /pictures/logo.png
     *
     * @return The path information
     */
    const std::string& path() const;

    /**
     * @brief Get the complete unparsed query string.
     *
     * @return The complete unparsed query string
     */
    const std::string& query() const;

    /**
     * @brief Get the fragment part.
     *
     * E.g. "...#anchor1"
     *
     * @return the fragment part
     */
    const std::string& fragment() const;

    /**
     * @brief Get the URI-decoded value of a query-string key.
     *
     * @param key : The key to find the associated value
     *
     * @return The key's associated value
     *
     * @example For the query: "?name=Bjarne%20Stroustrup",
     * query("name") returns "Bjarne Stroustrup"
     */
    const std::string& query(const std::string& key);

    /**
     * @brief Get a string representation of this
     * class
     *
     * @return - A string representation
     */
    std::string to_string() const;

    /**
     * @brief Operator to transform this class
     * into string form
     */
    operator std::string () const;

  private:
    /*
     * A copy of the data representing a uri
     */
    std::string uri_str_;

    mutable uint16_t port_;

    std::string scheme_;
    std::string userinfo_;
    std::string host_;
    std::string port_str_;
    std::string path_;
    std::string query_;
    std::string fragment_;

    std::unordered_map<std::string,std::string> queries_;

    /**
     * @brief Parse the given {std::string} representing a uri
     * into its given parts according to RFC 3986
     *
     * @param uri : The {std::string} representing a uri
     */
    void parse(const std::string& uri);

    /**
     * @brief Load queries into the map
     */
    void load_queries();

  }; // class uri::URI

  /**
   * @brief Operator to stream the contents of a {URI}
   * to the specified output stream device
   *
   * @param output_device : The output stream device
   * @param uri : The {URI} to send to the output stream
   *
   * @return A reference to the specified output stream device
   */
  std::ostream& operator<< (std::ostream& output_device, const URI& uri);

} // namespace uri

#endif //< URI_HPP
<|endoftext|>


<commit_before>#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;

struct

const vector<string>& split(string filename)
{
	ifstream myfile(filename);
	vector<string>* commands = new vector<string>();
	string current_command = "";
	int brace_balance = 0;
	typedef std::istreambuf_iterator<char> CharIter;

	for (CharIter it(myfile); it != CharIter(); ++it)
	{
		cout << current_command << endl;
		switch (*it)
		{
		case '\t': case '\n': case ' ':
			// silly whitespace
			break;
		case '{':
			++brace_balance;
			if (brace_balance != 1) // if it's not the opening {
			{
				current_command += *it;
			}
			break;
		case '}':
			--brace_balance;
			if (brace_balance != 0) // if it's not the closing }
			{
				current_command += *it;
			}
			break;
		case ';':
			if (brace_balance == 0)
			{
				commands->push_back(current_command);
				current_command = "";
			}
			else
			{
				current_command += ';';
			}
			break;
		default:
			current_command += *it;
			break;
		}
	}
	myfile.close();
	return *commands;
}
int main()
{
	vector<string> commands = split("file");
	cout << "Commands read as follows: (in order of execution)\n";
	for (vector<string>::const_iterator i = commands.begin(); i != commands.end(); ++i) cout << "  - " << *i << endl;
}
<commit_msg>Thing?<commit_after>#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <iterator>
using namespace std;

vector<const string>& split(string filename)
{
	ifstream myfile(filename);
	vector<const string>* commands = new vector<string>();
	string current_command = "";
	int brace_balance = 0;
	typedef std::istreambuf_iterator<char> CharIter;

	for (CharIter it(myfile); it != CharIter(); ++it)
	{
		cout << current_command << endl;
		switch (*it)
		{
		case '\t': case '\n': case ' ':
			// silly whitespace
			break;
		case '{':
			++brace_balance;
			if (brace_balance != 1) // if it's not the opening {
			{
				current_command += *it;
			}
			break;
		case '}':
			--brace_balance;
			if (brace_balance != 0) // if it's not the closing }
			{
				current_command += *it;
			}
			break;
		case ';':
			if (brace_balance == 0)
			{
				commands->push_back(current_command);
				current_command = "";
			}
			else
			{
				current_command += ';';
			}
			break;
		default:
			current_command += *it;
			break;
		}
	}
	myfile.close();
	return *commands;
}
int main()
{
	vector<const string> commands = split("file");
	cout << "Commands read as follows: (in order of execution)\n";
	for (vector<string>::const_iterator i = commands.begin(); i != commands.end(); ++i) cout << "  - " << *i << endl;
}
<|endoftext|>


<commit_before>//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// spdlog usage example
//
//

#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON

#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"

#include <iostream>
#include <memory>

void async_example();
void user_defined_example();
void err_handler_example();

namespace spd = spdlog;
int main(int, char *[])
{

    try
    {
        auto console = spdlog::stdout_color_st("console");
        console->info("Welcome to spdlog!");

        console->info("Welcome to spdlog!");
        console->error("Some error message with arg: {}", 1);
        err_handler_example();
        // Formatting examples
        console->warn("Easy padding in numbers like {:08d}", 12);
        console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
        console->info("Support for floats {:03.2f}", 1.23456);
        console->info("Positional args are {1} {0}..", "too", "supported");
        console->info("{:<30}", "left aligned");

        spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");

        // Create basic file logger (not rotated)
        auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic-log.txt");
        my_logger->info("Some log message");

        // Create a file rotating logger with 5mb size max and 3 rotated files
        auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
        for (int i = 0; i < 10; ++i)
        {
            rotating_logger->info("{} * {} equals {:>10}", i, i, i * i);
        }

        // Create a daily logger - a new file is created every day on 2:30am
        auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
        // trigger flush if the log severity is error or higher
        daily_logger->flush_on(spd::level::err);
        daily_logger->info(123.44);

        // Customize msg format for all messages
        spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v");

        console->info("This an info message with custom format");
        console->error("This an error message with custom format");

        // Runtime log levels
        spd::set_level(spd::level::info); // Set global log level to info
        console->debug("This message should not be displayed!");
        console->set_level(spd::level::debug); // Set specific logger's log level
        console->debug("This message should be displayed..");

        // Compile time log levels
        // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
        SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
        SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);

        // Asynchronous logging is very fast..
        // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
        async_example();

        // Log user-defined types example
        user_defined_example();

        // Change default log error handler
        err_handler_example();

        // Apply a function on all registered loggers
        spd::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });

        // Release and close all loggers
        spdlog::drop_all();
    }
    // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
    catch (const spd::spdlog_ex &ex)
    {
        std::cout << "Log init failed: " << ex.what() << std::endl;
        return 1;
    }
}
// must be included to use async logger
#include "spdlog/async.h"
void async_example()
{
    auto async_file = spd::basic_logger_mt<spdlog::create_async>("async_file_logger", "logs/async_log.txt");
    for (int i = 0; i < 100; ++i)
    {
        async_file->info("Async message #{}", i);
    }

    // you can also modify thread pool settings *before* creating the logger:
    // spdlog::init_thread_pool(32768, 4); // queue with 32k of pre allocated items and 4 backing threads.
    // if not called a defaults are: preallocated 8192 queue items and 1 worker thread.
}

// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h"
void syslog_example()
{
    std::string ident = "spdlog-example";
    auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID);
    syslog_logger->warn("This is warning that will end up in syslog.");
}
#endif

// Android example
#if defined(__ANDROID__)
#incude "spdlog/sinks/android_sink.h"
void android_example()
{
    std::string tag = "spdlog-android";
    auto android_logger = spd::android_logger("android", tag);
    android_logger->critical("Use \"adb shell logcat\" to view this message.");
}

#endif

// user defined types logging by implementing operator<<
struct my_type
{
    int i;
    template<typename OStream>
    friend OStream &operator<<(OStream &os, const my_type &c)
    {
        return os << "[my_type i=" << c.i << "]";
    }
};

#include "spdlog/fmt/ostr.h" // must be included
void user_defined_example()
{
    spd::get("console")->info("user defined type: {}", my_type{14});
}

//
// custom error handler
//
void err_handler_example()
{
    // can be set globaly or per logger(logger->set_error_handler(..))
    spdlog::set_error_handler([](const std::string &msg) { spd::get("console")->error("*******my err handler: {}", msg); });
    spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
    // spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
}
<commit_msg>example<commit_after>//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// spdlog usage example
//
//

#define SPDLOG_TRACE_ON
#define SPDLOG_DEBUG_ON

#include "spdlog/sinks/file_sinks.h"
#include "spdlog/sinks/stdout_color_sinks.h"

#include <iostream>
#include <memory>

void async_example();
void user_defined_example();
void err_handler_example();

namespace spd = spdlog;
int main(int, char *[])
{

    try
    {
        auto console = spdlog::stdout_color_st("console");
        console->info("Welcome to spdlog!");

        console->info("Welcome to spdlog!");
        console->error("Some error message with arg: {}", 1);
        err_handler_example();
        // Formatting examples
        console->warn("Easy padding in numbers like {:08d}", 12);
        console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
        console->info("Support for floats {:03.2f}", 1.23456);
        console->info("Positional args are {1} {0}..", "too", "supported");
        console->info("{:<30}", "left aligned");

        spd::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name) function");

        // Create basic file logger (not rotated)
        auto my_logger = spd::basic_logger_mt("basic_logger", "logs/basic-log.txt");
        my_logger->info("Some log message");

        // Create a file rotating logger with 5mb size max and 3 rotated files
        auto rotating_logger = spd::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
        for (int i = 0; i < 10; ++i)
        {
            rotating_logger->info("{} * {} equals {:>10}", i, i, i * i);
        }

        // Create a daily logger - a new file is created every day on 2:30am
        auto daily_logger = spd::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
        // trigger flush if the log severity is error or higher
        daily_logger->flush_on(spd::level::err);
        daily_logger->info(123.44);

        // Customize msg format for all messages
        spd::set_pattern("[%^+++%$] [%H:%M:%S %z] [thread %t] %v");

        console->info("This an info message with custom format");
        console->error("This an error message with custom format");

		// Change format back to to default
		spd::set_pattern ("%+");

        // Runtime log levels
        spd::set_level(spd::level::info); // Set global log level to info
        console->debug("This message should not be displayed!");
        console->set_level(spd::level::debug); // Set specific logger's log level
        console->debug("This message should be displayed..");

        // Compile time log levels
        // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
        SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
        SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);

        // Asynchronous logging is very fast..
        // Just call spdlog::set_async_mode(q_size) and all created loggers from now on will be asynchronous..
        async_example();

        // Log user-defined types example
        user_defined_example();

        // Change default log error handler
        err_handler_example();

        // Apply a function on all registered loggers
        spd::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });

        // Release and close all loggers
        spdlog::drop_all();
    }
    // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
    catch (const spd::spdlog_ex &ex)
    {
        std::cout << "Log init failed: " << ex.what() << std::endl;
        return 1;
    }
}
// must be included to use async logger
#include "spdlog/async.h"
void async_example()
{
    auto async_file = spd::basic_logger_mt<spdlog::create_async>("async_file_logger", "logs/async_log.txt");
    for (int i = 0; i < 100; ++i)
    {
        async_file->info("Async message #{}", i);
    }

    // you can also modify thread pool settings *before* creating the logger:
    // spdlog::init_thread_pool(32768, 4); // queue with 32k of pre allocated items and 4 backing threads.
    // if not called a defaults are: preallocated 8192 queue items and 1 worker thread.
}

// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h"
void syslog_example()
{
    std::string ident = "spdlog-example";
    auto syslog_logger = spd::syslog_logger("syslog", ident, LOG_PID);
    syslog_logger->warn("This is warning that will end up in syslog.");
}
#endif

// Android example
#if defined(__ANDROID__)
#incude "spdlog/sinks/android_sink.h"
void android_example()
{
    std::string tag = "spdlog-android";
    auto android_logger = spd::android_logger("android", tag);
    android_logger->critical("Use \"adb shell logcat\" to view this message.");
}

#endif

// user defined types logging by implementing operator<<
struct my_type
{
    int i;
    template<typename OStream>
    friend OStream &operator<<(OStream &os, const my_type &c)
    {
        return os << "[my_type i=" << c.i << "]";
    }
};

#include "spdlog/fmt/ostr.h" // must be included
void user_defined_example()
{
    spd::get("console")->info("user defined type: {}", my_type{14});
}

//
// custom error handler
//
void err_handler_example()
{
    // can be set globaly or per logger(logger->set_error_handler(..))
    spdlog::set_error_handler([](const std::string &msg) { spd::get("console")->error("*******my err handler: {}", msg); });
    spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
    // spd::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
}
<|endoftext|>


<commit_before>//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// spdlog usage example
//
//

#include <iostream>

void stdout_example();
void basic_example();
void rotating_example();
void daily_example();
void async_example();
void user_defined_example();
void err_handler_example();
void syslog_example();

#include "spdlog/spdlog.h"

int main(int, char *[])
{
    try
    {
        // console logging example
        stdout_example();

        // various file loggers
        basic_example();
        rotating_example();
        daily_example();

        // async logging using a backing thread pool
        async_example();

        // user defined types logging by implementing operator<<
        user_defined_example();

        // custom  error handler
        err_handler_example();

        // apply some function on all registered loggers
        spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });

        // Release and close all loggers
        spdlog::drop_all();
    }
    // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
    catch (const spdlog::spdlog_ex &ex)
    {
        std::cout << "Log init failed: " << ex.what() << std::endl;
        return 1;
    }
}

#include "spdlog/sinks/stdout_color_sinks.h" // or "/sinks/stdout_sinks.h" if no colors needed
void stdout_example()
{
    // create color multi threaded logger
    auto console = spdlog::stdout_logger_mt("console");
    console->info("Welcome to spdlog!");
    console->error("Some error message with arg: {}", 1);

    auto err_logger = spdlog::stderr_logger_mt("error_logger");
    err_logger->error("Some error message");

    // Formatting examples
    console->warn("Easy padding in numbers like {:08d}", 12);
    console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
    console->info("Support for floats {:03.2f}", 1.23456);
    console->info("Positional args are {1} {0}..", "too", "supported");
    console->info("{:<30}", "left aligned");

    spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");

    // Runtime log levels
    spdlog::set_level(spdlog::level::info); // Set global log level to info
    console->debug("This message should not be displayed!");
    console->set_level(spdlog::level::trace); // Set specific logger's log level
    console->debug("This message should be displayed..");

    // Customize msg format for all loggers
    spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] [thread %t] %v");
    console->info("This an info message with custom format");

    // Compile time log levels
    // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
    SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
    SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
}

#include "spdlog/sinks/basic_file_sink.h"
void basic_example()
{
    // Create basic file logger (not rotated)
    auto my_logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
}

#include "spdlog/sinks/rotating_file_sink.h"
void rotating_example()
{
    // Create a file rotating logger with 5mb size max and 3 rotated files
    auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
}

#include "spdlog/sinks/daily_file_sink.h"
void daily_example()
{
    // Create a daily logger - a new file is created every day on 2:30am
    auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
}

#include "spdlog/async.h"
void async_example()
{
    // default thread pool settings can be modified *before* creating the async logger:
    // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
    auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
    // alternatively:
    // auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");

    for (int i = 1; i < 101; ++i)
    {
        async_file->info("Async message #{}", i);
    }
}

// user defined types logging by implementing operator<<
#include "spdlog/fmt/ostr.h" // must be included
struct my_type
{
    int i;
    template<typename OStream>
    friend OStream &operator<<(OStream &os, const my_type &c)
    {
        return os << "[my_type i=" << c.i << "]";
    }
};

void user_defined_example()
{
    spdlog::get("console")->info("user defined type: {}", my_type{14});
}

//
// custom error handler
//
void err_handler_example()
{
    // can be set globally or per logger(logger->set_error_handler(..))
    spdlog::set_error_handler([](const std::string &msg) { spdlog::get("console")->error("*** LOGGER ERROR ***: {}", msg); });
    spdlog::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
}

// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h"
void syslog_example()
{
    std::string ident = "spdlog-example";
    auto syslog_logger = spdlog::syslog_logger("syslog", ident, LOG_PID);
    syslog_logger->warn("This is warning that will end up in syslog.");
}
#endif

// Android example
#if defined(__ANDROID__)
#incude "spdlog/sinks/android_sink.h"
void android_example()
{
    std::string tag = "spdlog-android";
    auto android_logger = spdlog::android_logger("android", tag);
    android_logger->critical("Use \"adb shell logcat\" to view this message.");
}

#endif
<commit_msg>Fixed example<commit_after>//
// Copyright(c) 2015 Gabi Melman.
// Distributed under the MIT License (http://opensource.org/licenses/MIT)
//
//
// spdlog usage example
//
//

#include <iostream>

void stdout_example();
void basic_example();
void rotating_example();
void daily_example();
void async_example();
void user_defined_example();
void err_handler_example();
void syslog_example();

#include "spdlog/spdlog.h"

int main(int, char *[])
{
    try
    {
        // console logging example
        stdout_example();

        // various file loggers
        basic_example();
        rotating_example();
        daily_example();

        // async logging using a backing thread pool
        async_example();

        // user defined types logging by implementing operator<<
        user_defined_example();

        // custom  error handler
        err_handler_example();

        // apply some function on all registered loggers
        spdlog::apply_all([&](std::shared_ptr<spdlog::logger> l) { l->info("End of example."); });

        // Release and close all loggers
        spdlog::drop_all();
    }
    // Exceptions will only be thrown upon failed logger or sink construction (not during logging)
    catch (const spdlog::spdlog_ex &ex)
    {
        std::cout << "Log init failed: " << ex.what() << std::endl;
        return 1;
    }
}

#include "spdlog/sinks/stdout_color_sinks.h" // or "/sinks/stdout_sinks.h" if no colors needed
void stdout_example()
{
    // create color multi threaded logger
    auto console = spdlog::stdout_color_mt("console");
    console->info("Welcome to spdlog!");
    console->error("Some error message with arg: {}", 1);

    auto err_logger = spdlog::stderr_color_mt("error_logger");
    err_logger->error("Some error message");

    // Formatting examples
    console->warn("Easy padding in numbers like {:08d}", 12);
    console->critical("Support for int: {0:d};  hex: {0:x};  oct: {0:o}; bin: {0:b}", 42);
    console->info("Support for floats {:03.2f}", 1.23456);
    console->info("Positional args are {1} {0}..", "too", "supported");
    console->info("{:<30}", "left aligned");

    spdlog::get("console")->info("loggers can be retrieved from a global registry using the spdlog::get(logger_name)");

    // Runtime log levels
    spdlog::set_level(spdlog::level::info); // Set global log level to info
    console->debug("This message should not be displayed!");
    console->set_level(spdlog::level::trace); // Set specific logger's log level
    console->debug("This message should be displayed..");

    // Customize msg format for all loggers
    spdlog::set_pattern("[%H:%M:%S %z] [%^---%L---%$] [thread %t] %v");
    console->info("This an info message with custom format");

    // Compile time log levels
    // define SPDLOG_DEBUG_ON or SPDLOG_TRACE_ON
    SPDLOG_TRACE(console, "Enabled only #ifdef SPDLOG_TRACE_ON..{} ,{}", 1, 3.23);
    SPDLOG_DEBUG(console, "Enabled only #ifdef SPDLOG_DEBUG_ON.. {} ,{}", 1, 3.23);
}

#include "spdlog/sinks/basic_file_sink.h"
void basic_example()
{
    // Create basic file logger (not rotated)
    auto my_logger = spdlog::basic_logger_mt("basic_logger", "logs/basic-log.txt");
}

#include "spdlog/sinks/rotating_file_sink.h"
void rotating_example()
{
    // Create a file rotating logger with 5mb size max and 3 rotated files
    auto rotating_logger = spdlog::rotating_logger_mt("some_logger_name", "logs/rotating.txt", 1048576 * 5, 3);
}

#include "spdlog/sinks/daily_file_sink.h"
void daily_example()
{
    // Create a daily logger - a new file is created every day on 2:30am
    auto daily_logger = spdlog::daily_logger_mt("daily_logger", "logs/daily.txt", 2, 30);
}

#include "spdlog/async.h"
void async_example()
{
    // default thread pool settings can be modified *before* creating the async logger:
    // spdlog::init_thread_pool(32768, 1); // queue with max 32k items 1 backing thread.
    auto async_file = spdlog::basic_logger_mt<spdlog::async_factory>("async_file_logger", "logs/async_log.txt");
    // alternatively:
    // auto async_file = spdlog::create_async<spdlog::sinks::basic_file_sink_mt>("async_file_logger", "logs/async_log.txt");

    for (int i = 1; i < 101; ++i)
    {
        async_file->info("Async message #{}", i);
    }
}

// user defined types logging by implementing operator<<
#include "spdlog/fmt/ostr.h" // must be included
struct my_type
{
    int i;
    template<typename OStream>
    friend OStream &operator<<(OStream &os, const my_type &c)
    {
        return os << "[my_type i=" << c.i << "]";
    }
};

void user_defined_example()
{
    spdlog::get("console")->info("user defined type: {}", my_type{14});
}

//
// custom error handler
//
void err_handler_example()
{
    // can be set globally or per logger(logger->set_error_handler(..))
    spdlog::set_error_handler([](const std::string &msg) { spdlog::get("console")->error("*** LOGGER ERROR ***: {}", msg); });
    spdlog::get("console")->info("some invalid message to trigger an error {}{}{}{}", 3);
}

// syslog example (linux/osx/freebsd)
#ifndef _WIN32
#include "spdlog/sinks/syslog_sink.h"
void syslog_example()
{
    std::string ident = "spdlog-example";
    auto syslog_logger = spdlog::syslog_logger("syslog", ident, LOG_PID);
    syslog_logger->warn("This is warning that will end up in syslog.");
}
#endif

// Android example
#if defined(__ANDROID__)
#incude "spdlog/sinks/android_sink.h"
void android_example()
{
    std::string tag = "spdlog-android";
    auto android_logger = spdlog::android_logger("android", tag);
    android_logger->critical("Use \"adb shell logcat\" to view this message.");
}

#endif
<|endoftext|>


<commit_before>#include "test.h"

#include "../drivers/MotorDriver.h"
#include "../drivers/ProximitySensors.h"
#include "../control/Movement.h"

#include <Arduino.h>

#define SPEED 1000

void initTest()
{
	enqueueLinearMovement(SPEED, 500);
	return;

	enqueueLinearMovement(SPEED, 250);
	enqueueTurn(SPEED, 0, -180);
	enqueueLinearMovement(SPEED, 250);
	enqueueTurn(SPEED, 0, 180);
	enqueueLinearMovement(SPEED, 250);
}

void handleTest(void)
{
	//	if(moment == 0 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateLinearMovement(SPEED, 500);
	//	}
	//	else if(moment == 2 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateLinearMovement(SPEED, -100);
	//	}
	//	else if(moment == 4 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 90);
	//	}
	//	else if(moment == 6 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, -90);
	//	}
	//	else if(moment == 8 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 100, 90);
	//	}
	//	else if(moment == 10 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 360);
	//	}
	//	else if(moment == 12 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 450);
	//	}
	//	else if(moment == 14 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 4000);
	//	}
}
<commit_msg>Update test<commit_after>#include "test.h"

#include "../drivers/MotorDriver.h"
#include "../drivers/ProximitySensors.h"
#include "../control/Movement.h"

#include <Arduino.h>

#define SPEED 1000

void initTest()
{
	static int moment = 0;

	switch(moment)
	{
		default: moment = 0;
		case 0: enqueueLinearMovement(SPEED, 500); break;
		case 1: enqueueLinearMovement(SPEED, -500); break;
		case 2: enqueueTurn(SPEED, 0, 90); break;
		case 3: enqueueTurn(SPEED, 0, -90); break;
	}

	++moment;
	return;

	enqueueLinearMovement(SPEED, 250);
	enqueueTurn(SPEED, 0, -180);
	enqueueLinearMovement(SPEED, 250);
	enqueueTurn(SPEED, 0, 180);
	enqueueLinearMovement(SPEED, 250);
}

void handleTest(void)
{
	//	if(moment == 0 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateLinearMovement(SPEED, 500);
	//	}
	//	else if(moment == 2 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateLinearMovement(SPEED, -100);
	//	}
	//	else if(moment == 4 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 90);
	//	}
	//	else if(moment == 6 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, -90);
	//	}
	//	else if(moment == 8 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 100, 90);
	//	}
	//	else if(moment == 10 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 360);
	//	}
	//	else if(moment == 12 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 450);
	//	}
	//	else if(moment == 14 && isMovementComplete())
	//	{
	//		++moment;
	//		initiateTurn(SPEED, 0, 4000);
	//	}
}
<|endoftext|>


<commit_before>#ifndef DATA_PORT_HPP_
#define DATA_PORT_HPP_
#include <unordered_map>
#include <mutex>
#include <condition_variable>
#include "FAST/Data/DataObject.hpp"
#include "FAST/Semaphore.hpp"

namespace fast {

enum StreamingMode { STREAMING_MODE_NEWEST_FRAME_ONLY, STREAMING_MODE_STORE_ALL_FRAMES, STREAMING_MODE_PROCESS_ALL_FRAMES };

class ProcessObject;

class DataPort {
	typedef unsigned int uint;
    public:
        explicit DataPort(SharedPointer<ProcessObject> processObject);

        void addFrame(DataObject::pointer data);

        DataObject::pointer getNextFrame();

        void setTimestep(uint64_t timestep);

        void setStreamingMode(StreamingMode mode);

        SharedPointer<ProcessObject> getProcessObject() const;

        uint64_t getFrameCounter() const;

        /**
         *
         * @return the number of frames stored in this DataPort
         */
        uint getSize() const;

        /**
         * If a process object does not execeute one update iteration; it should call this method.
         */
        void moveDataToNextTimestep();

        void setMaximumNumberOfFrames(uint frames);

        /**
         * This will unblock if this DataPort is currently blocking. Used to stop a pipeline.
         */
        void stop();

        bool hasCurrentData();

        typedef SharedPointer<DataPort> pointer;

        uint64_t getLatestTimestep();
    private:
        /**
         * The process object which produce data for this port
         */
        SharedPointer<ProcessObject> mProcessObject;
        std::unordered_map<uint64_t, DataObject::pointer> mFrames;
        uint64_t mFrameCounter = 0;
        uint64_t mCurrentTimestep = 0;
        StreamingMode mStreamingMode = STREAMING_MODE_PROCESS_ALL_FRAMES;
        std::mutex mMutex;
        std::condition_variable mFrameConditionVariable;
        /**
         * Used to define buffer size for the producer consumer model used in streaming mode PROCESS_ALL_FRAMES
         */
        uint mMaximumNumberOfFrames;
        UniquePointer<LightweightSemaphore> mFillCount;
        UniquePointer<LightweightSemaphore> mEmptyCount;

        bool mIsStaticData = false;
        bool mStop = false;
        bool mGetCalled = false;
};

}

#endif<commit_msg>Get uint definition from DataTypes.hpp<commit_after>#ifndef DATA_PORT_HPP_
#define DATA_PORT_HPP_
#include <unordered_map>
#include <mutex>
#include <condition_variable>
#include "FAST/Data/DataObject.hpp"
#include "FAST/Data/DataTypes.hpp"
#include "FAST/Semaphore.hpp"

namespace fast {

enum StreamingMode { STREAMING_MODE_NEWEST_FRAME_ONLY, STREAMING_MODE_STORE_ALL_FRAMES, STREAMING_MODE_PROCESS_ALL_FRAMES };

class ProcessObject;

class DataPort {
    public:
        explicit DataPort(SharedPointer<ProcessObject> processObject);

        void addFrame(DataObject::pointer data);

        DataObject::pointer getNextFrame();

        void setTimestep(uint64_t timestep);

        void setStreamingMode(StreamingMode mode);

        SharedPointer<ProcessObject> getProcessObject() const;

        uint64_t getFrameCounter() const;

        /**
         *
         * @return the number of frames stored in this DataPort
         */
        uint getSize() const;

        /**
         * If a process object does not execeute one update iteration; it should call this method.
         */
        void moveDataToNextTimestep();

        void setMaximumNumberOfFrames(uint frames);

        /**
         * This will unblock if this DataPort is currently blocking. Used to stop a pipeline.
         */
        void stop();

        bool hasCurrentData();

        typedef SharedPointer<DataPort> pointer;

        uint64_t getLatestTimestep();
    private:
        /**
         * The process object which produce data for this port
         */
        SharedPointer<ProcessObject> mProcessObject;
        std::unordered_map<uint64_t, DataObject::pointer> mFrames;
        uint64_t mFrameCounter = 0;
        uint64_t mCurrentTimestep = 0;
        StreamingMode mStreamingMode = STREAMING_MODE_PROCESS_ALL_FRAMES;
        std::mutex mMutex;
        std::condition_variable mFrameConditionVariable;
        /**
         * Used to define buffer size for the producer consumer model used in streaming mode PROCESS_ALL_FRAMES
         */
        uint mMaximumNumberOfFrames;
        UniquePointer<LightweightSemaphore> mFillCount;
        UniquePointer<LightweightSemaphore> mEmptyCount;

        bool mIsStaticData = false;
        bool mStop = false;
        bool mGetCalled = false;
};

}

#endif
<|endoftext|>