<commit_before>/******************************************************************************
The MIT License(MIT)

Embedded Template Library.

Copyright(c) 2014 jwellbelove

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#include <UnitTest++/UnitTest++.h>

#include <iterator>
#include <string>
#include <vector>
#include <cstdint>

#include "../crc8_ccitt.h"
#include "../crc16.h"
#include "../crc16_ccitt.h"
#include "../crc16_kermit.h"
#include "../crc32.h"
#include "../crc64_ecma.h"
#include "../endian.h"

namespace
{
  SUITE(test_crc)
  {
    //*************************************************************************
    TEST(test_crc8_ccitt_constructor)
    {
      std::string data("123456789");

      uint8_t crc = etl::crc8_ccitt<>(data.begin(), data.end());

      CHECK_EQUAL(0xF4, int(crc));
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_values)
    {
      std::string data("123456789");

      etl::crc8_ccitt<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint8_t crc = crc_calculator;

      CHECK_EQUAL(0xF4, crc);
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_range)
    {
      std::string data("123456789");

      etl::crc8_ccitt<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint8_t crc = crc_calculator.value();

      CHECK_EQUAL(0xF4, crc);
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint8_t crc1 = etl::crc8_ccitt<etl::endian::little>(data1.begin(), data1.end());
      uint8_t crc2 = etl::crc8_ccitt<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(int(crc1), int(crc2));

      uint8_t crc3 = etl::crc8_ccitt<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(int(crc1), int(crc3));
    }

    //*************************************************************************
    TEST(test_crc16)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16<>(data.begin(), data.end());

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_values)
    {
      std::string data("123456789");

      etl::crc16<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_range)
    {
      std::string data("123456789");

      etl::crc16<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16_ccitt<>(data.begin(), data.end());

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_values)
    {
      std::string data("123456789");

      etl::crc16_ccitt<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_range)
    {
      std::string data("123456789");

      etl::crc16_ccitt<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16_ccitt<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16_ccitt<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16_ccitt<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc16_kermit)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16_kermit<>(data.begin(), data.end());

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_values)
    {
      std::string data("123456789");

      etl::crc16_kermit<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_range)
    {
      std::string data("123456789");

      etl::crc16_kermit<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16_kermit<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16_kermit<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16_kermit<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc32)
    {
      std::string data("123456789");

      uint32_t crc = etl::crc32<>(data.begin(), data.end());

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_values)
    {
      std::string data("123456789");

      etl::crc32<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint32_t crc = crc_calculator;

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_range)
    {
      std::string data("123456789");

      etl::crc32<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint32_t crc = crc_calculator.value();

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint32_t crc1 = etl::crc32<etl::endian::little>(data1.begin(), data1.end());
      uint32_t crc2 = etl::crc32<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint32_t crc3 = etl::crc32<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc64_ecma)
    {
      std::string data("123456789");

      uint64_t crc = etl::crc64_ecma<>(data.begin(), data.end());

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_values)
    {
      std::string data("123456789");

      etl::crc64_ecma<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint64_t crc = crc_calculator;

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_range)
    {
      std::string data("123456789");

      etl::crc64_ecma<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint64_t crc = crc_calculator.value();

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint64_t crc1 = etl::crc64_ecma<etl::endian::little>(data1.begin(), data1.end());
      uint64_t crc2 = etl::crc64_ecma<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint64_t crc3 = etl::crc64_ecma<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }
  };
}

<commit_msg>Changed to stddef.h<commit_after>/******************************************************************************
The MIT License(MIT)

Embedded Template Library.

Copyright(c) 2014 jwellbelove

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files(the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and / or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions :

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
******************************************************************************/

#include <UnitTest++/UnitTest++.h>

#include <iterator>
#include <string>
#include <vector>
#include <stdint.h>

#include "../crc8_ccitt.h"
#include "../crc16.h"
#include "../crc16_ccitt.h"
#include "../crc16_kermit.h"
#include "../crc32.h"
#include "../crc64_ecma.h"
#include "../endian.h"

namespace
{
  SUITE(test_crc)
  {
    //*************************************************************************
    TEST(test_crc8_ccitt_constructor)
    {
      std::string data("123456789");

      uint8_t crc = etl::crc8_ccitt<>(data.begin(), data.end());

      CHECK_EQUAL(0xF4, int(crc));
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_values)
    {
      std::string data("123456789");

      etl::crc8_ccitt<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint8_t crc = crc_calculator;

      CHECK_EQUAL(0xF4, crc);
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_range)
    {
      std::string data("123456789");

      etl::crc8_ccitt<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint8_t crc = crc_calculator.value();

      CHECK_EQUAL(0xF4, crc);
    }

    //*************************************************************************
    TEST(test_crc8_ccitt_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint8_t crc1 = etl::crc8_ccitt<etl::endian::little>(data1.begin(), data1.end());
      uint8_t crc2 = etl::crc8_ccitt<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(int(crc1), int(crc2));

      uint8_t crc3 = etl::crc8_ccitt<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(int(crc1), int(crc3));
    }

    //*************************************************************************
    TEST(test_crc16)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16<>(data.begin(), data.end());

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_values)
    {
      std::string data("123456789");

      etl::crc16<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_range)
    {
      std::string data("123456789");

      etl::crc16<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0xBB3D, crc);
    }

    //*************************************************************************
    TEST(test_crc16_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16_ccitt<>(data.begin(), data.end());

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_values)
    {
      std::string data("123456789");

      etl::crc16_ccitt<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_range)
    {
      std::string data("123456789");

      etl::crc16_ccitt<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0x29B1, crc);
    }

    //*************************************************************************
    TEST(test_crc16_ccitt_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16_ccitt<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16_ccitt<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16_ccitt<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc16_kermit)
    {
      std::string data("123456789");

      uint16_t crc = etl::crc16_kermit<>(data.begin(), data.end());

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_values)
    {
      std::string data("123456789");

      etl::crc16_kermit<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint16_t crc = crc_calculator;

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_range)
    {
      std::string data("123456789");

      etl::crc16_kermit<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint16_t crc = crc_calculator.value();

      CHECK_EQUAL(0x2189, crc);
    }

    //*************************************************************************
    TEST(test_crc16_kermit_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint16_t crc1 = etl::crc16_kermit<etl::endian::little>(data1.begin(), data1.end());
      uint16_t crc2 = etl::crc16_kermit<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint16_t crc3 = etl::crc16_kermit<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc32)
    {
      std::string data("123456789");

      uint32_t crc = etl::crc32<>(data.begin(), data.end());

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_values)
    {
      std::string data("123456789");

      etl::crc32<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint32_t crc = crc_calculator;

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_range)
    {
      std::string data("123456789");

      etl::crc32<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint32_t crc = crc_calculator.value();

      CHECK_EQUAL(0xCBF43926, crc);
    }

    //*************************************************************************
    TEST(test_crc32_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint32_t crc1 = etl::crc32<etl::endian::little>(data1.begin(), data1.end());
      uint32_t crc2 = etl::crc32<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint32_t crc3 = etl::crc32<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }

    //*************************************************************************
    TEST(test_crc64_ecma)
    {
      std::string data("123456789");

      uint64_t crc = etl::crc64_ecma<>(data.begin(), data.end());

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_values)
    {
      std::string data("123456789");

      etl::crc64_ecma<> crc_calculator;

      for (size_t i = 0; i < data.size(); ++i)
      {
        crc_calculator += data[i];
      }

      uint64_t crc = crc_calculator;

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_range)
    {
      std::string data("123456789");

      etl::crc64_ecma<> crc_calculator;

      crc_calculator.add(data.begin(), data.end());

      uint64_t crc = crc_calculator.value();

      CHECK_EQUAL(0x6C40DF5F0B497347, crc);
    }

    //*************************************************************************
    TEST(test_crc64_ecma_add_range_endian)
    {
      std::vector<uint8_t>  data1 = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
      std::vector<uint32_t> data2 = { 0x04030201, 0x08070605 };
      std::vector<uint32_t> data3 = { 0x01020304, 0x05060708 };

      uint64_t crc1 = etl::crc64_ecma<etl::endian::little>(data1.begin(), data1.end());
      uint64_t crc2 = etl::crc64_ecma<etl::endian::little>(data2.begin(), data2.end());
      CHECK_EQUAL(crc1, crc2);

      uint64_t crc3 = etl::crc64_ecma<etl::endian::big>(data3.begin(), data3.end());
      CHECK_EQUAL(crc1, crc3);
    }
  };
}

<|endoftext|>


<commit_before>#include "BenchmarkStack.h"
#include "StackAllocator.h"

BenchmarkStack::BenchmarkStack(const int runtime)
	: Benchmark(runtime) {
}

BenchmarkResults BenchmarkStack::allocation() {
	setStartTimer();

	StackAllocator stackAllocator(1e10);

	int operations = 0;
	while(!outOfTime()){
		stackAllocator.Allocate(sizeof(int), alignof(int));			// 4  -> 4
		stackAllocator.Allocate(sizeof(bool), alignof(bool));		// 1  -> 5
																	// 3  -> 8
		stackAllocator.Allocate(sizeof(foo), alignof(foo));			// 16 -> 24

		++operations;
	}

	BenchmarkResults results = buildResults(operations, m_runtime, 0, 0);

	printResults(results);
	stackAllocator.Reset();
	return results;
}

BenchmarkResults BenchmarkStack::freeing() {
	return buildResults(0, 0, 0, 0);
}

BenchmarkResults BenchmarkStack::read() {
	return buildResults(0, 0, 0, 0);
}

BenchmarkResults BenchmarkStack::write() {
	return buildResults(0, 0, 0, 0);
}

BenchmarkResults BenchmarkStack::all() {
	return buildResults(0, 0, 0, 0);
}<commit_msg>Added freeing benchmark<commit_after>#include "BenchmarkStack.h"
#include "StackAllocator.h"

BenchmarkStack::BenchmarkStack(const int runtime)
	: Benchmark(runtime) {
}

BenchmarkResults BenchmarkStack::allocation() {
	setStartTimer();

	StackAllocator stackAllocator(1e10);

	int operations = 0;
	while(!outOfTime()){
		stackAllocator.Allocate(sizeof(int), alignof(int));			// 4  -> 4
		stackAllocator.Allocate(sizeof(bool), alignof(bool));		// 1  -> 5
																	// 3  -> 8
		stackAllocator.Allocate(sizeof(foo), alignof(foo));			// 16 -> 24

		++operations;
	}

	BenchmarkResults results = buildResults(operations, m_runtime, 0, 0);

	printResults(results);
	stackAllocator.Reset();
	return results;
}

BenchmarkResults BenchmarkStack::freeing() {
	setStartTimer();

	StackAllocator stackAllocator(1e10);

	std::size_t operations = 0;
	double elapsedTime = 0;
	while(elapsedTime < (m_runtime * 1e3)){
		if (operations % 2 == 0){
			stackAllocator.Allocate(sizeof(int), alignof(int));			// 4  -> 4
			stackAllocator.Allocate(sizeof(bool), alignof(bool));		// 1  -> 5
																	// 3  -> 8
			stackAllocator.Allocate(sizeof(foo), alignof(foo));			// 16 -> 24
		}else {
			timespec before_free, after_free;
			setTimer(before_free);
			stackAllocator.Free(sizeof(foo));
			stackAllocator.Free(sizeof(bool));
			stackAllocator.Free(sizeof(int));
			setTimer(after_free);
			elapsedTime += calculateElapsedTime(before_free, after_free);
		}
		++operations;
	}

	BenchmarkResults results = buildResults(operations/2, m_runtime, 0, 0);

	printResults(results);
	stackAllocator.Reset();
	return results;}

BenchmarkResults BenchmarkStack::read() {
	return buildResults(0, 0, 0, 0);
}

BenchmarkResults BenchmarkStack::write() {
	return buildResults(0, 0, 0, 0);
}

BenchmarkResults BenchmarkStack::all() {
	return buildResults(0, 0, 0, 0);
}<|endoftext|>


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

#ifndef SD_ASYNCHRONOUS_TASK_HXX
#define SD_ASYNCHRONOUS_TASK_HXX

namespace sd { namespace tools {

/** Interface for the asynchronous execution of a task.  This interface
    allows an controller to run the task either timer based with a fixed
    amount of time between the steps or thread based one step right after
    the other.
*/
class AsynchronousTask
{
public:
    /** Run the next step of the task.  After HasNextStep() returns false
        this method should ignore further calls.
    */
    virtual void RunNextStep (void) = 0;

    /** Return <TRUE/> when there is at least one more step to execute.
        When the task has been executed completely then <FALSE/> is
        returned.
    */
    virtual bool HasNextStep (void) = 0;
};

} } // end of namespace ::sd::tools

#endif
<commit_msg>INTEGRATION: CWS changefileheader (1.2.452); FILE MERGED 2008/03/31 13:58:41 rt 1.2.452.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: AsynchronousTask.hxx,v $
 * $Revision: 1.3 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org 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 version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

#ifndef SD_ASYNCHRONOUS_TASK_HXX
#define SD_ASYNCHRONOUS_TASK_HXX

namespace sd { namespace tools {

/** Interface for the asynchronous execution of a task.  This interface
    allows an controller to run the task either timer based with a fixed
    amount of time between the steps or thread based one step right after
    the other.
*/
class AsynchronousTask
{
public:
    /** Run the next step of the task.  After HasNextStep() returns false
        this method should ignore further calls.
    */
    virtual void RunNextStep (void) = 0;

    /** Return <TRUE/> when there is at least one more step to execute.
        When the task has been executed completely then <FALSE/> is
        returned.
    */
    virtual bool HasNextStep (void) = 0;
};

} } // end of namespace ::sd::tools

#endif
<|endoftext|>


<commit_before>// Copyright (c) 2010 The Native Client Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/proxy/plugin_file_ref.h"

#include "native_client/src/include/portability.h"
#include "ppapi/proxy/plugin_globals.h"

namespace ppapi_proxy {

namespace {
PP_Resource Create(PP_Resource file_system, const char* path) {
  UNREFERENCED_PARAMETER(file_system);
  UNREFERENCED_PARAMETER(path);
  return kInvalidResourceId;
}

PP_Resource CreateTemporaryFileRef(PP_Instance instance,
                                   const char* path) {
  UNREFERENCED_PARAMETER(instance);
  UNREFERENCED_PARAMETER(path);
  return kInvalidResourceId;
}

bool IsFileRef(PP_Resource resource) {
  UNREFERENCED_PARAMETER(resource);
  return false;
}

PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_FILESYSTEMTYPE_EXTERNAL;
}

PP_Var GetName(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_MakeUndefined();
}

PP_Var GetPath(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_MakeUndefined();
}

PP_Resource GetParent(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return kInvalidResourceId;
}
}  // namespace

const PPB_FileRef_Dev* PluginFileRef::GetInterface() {
  static const PPB_FileRef_Dev intf = {
    Create,
    IsFileRef,
    GetFileSystemType,
    GetName,
    GetPath,
    GetParent
  };
  return &intf;
}
}  // namespace ppapi_proxy
<commit_msg>Remove an unused function I forgot to remove. Clang complains about it...<commit_after>// Copyright (c) 2010 The Native Client Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ppapi/proxy/plugin_file_ref.h"

#include "native_client/src/include/portability.h"
#include "ppapi/proxy/plugin_globals.h"

namespace ppapi_proxy {

namespace {
PP_Resource Create(PP_Resource file_system, const char* path) {
  UNREFERENCED_PARAMETER(file_system);
  UNREFERENCED_PARAMETER(path);
  return kInvalidResourceId;
}

bool IsFileRef(PP_Resource resource) {
  UNREFERENCED_PARAMETER(resource);
  return false;
}

PP_FileSystemType_Dev GetFileSystemType(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_FILESYSTEMTYPE_EXTERNAL;
}

PP_Var GetName(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_MakeUndefined();
}

PP_Var GetPath(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return PP_MakeUndefined();
}

PP_Resource GetParent(PP_Resource file_ref) {
  UNREFERENCED_PARAMETER(file_ref);
  return kInvalidResourceId;
}
}  // namespace

const PPB_FileRef_Dev* PluginFileRef::GetInterface() {
  static const PPB_FileRef_Dev intf = {
    Create,
    IsFileRef,
    GetFileSystemType,
    GetName,
    GetPath,
    GetParent
  };
  return &intf;
}
}  // namespace ppapi_proxy
<|endoftext|>


<commit_before>/*

Copyright (c) 2012, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/config.hpp"
#include "libtorrent/rss.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/http_parser.hpp"

#include "test.hpp"

using namespace libtorrent;

void print_feed(feed_status const& f)
{
	fprintf(stderr, "FEED: %s\n",f.url.c_str());
	if (f.error)
		fprintf(stderr, "ERROR: %s\n", f.error.message().c_str());

	fprintf(stderr, "   %s\n   %s\n", f.title.c_str(), f.description.c_str());
	fprintf(stderr, "   ttl: %d minutes\n", f.ttl);
	fprintf(stderr, "   num items: %d\n", int(f.items.size()));

	for (std::vector<feed_item>::const_iterator i = f.items.begin()
		, end(f.items.end()); i != end; ++i)
	{
		fprintf(stderr, "\033[32m%s\033[0m\n------------------------------------------------------\n"
			"   url: %s\n   size: %"PRId64"\n   info-hash: %s\n   uuid: %s\n   description: %s\n"
			"   comment: %s\n   category: %s\n"
			, i->title.c_str(), i->url.c_str(), i->size
			, i->info_hash.is_all_zeros() ? "" : to_hex(i->info_hash.to_string()).c_str()
			, i->uuid.c_str(), i->description.c_str(), i->comment.c_str(), i->category.c_str());
	}
}

struct rss_expect
{
	rss_expect(int nitems, std::string url, std::string title, size_type size)
		: num_items(nitems), first_url(url), first_title(title), first_size(size)
	{}

	int num_items;
	std::string first_url;
	std::string first_title;
	size_type first_size;
};

void test_feed(std::string const& filename, rss_expect const& expect)
{
	std::vector<char> buffer;
	error_code ec;
	load_file(filename, buffer, ec);
	if (ec)
	{
		fprintf(stderr, "failed to load file \"%s\": %s\n", filename.c_str(), ec.message().c_str());
	}
	TEST_CHECK(!ec);

	char* buf = buffer.size() ? &buffer[0] : NULL;
	int len = buffer.size();

	char const header[] = "HTTP/1.1 200 OK\r\n"
		"\r\n";

	boost::shared_ptr<aux::session_impl> s = boost::shared_ptr<aux::session_impl>(new aux::session_impl(
		std::make_pair(100, 200), fingerprint("TT", 0, 0, 0 ,0), NULL, 0));
	s->start_session();

	feed_settings sett;
	sett.auto_download = false;
	sett.auto_map_handles = false;
	boost::shared_ptr<feed> f = boost::shared_ptr<feed>(new feed(*s, sett));
	http_parser parser;
	bool err = false;
	parser.incoming(buffer::const_interval(header, header + sizeof(header)-1), err);
	TEST_CHECK(err == false);

	f->on_feed(error_code(), parser, buf, len);

	feed_status st;
	f->get_feed_status(&st);
	TEST_CHECK(!st.error);

	print_feed(st);

	TEST_CHECK(st.items.size() == expect.num_items);
	if (st.items.size() > 0)
	{
		TEST_CHECK(st.items[0].url == expect.first_url);
		TEST_CHECK(st.items[0].size == expect.first_size);
		TEST_CHECK(st.items[0].title == expect.first_title);
	}

	entry state;
	f->save_state(state);

	fprintf(stderr, "feed_state:\n");
#ifdef TORRENT_DEBUG
	state.print(std::cerr);
#endif

	// TODO: verify some key state is saved in 'state'
}

int test_main()
{
	test_feed(combine_path("..", "eztv.xml"), rss_expect(30, "http://torrent.zoink.it/The.Daily.Show.2012.02.16.(HDTV-LMAO)[VTV].torrent", "The Daily Show 2012-02-16 [HDTV - LMAO]", 183442338));
	test_feed(combine_path("..", "cb.xml"), rss_expect(50, "http://www.clearbits.net/get/1911-norbergfestival-2011.torrent", "Norbergfestival 2011", 1160773632));
	test_feed(combine_path("..", "kat.xml"), rss_expect(25, "http://kat.ph/torrents/benito-di-paula-1975-benito-di-paula-lp-rip-ogg-at-500-jarax4u-t6194897/", "Benito Di Paula - 1975 - Benito Di Paula (LP Rip OGG at 500) [jarax4u]", 168773863));
	test_feed(combine_path("..", "mn.xml"), rss_expect(20, "http://www.mininova.org/get/13203100", "Dexcell - January TwentyTwelve Mix", 137311179));
	test_feed(combine_path("..", "pb.xml"), rss_expect(60, "magnet:?xt=urn:btih:FD4CDDB7BBE722D17A018EFD875EB0695ED7159C&dn=Thompson+Twins+-+1989+-+Big+Trash+%5BMP3%5D", "Thompson Twins - 1989 - Big Trash [MP3]", 100160904));
	return 0;
}

<commit_msg>fix test_rss for windows<commit_after>/*

Copyright (c) 2012, Arvid Norberg
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer in
      the documentation and/or other materials provided with the distribution.
    * Neither the name of the author nor the names of its
      contributors may be used to endorse or promote products derived
      from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.

*/

#include "libtorrent/config.hpp"
#include "libtorrent/rss.hpp"
#include "libtorrent/fingerprint.hpp"
#include "libtorrent/aux_/session_impl.hpp"
#include "libtorrent/http_parser.hpp"

#include "test.hpp"

using namespace libtorrent;

void print_feed(feed_status const& f)
{
	fprintf(stderr, "FEED: %s\n",f.url.c_str());
	if (f.error)
		fprintf(stderr, "ERROR: %s\n", f.error.message().c_str());

	fprintf(stderr, "   %s\n   %s\n", f.title.c_str(), f.description.c_str());
	fprintf(stderr, "   ttl: %d minutes\n", f.ttl);
	fprintf(stderr, "   num items: %d\n", int(f.items.size()));

	for (std::vector<feed_item>::const_iterator i = f.items.begin()
		, end(f.items.end()); i != end; ++i)
	{
		fprintf(stderr, "\033[32m%s\033[0m\n------------------------------------------------------\n"
			"   url: %s\n   size: %"PRId64"\n   info-hash: %s\n   uuid: %s\n   description: %s\n"
			"   comment: %s\n   category: %s\n"
			, i->title.c_str(), i->url.c_str(), i->size
			, i->info_hash.is_all_zeros() ? "" : to_hex(i->info_hash.to_string()).c_str()
			, i->uuid.c_str(), i->description.c_str(), i->comment.c_str(), i->category.c_str());
	}
}

struct rss_expect
{
	rss_expect(int nitems, std::string url, std::string title, size_type size)
		: num_items(nitems), first_url(url), first_title(title), first_size(size)
	{}

	int num_items;
	std::string first_url;
	std::string first_title;
	size_type first_size;
};

void test_feed(std::string const& filename, rss_expect const& expect)
{
	std::vector<char> buffer;
	error_code ec;
	load_file(filename, buffer, ec);
	if (ec)
	{
		fprintf(stderr, "failed to load file \"%s\": %s\n", filename.c_str(), ec.message().c_str());
	}
	TEST_CHECK(!ec);

	char* buf = buffer.size() ? &buffer[0] : NULL;
	int len = buffer.size();

	char const header[] = "HTTP/1.1 200 OK\r\n"
		"\r\n";

	boost::shared_ptr<aux::session_impl> s = boost::shared_ptr<aux::session_impl>(new aux::session_impl(
		std::make_pair(100, 200), fingerprint("TT", 0, 0, 0 ,0), NULL, 0));
	s->start_session();

	feed_settings sett;
	sett.auto_download = false;
	sett.auto_map_handles = false;
	boost::shared_ptr<feed> f = boost::shared_ptr<feed>(new feed(*s, sett));
	http_parser parser;
	bool err = false;
	parser.incoming(buffer::const_interval(header, header + sizeof(header)-1), err);
	TEST_CHECK(err == false);

	f->on_feed(error_code(), parser, buf, len);

	feed_status st;
	f->get_feed_status(&st);
	TEST_CHECK(!st.error);

	print_feed(st);

	TEST_CHECK(st.items.size() == expect.num_items);
	if (st.items.size() > 0)
	{
		TEST_CHECK(st.items[0].url == expect.first_url);
		TEST_CHECK(st.items[0].size == expect.first_size);
		TEST_CHECK(st.items[0].title == expect.first_title);
	}

	entry state;
	f->save_state(state);

	fprintf(stderr, "feed_state:\n");
#ifdef TORRENT_DEBUG
	state.print(std::cerr);
#endif

	// TODO: verify some key state is saved in 'state'
}

int test_main()
{
	std::string root_dir = parent_path(current_working_directory());

	test_feed(combine_path(root_dir, "eztv.xml"), rss_expect(30, "http://torrent.zoink.it/The.Daily.Show.2012.02.16.(HDTV-LMAO)[VTV].torrent", "The Daily Show 2012-02-16 [HDTV - LMAO]", 183442338));
	test_feed(combine_path(root_dir, "cb.xml"), rss_expect(50, "http://www.clearbits.net/get/1911-norbergfestival-2011.torrent", "Norbergfestival 2011", 1160773632));
	test_feed(combine_path(root_dir, "kat.xml"), rss_expect(25, "http://kat.ph/torrents/benito-di-paula-1975-benito-di-paula-lp-rip-ogg-at-500-jarax4u-t6194897/", "Benito Di Paula - 1975 - Benito Di Paula (LP Rip OGG at 500) [jarax4u]", 168773863));
	test_feed(combine_path(root_dir, "mn.xml"), rss_expect(20, "http://www.mininova.org/get/13203100", "Dexcell - January TwentyTwelve Mix", 137311179));
	test_feed(combine_path(root_dir, "pb.xml"), rss_expect(60, "magnet:?xt=urn:btih:FD4CDDB7BBE722D17A018EFD875EB0695ED7159C&dn=Thompson+Twins+-+1989+-+Big+Trash+%5BMP3%5D", "Thompson Twins - 1989 - Big Trash [MP3]", 100160904));
	return 0;
}

<|endoftext|>


<commit_before>#ifndef DISSENT_CRYPTO_INTEGER_H_GUARD
#define DISSENT_CRYPTO_INTEGER_H_GUARD

#include <QByteArray>
#include <QSharedData>
#include <QString>
#include "Utils/Utils.hpp"

namespace Dissent {
namespace Crypto {
  class IIntegerImpl : public QSharedData {
    public:
      virtual ~IIntegerImpl() {}
      virtual QByteArray GetByteArray() const = 0;
      virtual bool IsPrime() const = 0;
      virtual IIntegerImpl *Add(const IIntegerImpl * const term) const = 0;
      virtual IIntegerImpl *Subtract(const IIntegerImpl * const subtrahend) const = 0;
      virtual IIntegerImpl *Multiply(const IIntegerImpl * const multiplicand) const = 0;
      virtual IIntegerImpl *Multiply(const IIntegerImpl * const multiplicand, const IIntegerImpl * const modulus) const = 0;
      virtual IIntegerImpl *Divide(const IIntegerImpl * const divisor) const = 0;
      virtual IIntegerImpl *Modulo(const IIntegerImpl * const mod) const = 0;
      virtual IIntegerImpl *Pow(const IIntegerImpl * const pow, const IIntegerImpl * const mod) const = 0;
      virtual IIntegerImpl *PowCascade(const IIntegerImpl * const x0, const IIntegerImpl * const e0,
          const IIntegerImpl * const x1, const IIntegerImpl * const e1) const = 0;
      virtual IIntegerImpl *Inverse(const IIntegerImpl * const mod) const = 0;
      virtual bool Equals(const IIntegerImpl * const other) const = 0;
      virtual bool LessThan(const IIntegerImpl * const other) const = 0;
      virtual bool LessThanOrEqual(const IIntegerImpl * const other) const = 0;
      virtual int GetBitCount() const = 0;
      virtual int GetByteCount() const = 0;
      virtual int GetInt32() const = 0;
  };

  /**
   * "Big" Integer wrapper
   */
  class Integer {
    public:
      /**
       * Construct using an int
       * @param value the int value
       */
      Integer(int value = 0);

      /**
       * Construct using an byte array
       * @param value the byte array
       */
      explicit Integer(const QByteArray &value);

      /**
       * Construct using a base64 string
       * @param value the string
       */
      explicit Integer(const QString &value);

      /**
       * Returns the byte array representation of the number
       */
      inline QByteArray GetByteArray() const
      {
        return m_data->GetByteArray();
      }

      /**
       * Returns the string representation
       */
      inline QString ToString() const
      {
        return Utils::ToUrlSafeBase64(m_data->GetByteArray());
      }

      /**
       * Returns true if integer is greater than zero and is prime
       */
      inline bool IsPrime() const
      {
        return m_data->IsPrime();
      }

      /**
       * Add operator, produces a new Integer
       * @param other the Integer to add
       */
      inline Integer Add(const Integer &term) const
      {
        return Integer(m_data->Add(term.m_data.constData()));
      }

      /**
       * Subtraction operator, produces a new Integer
       * @param other the Integer to subtract (subtrahend)
       */
      inline Integer Subtract(const Integer &subtrahend) const
      {
        return Integer(m_data->Subtract(subtrahend.m_data.constData()));
      }

      /**
       * Multiply operator, produces a new Integer
       * @param multiplicand the Integer to multiply this
       */
      inline Integer Multiply(const Integer &multiplicand) const
      {
        return Integer(m_data->Multiply(multiplicand.m_data.constData()));
      }

      /**
       * Multiply operator with modulo, produces a new Integer
       * @param multiplicand multiplicand
       * @param mod modulus
       */
      Integer Multiply(const Integer &other, const Integer &mod) const
      {
        return Integer(m_data->Multiply(other.m_data.constData(),
              mod.m_data.constData()));
      }

      /**
       * Division operator, produces a new Integer
       * @param divisor the Integer to divide into this
       */
      inline Integer Divide(const Integer &divisor) const
      {
        return Integer(m_data->Divide(divisor.m_data.constData()));
      }

      /**
       * Modulo operator, produces a new Integer
       * @param modulus the modulus to use
       */
      inline Integer Modulo(const Integer &mod) const
      {
        return Integer(m_data->Modulo(mod.m_data.constData()));
      }

      /**
       * Exponentiating operator
       * @param pow raise this to other
       * @param mod modulus for the exponentiation
       */
      Integer Pow(const Integer &pow, const Integer &mod) const
      {
        return Integer(m_data->Pow(pow.m_data.constData(), mod.m_data.constData()));
      }

      /**
       * Cascade exponentiation modulo n
       * For integer n, compute ((x1^e1 * x2^e2) mod n)
       * This can be much faster than the naive way.
       * @param x1 first base
       * @param e1 first exponent
       * @param x2 second base
       * @param e2 second exponent
       */
      Integer PowCascade(const Integer &x1, const Integer &e1,
          const Integer &x2, const Integer &e2) const
      {
        return Integer(m_data->PowCascade(x1.m_data.constData(), e1.m_data.constData(),
            x2.m_data.constData(), e2.m_data.constData()));
      }

      /**
       * Compute x such that ax == 1 mod p
       * @param mod inverse modulo this group
       */
      Integer Inverse(const Integer &mod) const
      {
        return Integer(m_data->Inverse(mod.m_data.constData()));
      }

      /**
       * Assignment operator
       * @param other the other Integer
       */
      inline Integer &operator=(const Integer &other)
      {
        m_data = other.m_data;
        return *this;
      }

      /**
       * Add operator, adds to current
       * @param other the Integer to add
       */
      inline Integer &operator+=(const Integer &other)
      {
        m_data = Add(other).m_data;
        return *this;
      }

      /**
       * Subtraction operator, subtracts from current
       * @param other the Integer to subtract
       */
      Integer &operator-=(const Integer &other)
      {
        m_data = Subtract(other).m_data;
        return *this;
      }

      /**
       * Equality operator
       * @param other the Integer to compare
       */
      bool operator==(const Integer &other) const
      {
        return m_data->Equals(other.m_data.constData());
      }

      /**
       * Not qquality operator
       * @param other the Integer to compare
       */
      bool operator!=(const Integer &other) const
      {
        return ! m_data->Equals(other.m_data.constData());
      }

      /**
       * Greater than
       * @param other the Integer to compare
       */
      bool operator>(const Integer &other) const
      {
        return other.m_data->LessThan(m_data.constData());
      }

      /**
       * Greater than or equal
       * @param other the Integer to compare
       */
      bool operator>=(const Integer &other) const
      {
        return other.m_data->LessThanOrEqual(m_data.constData());
      }

      /**
       * Less than
       * @param other the Integer to compare
       */
      bool operator<(const Integer &other) const
      {
        return m_data->LessThan(other.m_data.constData());
      }

      /**
       * Less than or equal
       * @param other the Integer to compare
       */
      bool operator<=(const Integer &other) const
      {
        return m_data->LessThanOrEqual(other.m_data.constData());
      }

      /**
       * Returns the integer's count in bits
       */
      inline int GetBitCount() const
      {
        return m_data->GetBitCount();
      }

      /**
       * Returns the integer's count in bytes
       */
      inline int GetByteCount() const
      {
        return m_data->GetByteCount();
      }

      /**
       * Returns int32 rep
       */
      int GetInt32() const
      {
        return m_data->GetInt32();
      }

      Integer(IIntegerImpl *value) : m_data(value)
      {
      }

      const IIntegerImpl *GetHandle() const { return m_data.constData(); }

    private:
      QSharedDataPointer<IIntegerImpl> m_data;

      /**
       * Convert a base64 number into a clean byte array
       * @param string input base64 string
       */
      static QByteArray FromBase64(const QString &string)
      {
        const QChar *chs = string.constData();
        QByteArray tmp;
        int idx = 0;
        for(; chs[idx] != '\0'; idx++) {
          tmp.append(chs[idx].cell());
        }

        return Utils::FromUrlSafeBase64(tmp);
      }
  };

  /**
   * Add operator, produces a new Integer
   * @param lhs first term
   * @param rhs second term
   */
  inline Integer operator+(const Integer &lhs, const Integer &rhs)
  {
    return Integer(lhs.Add(rhs));
  }

  /**
   * Subtraction operator, produces a new Integer
   * @param lhs minuend
   * @param rhs subtrahend
   */
  inline Integer operator-(const Integer &lhs, const Integer &rhs)
  {
    return Integer(lhs.Subtract(rhs));
  }

  /**
   * Multiplication operator, produces a new Integer
   * @param lhs left multiplicand
   * @param rhs right multiplicand
   */
  inline Integer operator*(const Integer &lhs, const Integer &rhs)
  {
    return lhs.Multiply(rhs);
  }

  /**
   * Division operator, produces a new Integer (quotient)
   * @param lhs dividend
   * @param rhs divisor
   */
  inline Integer operator/(const Integer &lhs, const Integer &rhs)
  {
    return lhs.Divide(rhs);
  }

  inline Integer operator%(const Integer &value, const Integer &mod)
  {
    return value.Modulo(mod);
  }

  /**
   * Serialize an Integer
   * @param stream where to store the serialized integer
   * @param value the integer to serialize
   */
  inline QDataStream &operator<<(QDataStream &stream, const Integer &value)
  {
    return stream << value.GetByteArray();
  }

  /**
   * Deserialize an integer
   * @param stream where to read data from
   * @param value where to store the deserialized integer
   */
  inline QDataStream &operator>>(QDataStream &stream, Integer &value)
  {
    QByteArray tvalue;
    stream >> tvalue;
    value = Integer(tvalue);
    return stream;
  }
}
}

#endif
<commit_msg>add missing inplace operators to Integer<commit_after>#ifndef DISSENT_CRYPTO_INTEGER_H_GUARD
#define DISSENT_CRYPTO_INTEGER_H_GUARD

#include <QByteArray>
#include <QSharedData>
#include <QString>
#include "Utils/Utils.hpp"

namespace Dissent {
namespace Crypto {
  class IIntegerImpl : public QSharedData {
    public:
      virtual ~IIntegerImpl() {}
      virtual QByteArray GetByteArray() const = 0;
      virtual bool IsPrime() const = 0;
      virtual IIntegerImpl *Add(const IIntegerImpl * const term) const = 0;
      virtual IIntegerImpl *Subtract(const IIntegerImpl * const subtrahend) const = 0;
      virtual IIntegerImpl *Multiply(const IIntegerImpl * const multiplicand) const = 0;
      virtual IIntegerImpl *Multiply(const IIntegerImpl * const multiplicand, const IIntegerImpl * const modulus) const = 0;
      virtual IIntegerImpl *Divide(const IIntegerImpl * const divisor) const = 0;
      virtual IIntegerImpl *Modulo(const IIntegerImpl * const mod) const = 0;
      virtual IIntegerImpl *Pow(const IIntegerImpl * const pow, const IIntegerImpl * const mod) const = 0;
      virtual IIntegerImpl *PowCascade(const IIntegerImpl * const x0, const IIntegerImpl * const e0,
          const IIntegerImpl * const x1, const IIntegerImpl * const e1) const = 0;
      virtual IIntegerImpl *Inverse(const IIntegerImpl * const mod) const = 0;
      virtual bool Equals(const IIntegerImpl * const other) const = 0;
      virtual bool LessThan(const IIntegerImpl * const other) const = 0;
      virtual bool LessThanOrEqual(const IIntegerImpl * const other) const = 0;
      virtual int GetBitCount() const = 0;
      virtual int GetByteCount() const = 0;
      virtual int GetInt32() const = 0;
  };

  /**
   * "Big" Integer wrapper
   */
  class Integer {
    public:
      /**
       * Construct using an int
       * @param value the int value
       */
      Integer(int value = 0);

      /**
       * Construct using an byte array
       * @param value the byte array
       */
      explicit Integer(const QByteArray &value);

      /**
       * Construct using a base64 string
       * @param value the string
       */
      explicit Integer(const QString &value);

      /**
       * Returns the byte array representation of the number
       */
      inline QByteArray GetByteArray() const
      {
        return m_data->GetByteArray();
      }

      /**
       * Returns the string representation
       */
      inline QString ToString() const
      {
        return Utils::ToUrlSafeBase64(m_data->GetByteArray());
      }

      /**
       * Returns true if integer is greater than zero and is prime
       */
      inline bool IsPrime() const
      {
        return m_data->IsPrime();
      }

      /**
       * Add operator, produces a new Integer
       * @param other the Integer to add
       */
      inline Integer Add(const Integer &term) const
      {
        return Integer(m_data->Add(term.m_data.constData()));
      }

      /**
       * Subtraction operator, produces a new Integer
       * @param other the Integer to subtract (subtrahend)
       */
      inline Integer Subtract(const Integer &subtrahend) const
      {
        return Integer(m_data->Subtract(subtrahend.m_data.constData()));
      }

      /**
       * Multiply operator, produces a new Integer
       * @param multiplicand the Integer to multiply this
       */
      inline Integer Multiply(const Integer &multiplicand) const
      {
        return Integer(m_data->Multiply(multiplicand.m_data.constData()));
      }

      /**
       * Multiply operator with modulo, produces a new Integer
       * @param multiplicand multiplicand
       * @param mod modulus
       */
      Integer Multiply(const Integer &other, const Integer &mod) const
      {
        return Integer(m_data->Multiply(other.m_data.constData(),
              mod.m_data.constData()));
      }

      /**
       * Division operator, produces a new Integer
       * @param divisor the Integer to divide into this
       */
      inline Integer Divide(const Integer &divisor) const
      {
        return Integer(m_data->Divide(divisor.m_data.constData()));
      }

      /**
       * Modulo operator, produces a new Integer
       * @param modulus the modulus to use
       */
      inline Integer Modulo(const Integer &mod) const
      {
        return Integer(m_data->Modulo(mod.m_data.constData()));
      }

      /**
       * Exponentiating operator
       * @param pow raise this to other
       * @param mod modulus for the exponentiation
       */
      Integer Pow(const Integer &pow, const Integer &mod) const
      {
        return Integer(m_data->Pow(pow.m_data.constData(), mod.m_data.constData()));
      }

      /**
       * Cascade exponentiation modulo n
       * For integer n, compute ((x1^e1 * x2^e2) mod n)
       * This can be much faster than the naive way.
       * @param x1 first base
       * @param e1 first exponent
       * @param x2 second base
       * @param e2 second exponent
       */
      Integer PowCascade(const Integer &x1, const Integer &e1,
          const Integer &x2, const Integer &e2) const
      {
        return Integer(m_data->PowCascade(x1.m_data.constData(), e1.m_data.constData(),
            x2.m_data.constData(), e2.m_data.constData()));
      }

      /**
       * Compute x such that ax == 1 mod p
       * @param mod inverse modulo this group
       */
      Integer Inverse(const Integer &mod) const
      {
        return Integer(m_data->Inverse(mod.m_data.constData()));
      }

      /**
       * Assignment operator
       * @param other the other Integer
       */
      inline Integer &operator=(const Integer &other)
      {
        m_data = other.m_data;
        return *this;
      }

      /**
       * Add operator, adds to current
       * @param other the Integer to add
       */
      inline Integer &operator+=(const Integer &other)
      {
        m_data = Add(other).m_data;
        return *this;
      }

      /**
       * Subtraction operator, subtracts from current
       * @param other the Integer to subtract
       */
      Integer &operator-=(const Integer &other)
      {
        m_data = Subtract(other).m_data;
        return *this;
      }

      /**
       * Multiplication operator, multiplies with current
       * @param other the Integer to multiply by
       */
      Integer &operator*=(const Integer &other)
      {
        m_data = Multiply(other).m_data;
        return *this;
      }

      /**
       * Division operator, divides current
       * @param other the Integer to divide by
       */
      Integer &operator/=(const Integer &other)
      {
        m_data = Divide(other).m_data;
        return *this;
      }

      /**
       * Remainder operator, computes the remainder of current
       * @param other the Integer representing the modulus
       */
      Integer &operator%=(const Integer &modulus)
      {
        m_data = Modulo(modulus).m_data;
        return *this;
      }

      /**
       * Equality operator
       * @param other the Integer to compare
       */
      bool operator==(const Integer &other) const
      {
        return m_data->Equals(other.m_data.constData());
      }

      /**
       * Not qquality operator
       * @param other the Integer to compare
       */
      bool operator!=(const Integer &other) const
      {
        return ! m_data->Equals(other.m_data.constData());
      }

      /**
       * Greater than
       * @param other the Integer to compare
       */
      bool operator>(const Integer &other) const
      {
        return other.m_data->LessThan(m_data.constData());
      }

      /**
       * Greater than or equal
       * @param other the Integer to compare
       */
      bool operator>=(const Integer &other) const
      {
        return other.m_data->LessThanOrEqual(m_data.constData());
      }

      /**
       * Less than
       * @param other the Integer to compare
       */
      bool operator<(const Integer &other) const
      {
        return m_data->LessThan(other.m_data.constData());
      }

      /**
       * Less than or equal
       * @param other the Integer to compare
       */
      bool operator<=(const Integer &other) const
      {
        return m_data->LessThanOrEqual(other.m_data.constData());
      }

      /**
       * Returns the integer's count in bits
       */
      inline int GetBitCount() const
      {
        return m_data->GetBitCount();
      }

      /**
       * Returns the integer's count in bytes
       */
      inline int GetByteCount() const
      {
        return m_data->GetByteCount();
      }

      /**
       * Returns int32 rep
       */
      int GetInt32() const
      {
        return m_data->GetInt32();
      }

      Integer(IIntegerImpl *value) : m_data(value)
      {
      }

      const IIntegerImpl *GetHandle() const { return m_data.constData(); }

    private:
      QSharedDataPointer<IIntegerImpl> m_data;

      /**
       * Convert a base64 number into a clean byte array
       * @param string input base64 string
       */
      static QByteArray FromBase64(const QString &string)
      {
        const QChar *chs = string.constData();
        QByteArray tmp;
        int idx = 0;
        for(; chs[idx] != '\0'; idx++) {
          tmp.append(chs[idx].cell());
        }

        return Utils::FromUrlSafeBase64(tmp);
      }
  };

  /**
   * Add operator, produces a new Integer
   * @param lhs first term
   * @param rhs second term
   */
  inline Integer operator+(const Integer &lhs, const Integer &rhs)
  {
    return Integer(lhs.Add(rhs));
  }

  /**
   * Subtraction operator, produces a new Integer
   * @param lhs minuend
   * @param rhs subtrahend
   */
  inline Integer operator-(const Integer &lhs, const Integer &rhs)
  {
    return Integer(lhs.Subtract(rhs));
  }

  /**
   * Multiplication operator, produces a new Integer
   * @param lhs left multiplicand
   * @param rhs right multiplicand
   */
  inline Integer operator*(const Integer &lhs, const Integer &rhs)
  {
    return lhs.Multiply(rhs);
  }

  /**
   * Division operator, produces a new Integer (quotient)
   * @param lhs dividend
   * @param rhs divisor
   */
  inline Integer operator/(const Integer &lhs, const Integer &rhs)
  {
    return lhs.Divide(rhs);
  }

  inline Integer operator%(const Integer &value, const Integer &mod)
  {
    return value.Modulo(mod);
  }

  /**
   * Serialize an Integer
   * @param stream where to store the serialized integer
   * @param value the integer to serialize
   */
  inline QDataStream &operator<<(QDataStream &stream, const Integer &value)
  {
    return stream << value.GetByteArray();
  }

  /**
   * Deserialize an integer
   * @param stream where to read data from
   * @param value where to store the deserialized integer
   */
  inline QDataStream &operator>>(QDataStream &stream, Integer &value)
  {
    QByteArray tvalue;
    stream >> tvalue;
    value = Integer(tvalue);
    return stream;
  }
}
}

#endif
<|endoftext|>


<commit_before>#include <ros/ros.h>
#include <quirkd/Alert.h>
#include <nav_msgs/GetMap.h>
#include <sensor_msgs/LaserScan.h>

class DataController {
    public:
        DataController() {
            alert_pub_ = n_.advertise<quirkd::Alert>("/quirkd/alert/notification", 1);
            laser_sub_ = n_.subscribe("/base_scan", 1, &DataController::laserScanCB, this);
            static_map_client_ = n_.serviceClient<nav_msgs::GetMap>("static_map");
            dynamic_map_client_ = n_.serviceClient<nav_msgs::GetMap>("dynamic_map");
        }
        void laserScanCB(const sensor_msgs::LaserScan msg) {
            ROS_INFO("Laser Scan Callback");
            updated = true;
            last_data = msg;
        }
        void update() {
            ROS_INFO("Update Data Processor");
            nav_msgs::GetMap srv;
            if (static_map_client_.call(srv)) {
                ROS_INFO("Successfull call static map");
            } else {
                ROS_WARN("Failed to get static map");
            }
            if (dynamic_map_client_.call(srv)) {
                ROS_INFO("Successfull call dynamic map");
            } else {
                ROS_WARN("Failed to get dynamic map");
            }
            updated = false;
        }
        void pub_alert_status() {
            quirkd::Alert msg;
            alert_pub_.publish(msg);
        }
        bool updated;
        sensor_msgs::LaserScan last_data;
    private:
        ros::NodeHandle n_;
        ros::Publisher alert_pub_;
        ros::Subscriber laser_sub_;
        ros::ServiceClient dynamic_map_client_;
        ros::ServiceClient static_map_client_;
};

int main(int argc, char** argv) {
    ros::init(argc, argv, "DataController");
    ROS_INFO("1");
    DataController dp;
    ROS_INFO("2");
    dp.updated = false;
    ROS_INFO("3");
    ros::Rate r(30);
    ROS_INFO("4");
    dp.update();
    while(ros::ok()) {
        ros::spinOnce();
        if (dp.updated) {
            dp.update();
            ROS_INFO("Processed message data in loop");
        }
        dp.pub_alert_status();
        r.sleep();
    }
    ROS_INFO("Data Processor Exited.");
    return 0;
}
<commit_msg>DC gets callback, updates, makes the service calls<commit_after>#include <ros/ros.h>

#include <nav_msgs/GetMap.h>
#include <quirkd/Alert.h>
#include <sensor_msgs/LaserScan.h>
#include <tf/transform_listener.h>

class DataController {
    public:
        DataController() {
            alert_pub_ = n_.advertise<quirkd::Alert>("/quirkd/alert/notification", 1);
            laser_sub_ = n_.subscribe("/base_scan", 1, &DataController::laserScanCB, this);
            // ros::service::waitForService("static_map");
            static_map_client_ = n_.serviceClient<nav_msgs::GetMap>("static_map");
            // ros::service::waitForService("dynamic_map");
            dynamic_map_client_ = n_.serviceClient<nav_msgs::GetMap>("dynamic_map");
        }
        void laserScanCB(const sensor_msgs::LaserScan msg) {
            ROS_INFO("Laser Scan Callback");
            updated = true;
            last_data = msg;
            try {
                tf_.lookupTransform("/map", "/base_laser_link", ros::Time(0), last_tf);
            } catch (tf::TransformException &ex) {
                ROS_WARN("tf fetch failed. %s", ex.what());
            }
        }
        void update() {
            ROS_INFO("Update Data Processor");
            nav_msgs::GetMap srv;
            if (static_map_client_.call(srv)) {
                ROS_INFO("Successfull call static map");
            } else {
                ROS_WARN("Failed to get static map");
            }
            if (dynamic_map_client_.call(srv)) {
                ROS_INFO("Successfull call dynamic map");
            } else {
                ROS_WARN("Failed to get dynamic map");
            }
            updated = false;
        }
        void pub_alert_status() {
            quirkd::Alert msg;
            alert_pub_.publish(msg);
        }
        bool updated;
        sensor_msgs::LaserScan last_data;
        tf::StampedTransform last_tf;
    private:
        ros::NodeHandle n_;
        ros::Publisher alert_pub_;
        ros::Subscriber laser_sub_;
        ros::ServiceClient dynamic_map_client_;
        ros::ServiceClient static_map_client_;
        tf::TransformListener tf_;
};

int main(int argc, char** argv) {
    ros::init(argc, argv, "DataController");
    ROS_INFO("1");
    DataController dp;
    ROS_INFO("2");
    dp.updated = false;
    ROS_INFO("3");
    ros::Rate r(30);
    ROS_INFO("4");
    dp.update();
    while(ros::ok()) {
        ros::spinOnce();
        if (dp.updated) {
            dp.update();
            ROS_INFO("Processed message data in loop");
        }
        dp.pub_alert_status();
        r.sleep();
    }
    ROS_INFO("Data Processor Exited.");
    return 0;
}
<|endoftext|>