text:
#include <stdlib.h>
#include <stdio.h>
#include <omp.h>
#include <chrono>
#include <vector>
#include <string>
#include <sstream>
#include <iostream>
#include <stdexcept>
#include <Eigen/Geometry>
#include <visualization_msgs/Marker.h>
#include <arc_utilities/eigen_helpers.hpp>
#include <arc_utilities/voxel_grid.hpp>
#include <arc_utilities/pretty_print.hpp>
#include <sdf_tools/sdf.hpp>

#ifndef SDF_GENERATION_HPP
#define SDF_GENERATION_HPP

namespace sdf_generation
{
struct bucket_cell
{
  double distance_square;
  int32_t update_direction;
  uint32_t location[3];
  uint32_t closest_point[3];
};

typedef VoxelGrid::VoxelGrid<bucket_cell> DistanceField;

inline int32_t GetDirectionNumber(
    const int32_t dx, const int32_t dy, const int32_t dz)
{
  return ((dx + 1) * 9) + ((dy + 1) * 3) + (dz + 1);
}

inline std::vector<std::vector<std::vector<std::vector<int32_t>>>>
MakeNeighborhoods()
{
  // First vector<>: 2 - the first bucket queue, the points we know are zero
  // distance, start with a complete set of neighbors to check. Every other
  // bucket queue checks fewer neighbors.
  // Second vector<>: 27 (# of source directions in fully-connected 3d grid).
  // Third vector<>:
  std::vector<std::vector<std::vector<std::vector<int32_t>>>> neighborhoods;
  // I don't know why there are 2 initial neighborhoods.
  neighborhoods.resize(2);
  for (size_t n = 0; n < neighborhoods.size(); n++)
  {
    neighborhoods[n].resize(27);
    // Loop through the source directions.
    for (int32_t dx = -1; dx <= 1; dx++)
    {
      for (int32_t dy = -1; dy <= 1; dy++)
      {
        for (int32_t dz = -1; dz <= 1; dz++)
        {
          const int32_t direction_number = GetDirectionNumber(dx, dy, dz);
          // Loop through the target directions.
          for (int32_t tdx = -1; tdx <= 1; tdx++)
          {
            for (int32_t tdy = -1; tdy <= 1; tdy++)
            {
              for (int32_t tdz = -1; tdz <= 1; tdz++)
              {
                // Ignore the case of ourself.
                if (tdx == 0 && tdy == 0 && tdz == 0)
                {
                  continue;
                }
                // Why is one set of neighborhoods larger than the other?
                if (n >= 1)
                {
                  if ((abs(tdx) + abs(tdy) + abs(tdz)) != 1)
                  {
                    continue;
                  }
                  if ((dx * tdx) < 0 || (dy * tdy) < 0 || (dz * tdz) < 0)
                  {
                    continue;
                  }
                }
                std::vector<int32_t> new_point;
                new_point.resize(3);
                new_point[0] = tdx;
                new_point[1] = tdy;
                new_point[2] = tdz;
                neighborhoods[n][direction_number].push_back(new_point);
              }
            }
          }
        }
      }
    }
  }
  return neighborhoods;
}

inline double ComputeDistanceSquared(
    const int32_t x1, const int32_t y1, const int32_t z1,
    const int32_t x2, const int32_t y2, const int32_t z2)
{
  const int32_t dx = x1 - x2;
  const int32_t dy = y1 - y2;
  const int32_t dz = z1 - z2;
  return double((dx * dx) + (dy * dy) + (dz * dz));
}

class MultipleThreadIndexQueueWrapper
{
public:

  explicit MultipleThreadIndexQueueWrapper(const size_t max_queues)
  {
    per_thread_queues_.resize(
          GetNumOMPThreads(), ThreadIndexQueues(max_queues));
  }

  const VoxelGrid::GRID_INDEX& Query(
      const int32_t distance_squared, const size_t idx) const
  {
    size_t working_index = idx;
    for (size_t thread = 0; thread < per_thread_queues_.size(); thread++)
    {
      const auto& current_thread_queue =
          per_thread_queues_.at(thread).at(distance_squared);
      const size_t current_thread_queue_size = current_thread_queue.size();
      if (working_index < current_thread_queue_size)
      {
        return current_thread_queue.at(working_index);
      }
      else
      {
        working_index -= current_thread_queue_size;
      }
    }
    throw std::runtime_error("Failed to find item");
  }

  size_t NumQueues() const
  {
    return per_thread_queues_.at(0).size();
  }

  size_t Size(const int32_t distance_squared) const
  {
    size_t total_size = 0;
    for (size_t thread = 0; thread < per_thread_queues_.size(); thread++)
    {
      total_size += per_thread_queues_.at(thread).at(distance_squared).size();
    }
    return total_size;
  }

  void Enqueue(
      const int32_t distance_squared, const VoxelGrid::GRID_INDEX& index)
  {
#if defined(_OPENMP)
    const size_t thread_num = (size_t)omp_get_thread_num();
#else
    const size_t thread_num = 0;
#endif
    per_thread_queues_.at(thread_num).at(distance_squared).push_back(index);
  }

  void ClearCompletedQueues(const int32_t distance_squared)
  {
    for (size_t thread = 0; thread < per_thread_queues_.size(); thread++)
    {
      per_thread_queues_.at(thread).at(distance_squared).clear();
    }
  }

private:

  inline static size_t GetNumOMPThreads()
  {
#if defined(_OPENMP)
    size_t num_threads = 0;
#pragma omp parallel
    {
      num_threads = (size_t)omp_get_num_threads();
    }
    return num_threads;
#else
    return 1;
#endif
  }

  typedef std::vector<std::vector<VoxelGrid::GRID_INDEX>> ThreadIndexQueues;
  std::vector<ThreadIndexQueues> per_thread_queues_;

};

inline DistanceField BuildDistanceFieldSerial(
    const Eigen::Isometry3d& grid_origin_transform,
    const double grid_resolution,
    const int64_t grid_num_x_cells,
    const int64_t grid_num_y_cells,
    const int64_t grid_num_z_cells,
    const std::vector<VoxelGrid::GRID_INDEX>& points)
{
  const std::chrono::time_point<std::chrono::steady_clock> start_time
      = std::chrono::steady_clock::now();
  // Make the DistanceField container
  bucket_cell default_cell;
  default_cell.distance_square = std::numeric_limits<double>::infinity();
  DistanceField distance_field(grid_origin_transform, grid_resolution,
                               grid_num_x_cells, grid_num_y_cells,
                               grid_num_z_cells, default_cell);
  // Compute maximum distance square
  const int64_t max_distance_square =
      (distance_field.GetNumXCells() * distance_field.GetNumXCells())
      + (distance_field.GetNumYCells() * distance_field.GetNumYCells())
      + (distance_field.GetNumZCells() * distance_field.GetNumZCells());
  // Make bucket queue
  std::vector<std::vector<bucket_cell>> bucket_queue(max_distance_square + 1);
  bucket_queue[0].reserve(points.size());
  // Set initial update direction
  int32_t initial_update_direction = GetDirectionNumber(0, 0, 0);
  // Mark all provided points with distance zero and add to the bucket queue
  for (size_t index = 0; index < points.size(); index++)
  {
    const VoxelGrid::GRID_INDEX& current_index = points[index];
    auto query = distance_field.GetMutable(current_index);
    if (query)
    {
      query.Value().location[0] = (uint32_t)current_index.x;
      query.Value().location[1] = (uint32_t)current_index.y;
      query.Value().location[2] = (uint32_t)current_index.z;
      query.Value().closest_point[0] = (uint32_t)current_index.x;
      query.Value().closest_point[1] = (uint32_t)current_index.y;
      query.Value().closest_point[2] = (uint32_t)current_index.z;
      query.Value().distance_square = 0.0;
      query.Value().update_direction = initial_update_direction;
      bucket_queue[0].push_back(query.Value());
    }
    // If the point is outside the bounds of the SDF, skip
    else
    {
      throw std::runtime_error("Point for BuildDistanceField out of bounds");
    }
  }
  // HERE BE DRAGONS
  // Process the bucket queue
  const std::vector<std::vector<std::vector<std::vector<int>>>> neighborhoods =
      MakeNeighborhoods();
  for (size_t bq_idx = 0; bq_idx < bucket_queue.size(); bq_idx++)
  {
    for (const auto& cur_cell : bucket_queue[bq_idx])
    {
      // Get the current location
      const double x = cur_cell.location[0];
      const double y = cur_cell.location[1];
      const double z = cur_cell.location[2];
      // Pick the update direction
      // Only the first bucket queue gets the larger set of neighborhoods?
      // Don't really userstand why.
      const size_t direction_switch = (bq_idx > 0) ? 1 : 0;
      // Make sure the update direction is valid
      if (cur_cell.update_direction < 0 || cur_cell.update_direction > 26)
      {
        continue;
      }
      // Get the current neighborhood list
      const std::vector<std::vector<int>>& neighborhood =
          neighborhoods[direction_switch][cur_cell.update_direction];
      // Update the distance from the neighboring cells
      for (size_t nh_idx = 0; nh_idx < neighborhood.size(); nh_idx++)
      {
        // Get the direction to check
        const int dx = neighborhood[nh_idx][0];
        const int dy = neighborhood[nh_idx][1];
        const int dz = neighborhood[nh_idx][2];
        const int nx = x + dx;
        const int ny = y + dy;
        const int nz = z + dz;
        auto neighbor_query =
            distance_field.GetMutable((int64_t)nx, (int64_t)ny, (int64_t)nz);
        if (!neighbor_query)
        {
          // "Neighbor" is outside the bounds of the SDF
          continue;
        }
        // Update the neighbor's distance based on the current
        const int32_t new_distance_square =
            (int32_t)ComputeDistanceSquared(nx, ny, nz,
                                            cur_cell.closest_point[0],
                                            cur_cell.closest_point[1],
                                            cur_cell.closest_point[2]);
        if (new_distance_square > max_distance_square)
        {
          // Skip these cases
          continue;
        }
        if (new_distance_square < neighbor_query.Value().distance_square)
        {
          // If the distance is better, time to update the neighbor
          neighbor_query.Value().distance_square = new_distance_square;
          neighbor_query.Value().closest_point[0] = cur_cell.closest_point[0];
          neighbor_query.Value().closest_point[1] = cur_cell.closest_point[1];
          neighbor_query.Value().closest_point[2] = cur_cell.closest_point[2];
          neighbor_query.Value().location[0] = nx;
          neighbor_query.Value().location[1] = ny;
          neighbor_query.Value().location[2] = nz;
          neighbor_query.Value().update_direction =
              GetDirectionNumber(dx, dy, dz);
          // Add the neighbor into the bucket queue
          bucket_queue[new_distance_square].push_back(neighbor_query.Value());
        }
      }
    }
    // Clear the current queue now that we're done with it
    bucket_queue[bq_idx].clear();
  }
  const std::chrono::time_point<std::chrono::steady_clock> end_time
      = std::chrono::steady_clock::now();
  const std::chrono::duration<double> elapsed = end_time - start_time;
  std::cout << "Computed DistanceField for grid size (" << grid_num_x_cells
            << ", " << grid_num_y_cells << ", " << grid_num_z_cells << ") in "
            << elapsed.count() << " seconds" << std::endl;
  return distance_field;
}

inline DistanceField BuildDistanceFieldParallel(
    const Eigen::Isometry3d& grid_origin_transform,
    const double grid_resolution,
    const int64_t grid_num_x_cells,
    const int64_t grid_num_y_cells,
    const int64_t grid_num_z_cells,
    const std::vector<VoxelGrid::GRID_INDEX>& points)
{
  const std::chrono::time_point<std::chrono::steady_clock> start_time
      = std::chrono::steady_clock::now();
  // Make the DistanceField container
  bucket_cell default_cell;
  default_cell.distance_square = std::numeric_limits<double>::infinity();
  DistanceField distance_field(grid_origin_transform, grid_resolution,
                               grid_num_x_cells, grid_num_y_cells,
                               grid_num_z_cells, default_cell);
  // Compute maximum distance square
  const int64_t max_distance_square =
      (distance_field.GetNumXCells() * distance_field.GetNumXCells())
      + (distance_field.GetNumYCells() * distance_field.GetNumYCells())
      + (distance_field.GetNumZCells() * distance_field.GetNumZCells());
  // Make bucket queue
  std::vector<std::vector<bucket_cell>> bucket_queue(max_distance_square + 1);
  bucket_queue[0].reserve(points.size());
  MultipleThreadIndexQueueWrapper bucket_queues(max_distance_square + 1);
  // Set initial update direction
  int32_t initial_update_direction = GetDirectionNumber(0, 0, 0);
  // Mark all provided points with distance zero and add to the bucket queues
  // points MUST NOT CONTAIN DUPLICATE ENTRIES!
#if defined(_OPENMP)
#pragma omp parallel for
#endif
  for (size_t index = 0; index < points.size(); index++)
  {
    const VoxelGrid::GRID_INDEX& current_index = points[index];
    auto query = distance_field.GetMutable(current_index);
    if (query)
    {
      query.Value().location[0] = (uint32_t)current_index.x;
      query.Value().location[1] = (uint32_t)current_index.y;
      query.Value().location[2] = (uint32_t)current_index.z;
      query.Value().closest_point[0] = (uint32_t)current_index.x;
      query.Value().closest_point[1] = (uint32_t)current_index.y;
      query.Value().closest_point[2] = (uint32_t)current_index.z;
      query.Value().distance_square = 0.0;
      query.Value().update_direction = initial_update_direction;
      bucket_queues.Enqueue(0, current_index);
    }
    // If the point is outside the bounds of the SDF, skip
    else
    {
      throw std::runtime_error("Point for BuildDistanceField out of bounds");
    }
  }
  // HERE BE DRAGONS
  // Process the bucket queue
  const std::vector<std::vector<std::vector<std::vector<int>>>> neighborhoods =
      MakeNeighborhoods();
  for (int32_t current_distance_square = 0;
       current_distance_square < (int32_t)bucket_queues.NumQueues();
       current_distance_square++)
  {
#if defined(_OPENMP)
#pragma omp parallel for
#endif
    for (size_t idx = 0; idx < bucket_queues.Size(current_distance_square);
         idx++)
    {
      const VoxelGrid::GRID_INDEX& current_index =
          bucket_queues.Query(current_distance_square, idx);
      // Get the current location
      const bucket_cell& cur_cell =
          distance_field.GetImmutable(current_index).Value();
      const double x = cur_cell.location[0];
      const double y = cur_cell.location[1];
      const double z = cur_cell.location[2];
      // Pick the update direction
      // Only the first bucket queue gets the larger set of neighborhoods?
      // Don't really userstand why.
      const size_t direction_switch = (current_distance_square > 0) ? 1 : 0;
      // Make sure the update direction is valid
      if (cur_cell.update_direction < 0 || cur_cell.update_direction > 26)
      {
        continue;
      }
      // Get the current neighborhood list
      const std::vector<std::vector<int32_t>>& neighborhood =
          neighborhoods[direction_switch][cur_cell.update_direction];
      // Update the distance from the neighboring cells
      for (size_t nh_idx = 0; nh_idx < neighborhood.size(); nh_idx++)
      {
        // Get the direction to check
        const int32_t dx = neighborhood[nh_idx][0];
        const int32_t dy = neighborhood[nh_idx][1];
        const int32_t dz = neighborhood[nh_idx][2];
        const int32_t nx = (int32_t)(x + dx);
        const int32_t ny = (int32_t)(y + dy);
        const int32_t nz = (int32_t)(z + dz);
        const VoxelGrid::GRID_INDEX neighbor_index(
              (int64_t)nx, (int64_t)ny, (int64_t)nz);
        auto neighbor_query = distance_field.GetMutable(neighbor_index);
        if (!neighbor_query)
        {
          // "Neighbor" is outside the bounds of the SDF
          continue;
        }
        // Update the neighbor's distance based on the current
        const int32_t new_distance_square =
            (int32_t)ComputeDistanceSquared(nx, ny, nz,
                                            cur_cell.closest_point[0],
                                            cur_cell.closest_point[1],
                                            cur_cell.closest_point[2]);
        if (new_distance_square > max_distance_square)
        {
          // Skip these cases
          continue;
        }
        if (new_distance_square < neighbor_query.Value().distance_square)
        {
          // If the distance is better, time to update the neighbor
          neighbor_query.Value().distance_square = new_distance_square;
          neighbor_query.Value().closest_point[0] = cur_cell.closest_point[0];
          neighbor_query.Value().closest_point[1] = cur_cell.closest_point[1];
          neighbor_query.Value().closest_point[2] = cur_cell.closest_point[2];
          neighbor_query.Value().location[0] = nx;
          neighbor_query.Value().location[1] = ny;
          neighbor_query.Value().location[2] = nz;
          neighbor_query.Value().update_direction =
              GetDirectionNumber(dx, dy, dz);
          // Add the neighbor into the bucket queue
          bucket_queues.Enqueue(new_distance_square, neighbor_index);
        }
      }
    }
    // Clear the current queues now that we're done with it
    bucket_queues.ClearCompletedQueues(current_distance_square);
  }
  const std::chrono::time_point<std::chrono::steady_clock> end_time
      = std::chrono::steady_clock::now();
  const std::chrono::duration<double> elapsed = end_time - start_time;
  std::cout << "Computed DistanceField for grid size (" << grid_num_x_cells
            << ", " << grid_num_y_cells << ", " << grid_num_z_cells << ") in "
            << elapsed.count() << " seconds" << std::endl;
  return distance_field;
}

#define COMPARE_DISTANCE_FIELD_GENERATION

inline DistanceField BuildDistanceField(
    const Eigen::Isometry3d& grid_origin_transform,
    const double grid_resolution,
    const int64_t grid_num_x_cells,
    const int64_t grid_num_y_cells,
    const int64_t grid_num_z_cells,
    const std::vector<VoxelGrid::GRID_INDEX>& points)
{
#ifdef COMPARE_DISTANCE_FIELD_GENERATION
  const DistanceField legacy_field =
      BuildDistanceFieldSerial(grid_origin_transform, grid_resolution,
                               grid_num_x_cells, grid_num_y_cells,
                               grid_num_z_cells, points);
  const DistanceField new_field =
      BuildDistanceFieldParallel(grid_origin_transform, grid_resolution,
                                 grid_num_x_cells, grid_num_y_cells,
                                 grid_num_z_cells, points);
  for (int64_t x_index = 0; x_index < grid_num_x_cells; x_index++)
  {
    for (int64_t y_index = 0; y_index < grid_num_y_cells; y_index++)
    {
      for (int64_t z_index = 0; z_index < grid_num_z_cells; z_index++)
      {
        const bucket_cell& legacy_cell =
            legacy_field.GetImmutable(x_index, y_index, z_index).Value();
        const bucket_cell& new_cell =
            new_field.GetImmutable(x_index, y_index, z_index).Value();
        const double legacy_distance = legacy_cell.distance_square;
        const double new_distance = new_cell.distance_square;
        const double new_delta = std::abs(new_distance - legacy_distance);
        assert(new_delta < 1e-6);
      }
    }
  }
  return new_field;
#else
  // Should we use the parallelizable new variant or the serial legacy variant?
  if (points.size() > 1000)
  {
    return BuildDistanceFieldParallel(grid_origin_transform, grid_resolution,
                                      grid_num_x_cells, grid_num_y_cells,
                                      grid_num_z_cells, points);
  }
  else
  {
    return BuildDistanceFieldSerial(grid_origin_transform, grid_resolution,
                                    grid_num_x_cells, grid_num_y_cells,
                                    grid_num_z_cells, points);
  }
#endif
}

template<typename T>
inline std::pair<sdf_tools::SignedDistanceField, std::pair<double, double>>
ExtractSignedDistanceField(
    const Eigen::Isometry3d& grid_origin_tranform,
    const double grid_resolution,
    const int64_t grid_num_x_cells,
    const int64_t grid_num_y_cells,
    const int64_t grid_num_z_cells,
    const std::function<bool(const VoxelGrid::GRID_INDEX&)>& is_filled_fn,
    const float oob_value,
    const std::string& frame)
{
  const std::chrono::time_point<std::chrono::steady_clock> start_time
      = std::chrono::steady_clock::now();
  std::vector<VoxelGrid::GRID_INDEX> filled;
  std::vector<VoxelGrid::GRID_INDEX> free;
  for (int64_t x_index = 0; x_index < grid_num_x_cells; x_index++)
  {
    for (int64_t y_index = 0; y_index < grid_num_y_cells; y_index++)
    {
      for (int64_t z_index = 0; z_index < grid_num_z_cells; z_index++)
      {
        const VoxelGrid::GRID_INDEX current_index(x_index, y_index, z_index);
        if (is_filled_fn(current_index))
        {
          // Mark as filled
          filled.push_back(current_index);
        }
        else
        {
          // Mark as free space
          free.push_back(current_index);
        }
      }
    }
  }
  // Make two distance fields, one for distance to filled voxels, one for
  // distance to free voxels.
  const DistanceField filled_distance_field =
      BuildDistanceField(grid_origin_tranform, grid_resolution,
                         grid_num_x_cells, grid_num_y_cells, grid_num_z_cells,
                         filled);
  const DistanceField free_distance_field =
      BuildDistanceField(grid_origin_tranform, grid_resolution,
                         grid_num_x_cells, grid_num_y_cells, grid_num_z_cells,
                         free);
  // Generate the SDF
  sdf_tools::SignedDistanceField new_sdf(
        grid_origin_tranform, frame, grid_resolution, grid_num_x_cells,
        grid_num_y_cells, grid_num_z_cells, oob_value);
  double max_distance = -std::numeric_limits<double>::infinity();
  double min_distance = std::numeric_limits<double>::infinity();
  for (int64_t x_index = 0; x_index < new_sdf.GetNumXCells(); x_index++)
  {
    for (int64_t y_index = 0; y_index < new_sdf.GetNumYCells(); y_index++)
    {
      // Parallelize across the Z-axis, since VoxelGrid ensures Z-axis cells are
      // contiguous in memory.
#if defined(_OPENMP)
#pragma omp parallel for
#endif
      for (int64_t z_index = 0; z_index < new_sdf.GetNumZCells(); z_index++)
      {
        const double distance1 =
            std::sqrt(
              filled_distance_field.GetImmutable(x_index, y_index, z_index)
                .Value().distance_square)
            * new_sdf.GetResolution();
        const double distance2 =
            std::sqrt(
              free_distance_field.GetImmutable(x_index, y_index, z_index)
                .Value().distance_square)
            * new_sdf.GetResolution();
        const double distance = distance1 - distance2;
        if (distance > max_distance)
        {
          max_distance = distance;
        }
        if (distance < min_distance)
        {
          min_distance = distance;
        }
        new_sdf.SetValue(x_index, y_index, z_index, (float)distance);
      }
    }
  }
  const std::chrono::time_point<std::chrono::steady_clock> end_time
      = std::chrono::steady_clock::now();
  const std::chrono::duration<double> elapsed = end_time - start_time;
  std::cout << "Computed SDF for grid size (" << grid_num_x_cells << ", "
            << grid_num_y_cells << ", " << grid_num_z_cells << ") in "
            << elapsed.count() << " seconds" << std::endl;
  std::pair<double, double> extrema(max_distance, min_distance);
  return std::pair<sdf_tools::SignedDistanceField,
                   std::pair<double, double>>(new_sdf, extrema);
}

template<typename T, typename BackingStore=std::vector<T>>
inline std::pair<sdf_tools::SignedDistanceField, std::pair<double, double>>
ExtractSignedDistanceField(
    const VoxelGrid::VoxelGrid<T, BackingStore>& grid,
    const std::function<bool(const VoxelGrid::GRID_INDEX&)>& is_filled_fn,
    const float oob_value, const std::string& frame,
    const bool add_virtual_border)
{
  (void)(add_virtual_border);
  const Eigen::Vector3d cell_sizes = grid.GetCellSizes();
  if ((cell_sizes.x() != cell_sizes.y()) || (cell_sizes.x() != cell_sizes.z()))
  {
    throw std::invalid_argument("Grid must have uniform resolution");
  }
  if (add_virtual_border == false)
  {
    // This is the conventional single-pass result
    return ExtractSignedDistanceField<T>(
          grid.GetOriginTransform(), cell_sizes.x(), grid.GetNumXCells(),
          grid.GetNumYCells(), grid.GetNumZCells(), is_filled_fn, oob_value,
          frame);
  }
  else
  {
    const int64_t x_axis_size_offset =
        (grid.GetNumXCells() > 1) ? (int64_t)2 : (int64_t)0;
    const int64_t x_axis_query_offset =
        (grid.GetNumXCells() > 1) ? (int64_t)1 : (int64_t)0;
    const int64_t y_axis_size_offset =
        (grid.GetNumYCells() > 1) ? (int64_t)2 : (int64_t)0;
    const int64_t y_axis_query_offset =
        (grid.GetNumYCells() > 1) ? (int64_t)1 : (int64_t)0;
    const int64_t z_axis_size_offset =
        (grid.GetNumZCells() > 1) ? (int64_t)2 : (int64_t)0;
    const int64_t z_axis_query_offset =
        (grid.GetNumZCells() > 1) ? (int64_t)1 : (int64_t)0;
    // We need to lie about the size of the grid to add a virtual border
    const int64_t num_x_cells = grid.GetNumXCells() + x_axis_size_offset;
    const int64_t num_y_cells = grid.GetNumYCells() + y_axis_size_offset;
    const int64_t num_z_cells = grid.GetNumZCells() + z_axis_size_offset;
    // Make some deceitful helper functions that hide our lies about size
    // For the free space SDF, we lie and say the virtual border is filled
    const std::function<bool(const VoxelGrid::GRID_INDEX&)> free_is_filled_fn
        = [&] (const VoxelGrid::GRID_INDEX& virtual_border_grid_index)
    {
      // Is there a virtual border on our axis?
      if (x_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.x == 0)
            || (virtual_border_grid_index.x == (num_x_cells - 1)))
        {
          return true;
        }
      }
      // Is there a virtual border on our axis?
      if (y_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.y == 0)
            || (virtual_border_grid_index.y == (num_y_cells - 1)))
        {
          return true;
        }
      }
      // Is there a virtual border on our axis?
      if (z_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.z == 0)
            || (virtual_border_grid_index.z == (num_z_cells - 1)))
        {
          return true;
        }
      }
      const VoxelGrid::GRID_INDEX real_grid_index(
            virtual_border_grid_index.x - x_axis_query_offset,
            virtual_border_grid_index.y - y_axis_query_offset,
            virtual_border_grid_index.z - z_axis_query_offset);
      return is_filled_fn(real_grid_index);
    };
    // For the filled space SDF, we lie and say the virtual border is empty
    const std::function<bool(const VoxelGrid::GRID_INDEX&)> filled_is_filled_fn
        = [&] (const VoxelGrid::GRID_INDEX& virtual_border_grid_index)
    {
      // Is there a virtual border on our axis?
      if (x_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.x == 0)
            || (virtual_border_grid_index.x == (num_x_cells - 1)))
        {
          return false;
        }
      }
      // Is there a virtual border on our axis?
      if (y_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.y == 0)
            || (virtual_border_grid_index.y == (num_y_cells - 1)))
        {
          return false;
        }
      }
      // Is there a virtual border on our axis?
      if (z_axis_size_offset > 0)
      {
        // Are we a virtual border cell?
        if ((virtual_border_grid_index.z == 0)
            || (virtual_border_grid_index.z == (num_z_cells - 1)))
        {
          return false;
        }
      }
      const VoxelGrid::GRID_INDEX real_grid_index(
            virtual_border_grid_index.x - x_axis_query_offset,
            virtual_border_grid_index.y - y_axis_query_offset,
            virtual_border_grid_index.z - z_axis_query_offset);
      return is_filled_fn(real_grid_index);
    };
    // Make both SDFs
    auto free_sdf_result = ExtractSignedDistanceField<T>(
                             grid.GetOriginTransform(), cell_sizes.x(),
                             num_x_cells, num_y_cells, num_z_cells,
                             free_is_filled_fn, oob_value, frame);
    auto filled_sdf_result = ExtractSignedDistanceField<T>(
                               grid.GetOriginTransform(), cell_sizes.x(),
                               num_x_cells, num_y_cells, num_z_cells,
                               filled_is_filled_fn, oob_value, frame);
    // Combine to make a single SDF
    sdf_tools::SignedDistanceField combined_sdf(
          grid.GetOriginTransform(), frame, cell_sizes.x(), grid.GetNumXCells(),
          grid.GetNumYCells(), grid.GetNumZCells(), oob_value);
    for (int64_t x_idx = 0; x_idx < combined_sdf.GetNumXCells(); x_idx++)
    {
      for (int64_t y_idx = 0; y_idx < combined_sdf.GetNumYCells(); y_idx++)
      {
        // Parallelize across the Z-axis, since VoxelGrid ensures Z-axis cells
        // are contiguous in memory.
#if defined(_OPENMP)
#pragma omp parallel for
#endif
        for (int64_t z_idx = 0; z_idx < combined_sdf.GetNumZCells(); z_idx++)
        {
          const int64_t query_x_idx = x_idx + x_axis_query_offset;
          const int64_t query_y_idx = y_idx + y_axis_query_offset;
          const int64_t query_z_idx = z_idx + z_axis_query_offset;
          const float free_sdf_value
              = free_sdf_result.first.GetImmutable(
                  query_x_idx, query_y_idx, query_z_idx).Value();
          const float filled_sdf_value
              = filled_sdf_result.first.GetImmutable(
                  query_x_idx, query_y_idx, query_z_idx).Value();
          if (free_sdf_value >= 0.0)
          {
            combined_sdf.SetValue(x_idx, y_idx, z_idx, free_sdf_value);
          }
          else if (filled_sdf_value <= -0.0)
          {
            combined_sdf.SetValue(x_idx, y_idx, z_idx, filled_sdf_value);
          }
          else
          {
            combined_sdf.SetValue(x_idx, y_idx, z_idx, 0.0f);
          }
        }
      }
    }
    // Get the combined max/min values
    const std::pair<double, double> combined_extrema(
          free_sdf_result.second.first, filled_sdf_result.second.second);
    return std::make_pair(combined_sdf, combined_extrema);
  }
}

template<typename T, typename BackingStore=std::vector<T>>
inline std::pair<sdf_tools::SignedDistanceField, std::pair<double, double>>
ExtractSignedDistanceField(const VoxelGrid::VoxelGrid<T, BackingStore>& grid,
                           const std::function<bool(const T&)>& is_filled_fn,
                           const float oob_value, const std::string& frame)
{
  const std::function<bool(const VoxelGrid::GRID_INDEX&)> real_is_filled_fn =
      [&] (const VoxelGrid::GRID_INDEX& index)
  {
    const T& stored = grid.GetImmutable(index).Value();
    // If it matches an object to use OR there are no objects supplied
    if (is_filled_fn(stored))
    {
      // Mark as filled
      return true;
    }
    else
    {
      // Mark as free space
      return false;
    }
  };
  return ExtractSignedDistanceField(
        grid, real_is_filled_fn, oob_value, frame, false);
}
}

#endif // SDF_GENERATION_HPP


text:
// Copyright (c) 2014-2015 Dims dev-team
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "informationProvider.h"
#include <boost/assign.hpp>
#include <boost/foreach.hpp>
#include <boost/assign/list_of.hpp>
#include <boost/thread.hpp>

#include <sstream>

#include "client/trackerLocalRanking.h"
#include "qt/dimsUnits.h"

#include "base58.h"

using boost::assign::map_list_of;
using namespace boost::assign;
using namespace boost;
using namespace monitorsScaner;

template < typename ConvertedType >
std::string
convert( ConvertedType const & _converted )
{
	std::ostringstream stream;
	stream << _converted;
	return stream.str();
}

CInforamtionProvider * CInforamtionProvider::ms_instance = NULL;

CInforamtionProvider*
CInforamtionProvider::getInstance( )
{
	if ( !ms_instance )
	{
		ms_instance = new CInforamtionProvider();
	};
	return ms_instance;
}

CInforamtionProvider::CInforamtionProvider()
{
}

void
CInforamtionProvider::reloadData()
{
	m_trackers.clear();
	m_usedMonitorsTest.clear();
	std::vector< common::CTrackerStats > trackers = client::CTrackerLocalRanking::getInstance()->getTrackers();
	BOOST_FOREACH( common::CTrackerStats const & tracker, trackers )
	{

		CNodeAddress node;

		std::string monitor;
		CPubKey monitorKey;
		if ( client::CTrackerLocalRanking::getInstance()->getMonitorKeyForTracker( tracker.m_key, monitorKey ) )
		{
			node.Set( monitorKey.GetID(), common::NodePrefix::Monitor );
			monitor = node.ToString();
		}

		node.Set( tracker.m_key.GetID(), common::NodePrefix::Tracker );

		m_trackers.insert(
					std::make_pair(
						monitor
						, ( std::list<std::string> const & )boost::assign::list_of( tracker.m_ip )( node.ToString() )( "" )( convert( tracker.m_reputation ) )( CDimsUnits::format(0, tracker.m_price).toStdString() )
						)
				);
	}

	std::vector< common::CMonitorInfo > monitors = client::CTrackerLocalRanking::getInstance()->getMonitors();
	BOOST_FOREACH( common::CNodeInfo const & monitor, monitors )
	{
		CNodeAddress monitorAddress;

		monitorAddress.Set( monitor.m_key.GetID(), common::NodePrefix::Monitor );
		m_usedMonitorsTest.push_back( boost::assign::list_of( monitor.m_ip )( monitorAddress.ToString() )("")("")("") );
	}
}

void
CInforamtionProvider::getTrackers(monitorsScaner::Data& _trackers, std::string _publicKey ) const
{
	typedef std::multimap< std::string ,std::list<std::string> >::const_iterator TrackerInfoIterator;

	unsigned int rows = 0, columns = 0;
	 std::pair<  TrackerInfoIterator, TrackerInfoIterator> keyRange= m_trackers.equal_range(_publicKey);
	// Iterate over all map elements with key == theKey

	for (TrackerInfoIterator it = keyRange.first;  it != keyRange.second;  ++it)
	{
		rows++;
		columns = it->second.size();

		BOOST_FOREACH( std::string const & info, it->second )
		{
			_trackers.data.push_back( info );
		};
	}

	_trackers.cols = columns;
	_trackers.rows = rows;
}

typedef std::list<std::string> StringStorage;

void
CInforamtionProvider::getMonitorsInfo(monitorsScaner::Data& _monitors) const
{

	unsigned int rows = 0, columns = 0;
	BOOST_FOREACH( StringStorage const & storage, m_usedMonitors )
	{
		rows++;
		columns = storage.size();
		BOOST_FOREACH( std::string const &data, storage )
		{
			_monitors.data.push_back( data );
		}
	}

	_monitors.cols = columns;
	_monitors.rows = rows;
}

void
CInforamtionProvider::getInfo(monitorsScaner::Data& _return, const InfoRequest& infoRequest)
{
	if ( Info::TRACKERS_INFO == infoRequest.info )
	{
		getTrackers(_return, infoRequest.key );
	}
	else if( Info::MONITORS_INFO == infoRequest.info  )
	{
		if ( infoRequest.networkType == NetworkType::TESTNET )
		{
			m_usedMonitors = m_usedMonitorsTest;
		}
		else if ( infoRequest.networkType == NetworkType::MAIN )
		{
			m_usedMonitors = m_usedMonitorsMain;
		}
		else
		{
			Exception e;
			e.msg = "specify network type";
			throw e;
		}
		getMonitorsInfo(_return);
	}
	else
	{
		Exception e;

		e.msg = "specify tracker or monitor info";
		throw e;
	}
}

ext: cpp

max_stars_repo_name: salarii/dims

max_issues_repo_name: salivan-ratcoin-dev-team/dims

max_forks_repo_name: salivan-ratcoin-dev-team/dims


text:
#include <fstream>
#include <experimental/filesystem>
#include <boost/progress.hpp>
#include <boost/program_options.hpp>
#include <GraphMol/FileParsers/MolSupplier.h>
#include "SAScore.hpp"

int main(int argc, const char* argv[]) {
  // Set up a command line argument parser and parse the command line arguments.
  std::string input, output;

  boost::program_options::options_description description("Options");
  description.add_options()
    ("help,h",
      "Display this help message.")
    ("input,i", boost::program_options::value<std::string>(&input)->required(),
      "Path to the input file containing molecules in SMILES or SDF format.")
    ("output,o", boost::program_options::value<std::string>(&output)->required(),
      "Path to the output file containing the serialized feature library.");

  boost::program_options::positional_options_description positionals_description;
  positionals_description.add("input", 1);
  positionals_description.add("output", 1);
  boost::program_options::variables_map vm;
  boost::program_options::command_line_parser parser(argc, argv);
  parser.options(description);
  parser.positional(positionals_description);
  boost::program_options::parsed_options parsed_options = parser.run();
  boost::program_options::store(parsed_options, vm);
  if (vm.count("help")) {
    std::cout << description;
    return 1;
  };
  boost::program_options::notify(vm);

  // Initialize an empty FeatureLibrary.
  FeatureLibrary feature_library;

  // Create a molecule input stream based on the extension of the input file.
  std::experimental::filesystem::path extension = std::experimental::filesystem::path(input).extension();

  // If the input file is a SMILES file:
  if (extension == ".smi" || extension == ".ism") {
    RDKit::SmilesMolSupplier supplier(input);

    // Initialize a progress bar.
    unsigned n_mols = supplier.length();
    supplier.reset();
    boost::progress_display progress(n_mols);

    // Add the features of the input molecules to the FeatureLibrary.
    std::unique_ptr<RDKit::ROMol> mol;
    while (!supplier.atEnd()) {
      mol.reset(supplier.next());
      // Verify that the molecule was successfully read.
      if (mol) {
        feature_library.AddMolecule(*mol);
      };
      ++progress;
    };

  // If the input file is a SDF file:
  } else if (extension == ".sdf") {
    RDKit::SDMolSupplier supplier(input);

    // Initialize a progress bar.
    unsigned n_mols = supplier.length();
    supplier.reset();
    boost::progress_display progress(n_mols);

    // Add the features of the input molecules to the FeatureLibrary.
    std::unique_ptr<RDKit::ROMol> mol;
    while (!supplier.atEnd()) {
      mol.reset(supplier.next());
      // Verify that the molecule was successfully read.
      if (mol) {
        feature_library.AddMolecule(*mol);
      };
      ++progress;
    };

  // If the molecule input format is something else, throw an error.
  } else {
    throw std::runtime_error("Unrecognized input format. Input should be either SMILES or SDF.");
  };

  // Calculate the scores of the features in the FeatureLibrary.
  feature_library.CalcFeatureScores();

  // Write out the FeatureLibrary to the output file.
  std::ofstream output_stream (output, std::ofstream::binary);
  boost::archive::binary_oarchive binary_archive (output_stream);
  binary_archive << feature_library;

  // Signal success.
	return 0;
};

max_stars_repo_name: etijskens/LEADD

max_issues_repo_name: etijskens/LEADD

max_forks_repo_name: etijskens/LEADD


text: #include <boost/compute/context.hpp>

ext: hpp

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
/*
 * The MIT License (MIT)
 *
 * Copyright (c) 2019 Sylko Olzscher
 *
 */

#include <boost/program_options.hpp>
#include <cyng/compatibility/file_system.hpp>
#include <boost/config.hpp>
#include <boost/predef.h>
#include <fstream>
#include <iostream>
#include <DOCC_project_info.h>
#include "../../src/driver.h"
#if BOOST_OS_WINDOWS
#include <windows.h>
#endif

//#include <html/node.hpp>

/**
 * The first version generates HTML only. Future version generate hopefully SVG and PDF too.
 *
 * Start with
 * @code
 * build/docc -V9 ~/projects/docc/src/main/examples/readme
 * build/docc -V9 C:\projects\docc\src\main\examples\readme
 * @endcode
 */

int main(int argc, char* argv[]) {

	try
	{
		const cyng::filesystem::path cwd = cyng::filesystem::current_path();

		std::string config_file = "docc_" + std::string(DOCC_SUFFIX) + ".cfg";
		std::string inp_file = "main.docscript";
		std::string out_file = (cwd / "out.html").string();

		//
		//	generic options
		//
		boost::program_options::options_description generic("Generic options");
		generic.add_options()

			("help,h", "print usage message")
			("version,v", "print version string")
			("build,b", "last built timestamp and platform")
			("config,C", boost::program_options::value<std::string>(&config_file)->default_value(config_file), "configuration file")

			;

		//
		//	all compiler options
		//
		boost::program_options::options_description compiler("compiler");
		compiler.add_options()

			("source,S", boost::program_options::value(&inp_file)->default_value(inp_file), "main source file")
			("output,O", boost::program_options::value(&out_file)->default_value(out_file), "output file")
			("include-path,I", boost::program_options::value< std::vector<std::string> >()->default_value(std::vector<std::string>(1, cwd.string()), cwd.string()), "include path")
			//	verbose level
			("verbose,V", boost::program_options::value<int>()->default_value(0)->implicit_value(1), "verbose level")
			;

		boost::program_options::options_description gen("generator");
		gen.add_options()
			("generator.body", boost::program_options::bool_switch()->default_value(false), "generate (HTML) body only")
			("generator.meta", boost::program_options::bool_switch()->default_value(true), "generate a JSON file with meta data")
			("generator.index", boost::program_options::bool_switch()->default_value(true), "generate an index file \"index.json\"")
			("generator.type,T", boost::program_options::value<std::string>()->default_value("report"), "og:type (article/report)")
			;

		//
		//	all you can grab from the command line
		//
		boost::program_options::options_description cmdline_options;
		cmdline_options.add(generic).add(compiler).add(gen);

		//
		//	positional arguments
		//
		boost::program_options::positional_options_description p;
		p.add("source", -1);

		boost::program_options::variables_map vm;
		boost::program_options::store(boost::program_options::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm);
		boost::program_options::notify(vm);

		if (vm.count("help"))
		{
			std::cout
				<< cmdline_options
				<< std::endl
				;
			return EXIT_SUCCESS;
		}

		if (vm.count("version"))
		{
			std::cout
				<< "docScript compiler v"
				<< DOCC_VERSION
				<< std::endl
				;
			return EXIT_SUCCESS;
		}

		if (vm.count("build"))
		{
			std::cout
				<< "last built at : "
				<< DOCC_BUILD_DATE
				<< std::endl
				<< "Platform      : "
				<< DOCC_PLATFORM
				<< std::endl
				<< "Compiler      : "
				<< BOOST_COMPILER
				<< std::endl
				<< "StdLib        : "
				<< BOOST_STDLIB
				<< std::endl

#if defined(BOOST_LIBSTDCXX_VERSION)
				<< "StdLib++      : "
				<< BOOST_LIBSTDCXX_VERSION
				<< std::endl
#endif

				<< "BOOSTLib      : "
				<< BOOST_LIB_VERSION
				<< " ("
				<< BOOST_VERSION
				<< ")"
				<< std::endl

				<< "shared mutex  : "
#if defined(__CPP_SUPPORT_N4508)
				<< "yes"
#else
				<< "no"
#endif
				<< std::endl
				<< "uint8_t type  : "
#if defined(__CPP_SUPPORT_P0482R6)
				<< "yes"
#else
				<< "no"
#endif
				<< std::endl
				<< std::endl
				;
			return EXIT_SUCCESS;
		}

		std::ifstream ifs(config_file);
		if (!ifs)
		{
			std::cout
				<< "***info: config file: "
				<< config_file
				<< " not found"
				<< std::endl
				;
		}
		else
		{
			//
			//	options available from config file
			//
			boost::program_options::options_description file_options;
			file_options.add(compiler).add(gen);

			boost::program_options::store(boost::program_options::parse_config_file(ifs, file_options), vm);
			boost::program_options::notify(vm);
		}

		//
		//	generate some temporary file names for intermediate files
		//
		cyng::filesystem::path tmp = cyng::filesystem::temp_directory_path() / (cyng::filesystem::path(inp_file).filename().string() + ".bin");

		const int verbose = vm["verbose"].as< int >();
		if (verbose > 0)
		{
			std::cout
				<< "***info: verbose level: "
				<< verbose
				<< std::endl
				;

		}

		//
		//	read specified include paths
		//
		auto inc_paths = vm["include-path"].as< std::vector<std::string>>();

		//
		//	Add the path of the input file as include path, if it is not already specified
		//
		auto path = cyng::filesystem::path(inp_file).parent_path();
		auto pos = std::find(inc_paths.begin(), inc_paths.end(), path);
		if (pos == inc_paths.end()) {
			inc_paths.push_back(path.string());
		}

		//
		//	last entry is empty
		//
		inc_paths.push_back("");
		if (verbose > 0)
		{
			std::cout
				<< "Include paths are: "
				<< std::endl
				;
			std::copy(inc_paths.begin(), inc_paths.end(), std::ostream_iterator<std::string>(std::cout, "\n"));
		}

#if BOOST_OS_WINDOWS
		//
		//	set console outpt code page to UTF-8
		//	requires a TrueType font like Lucida
		//
		if (::SetConsoleOutputCP(65001) == 0)
			//if (::SetConsoleOutputCP(12000) == 0)		//	UTF-32
		{
			std::cerr
				<< "Cannot set console code page"
				<< std::endl
				;

		}
#endif
		//
		//	Construct driver instance
		//
  		docscript::driver d(inc_paths, verbose);

		//
		//	Start driver with the main/input file
		//
 		return d.run(cyng::filesystem::path(inp_file).filename()
 			, tmp
			, out_file
			, vm["generator.body"].as< bool >()
			, vm["generator.meta"].as< bool >()
			, vm["generator.index"].as< bool >()
			, vm["generator.type"].as< std::string >());

	}
	catch (std::exception& e)
	{
		std::cerr
			<< e.what()
			<< std::endl
			;
	}

	return EXIT_FAILURE;

}

max_stars_repo_name: solosTec/docScript

max_issues_repo_name: solosTec/docScript

max_forks_repo_name: solosTec/docScript


text:
#ifndef BONJOUR_ADDRESS_RESOLVER_HPP__
#define BONJOUR_ADDRESS_RESOLVER_HPP__

#include <boost/noncopyable.hpp>
#include <boost/asio.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/enable_shared_from_this.hpp>

#include <ddnspp/bonjourpp/dnsd_callback.hpp>		/// callback func def

#include <ddnspp/bonjourpp/dnsdapi.hpp>
#include <ddnspp/bonjourpp/core.hpp>
#include <ddnspp/bonjourpp/bonjourerror.hpp>
#include <ddnspp/bonjourpp/servicetype.hpp>
#include <ddnspp/logv/logv.hpp>

namespace air
{
namespace bonjour
{

class ServiceFactory;

/// AddressResolver
/// Queries for the IP address of a hostname by using either Multicast or Unicast DNS
class AddressResolver:boost::noncopyable,public boost::enable_shared_from_this<AddressResolver>
{

    friend class ServiceFactory;
private:
    CoreContextPtr		core;
    AddressResolverEvtCallback	evtCallback;
public:
    AddressResolver(boost::asio::io_service& ios,const DNSDApi &dll,const AddressResolverEvtCallback& func)
        :core(new CoreContext(ios,dll)),evtCallback(func)
    {
    }
    ~AddressResolver()
    {
        //LOG_DEBUG<<"AddressResolver dead";
    }

    CoreContextPtr		getCoreContext()
    {
        return core;
	}

	void	close()
	{
		core->close();
	}

    /// return old one
    AddressResolverEvtCallback				setEvtCallback(const AddressResolverEvtCallback& func)
    {
        AddressResolverEvtCallback old=evtCallback;
        evtCallback=func;
        return old;
    }

private:
    static void		DNSSD_API	DNSServiceGetAddrInfoReplyCallback(
        DNSServiceRef                    sdRef,
        DNSServiceFlags                  flags,
        uint32_t                         interfaceIndex,
        DNSServiceErrorType              errorCode,
        const char                       *hostname,
        const struct sockaddr            *address,
        uint32_t                         ttl,
        void                             *context
    )
    {

        AddressResolver* thisService=NULL;
        if(context != NULL) {
            thisService=(AddressResolver*)context;
            thisService->evtHanler(sdRef,flags,interfaceIndex,errorCode,hostname,address,ttl,context);
        }
    }

    //Possible values are kDNSServiceFlagsMoreComing and kDNSServiceFlagsAdd.
    void	evtHanler(
        DNSServiceRef                    sdRef,
        DNSServiceFlags                  flags,
        uint32_t                         interfaceIndex,
        DNSServiceErrorType              errorCode,
        const char                       *hostname,
        const struct sockaddr            *address,
        uint32_t                         ttl,
        void                             *context)
    {

        air::bonjour::BonjourError err(errorCode);
        /*
        bool moreData=(flags & kDNSServiceFlagsMoreComing);
        if (moreData) return;
        */

        boost::asio::ip::address warped_address;
        if(!err && NULL != address) {
            if (AF_INET == address->sa_family ) {
                boost::uint32_t be32=air::common::as_be32(reinterpret_cast<const struct sockaddr_in*>(address)->sin_addr.s_addr);
                warped_address = boost::asio::ip::address_v4(be32);
            } else if (AF_INET6 == address->sa_family) {
                boost::asio::ip::address_v6::bytes_type addr_bytes;
                for (int i=0; i< 16; i++) {
                    addr_bytes[i] = reinterpret_cast<const struct sockaddr_in6*>(address)->sin6_addr.s6_addr[i];
                }
                warped_address=boost::asio::ip::address_v6 (
                                   addr_bytes,
                                   reinterpret_cast<const struct sockaddr_in6*>(address)->sin6_scope_id);

            } else {
                //bug here!
            }
        }
        if(err) {
            LOG_ERR<<err.getErrorCode()<<"," <<err.getMessage();
        } else {
            if (flags & kDNSServiceFlagsAdd) {
                LOG_TRACE<<"Addres added";
            } else {
                LOG_TRACE<<"Addres removed";
            }
            LOG_TRACE<<"flags:"<< flags;
            LOG_TRACE<<"interfaceIndex:"<< interfaceIndex;
            LOG_TRACE<<"hostname:"<< hostname;
            LOG_TRACE<<"address:"<<warped_address;
            LOG_TRACE<<"ttl:"<<ttl;
        }
        if(evtCallback) {
			air::bonjour::AddressResolveData	data;
			data.addr			=	warped_address;
			data.error			=	err;
			data.flags			=	flags;
			data.hostName		=	hostname;
			data.interfaceIndex	=	interfaceIndex;
			data.ttl			=	ttl;
			data.owner			=	shared_from_this();

			evtCallback(data);

        }
    }
};
typedef	boost::shared_ptr<AddressResolver>	AddressResolverPtr;

}
}
#endif // BONJOUR_ADDRESS_RESOLVER_HPP__

max_stars_repo_name: John-Chan/dnssdpp

max_issues_repo_name: John-Chan/dnssdpp

max_forks_repo_name: John-Chan/dnssdpp


text:
#define BOOST_TEST_MODULE
#include <boost/test/unit_test.hpp>
#include <util/test_macros.hpp>
#include <string>
#include <random>
#include <set>
#include <sstream>
#include <vector>
#include <array>
#include <algorithm>
#include <util/cityhash_tc.hpp>

// Eigen
#include <Eigen/Core>
#include <Eigen/SparseCore>

// SFrame and Flex type
#include <unity/lib/flex_dict_view.hpp>
#include <random/random.hpp>

// ML-Data Utils
#include <ml_data/ml_data.hpp>
#include <ml_data/ml_data_entry.hpp>
#include <ml_data/metadata.hpp>

// Testing utils common to all of ml_data_iterator
#include <sframe/testing_utils.hpp>
#include <ml_data/testing_utils.hpp>
#include <util/testing_utils.hpp>

#include <globals/globals.hpp>

using namespace turi;

typedef Eigen::Matrix<double, Eigen::Dynamic,1>  DenseVector;
typedef Eigen::SparseVector<double> SparseVector;

struct test_row_bounds  {
 public:

  // Test the block iterator by stress-testing a large number of
  // combinations of bounds, threads, sizes, and types

  enum class target_column_type {NONE, NUMERICAL, CATEGORICAL};

  void run_row_bounds_check_test(size_t n, std::string run_string, target_column_type target_type,
                                 std::vector<size_t> untranslated_columns = {}) {

    globals::set_global("TURI_ML_DATA_TARGET_ROW_BYTE_MINIMUM", 29);
    globals::set_global("TURI_ML_DATA_STATS_PARALLEL_ACCESS_THRESHOLD", 7);

    // This must hold if we are going to have deterministic indexing
    ASSERT_LE(n, 10000);

    random::seed(0);

    bool target_column;

    if(target_type == target_column_type::CATEGORICAL) {
      target_column = true;
      run_string = std::string("Z") + run_string;
    } else if(target_type == target_column_type::NUMERICAL) {
      target_column = true;
      run_string = std::string("n") + run_string;
    } else {
      target_column = false;
    }

    sframe raw_data = make_random_sframe(n, run_string, false);

    if(target_column)
      raw_data.set_column_name(0, "target");

    std::vector<std::vector<flexible_type> > ref_data = testing_extract_sframe_data(raw_data);

    std::map<std::string, ml_column_mode> mode_overrides;

    for(size_t c_idx : untranslated_columns)
      mode_overrides[raw_data.column_name(c_idx)] = ml_column_mode::UNTRANSLATED;

    for(size_t c_idx = target_column ? 1 : 0; c_idx < raw_data.num_columns(); ++c_idx) {
      if(raw_data.column_type(c_idx) == flex_type_enum::INTEGER)
        mode_overrides[raw_data.column_name(c_idx)] = ml_column_mode::CATEGORICAL;
    }

    std::string print_str = run_string;

    if(target_column)
      print_str += ":target";

    bool target_column_categorical = (target_type == target_column_type::CATEGORICAL);

    if(target_column_categorical)
      mode_overrides["target"] = ml_column_mode::CATEGORICAL;
    else
      mode_overrides["target"] = ml_column_mode::NUMERIC;

    ml_data data;

    data.fill(raw_data, (target_column ? "target" : ""), mode_overrides);

    ////////////////////////////////////////////////////////////////////////////////

    std::vector<std::pair<size_t, size_t> > row_segments
    { {0, n},
      {0, n / 3},
      {n / 3, 2*n / 3},
      {2*n / 3, n} };

    for(const std::pair<size_t, size_t>& row_bounds : row_segments) {

      sframe sliced_raw_data = slice_sframe(raw_data, row_bounds.first, row_bounds.second);

      ml_data data_row_sliced;
      data_row_sliced.fill(raw_data, row_bounds, (target_column ? "target" : ""), mode_overrides);

      ml_data data_true;
      data_true.fill(sliced_raw_data, (target_column ? "target" : ""), mode_overrides);

      ml_data data_sliced = data.slice(row_bounds.first, row_bounds.second);

      // Now go through and make sure they are equal.
      data_row_sliced.metadata()->_debug_is_equal(data_true.metadata());

      ASSERT_EQ(data_row_sliced.num_rows(), data_true.num_rows());
      ASSERT_EQ(data_sliced.num_rows(), data_true.num_rows());

      in_parallel([&](size_t thread_idx, size_t num_threads) {

          std::vector<ml_data_entry> x1, x2, x3;
          std::vector<flexible_type> xf1, xf2, xf3;
          std::vector<flexible_type> row_x1, row_x2, row_x3;

          auto it_1 = data_row_sliced.get_iterator(thread_idx, num_threads);
          auto it_2 = data_true.get_iterator(thread_idx, num_threads);
          auto it_3 = data_sliced.get_iterator(thread_idx, num_threads);

          for(;!it_1.done();++it_1, ++it_2, ++it_3) {
            ASSERT_FALSE(it_2.done());
            ASSERT_FALSE(it_3.done());

            ASSERT_EQ(it_1.row_index(), it_2.row_index());
            ASSERT_EQ(it_1.row_index(), it_3.row_index());

            ////////////////////////////////////////////////////////////////////////////////
            // Test that the sliced creation and the creation from sliced are identical

            it_1->fill(x1);
            it_2->fill(x2);
            it_3->fill(x3);

            ASSERT_TRUE(x1 == x2);

            ASSERT_TRUE(it_1->target_index() == it_2->target_index());
            ASSERT_TRUE(it_1->target_value() == it_2->target_value());

            ASSERT_TRUE(it_1->target_value() == it_3->target_value());

            ////////////////////////////////////////////////////////////////////////////////
            // Test reference to the original data, including the sliced data.

            row_x1 = translate_row_to_original(data_row_sliced.metadata(), x1);
            row_x2 = translate_row_to_original(data_true.metadata(), x2);
            row_x3 = translate_row_to_original(data_sliced.metadata(), x3);

            ASSERT_EQ(row_x1.size(), row_x2.size());
            ASSERT_EQ(row_x1.size(), row_x3.size());

            for(size_t ri = 0; ri < row_x1.size(); ++ri) {
              ASSERT_TRUE(ml_testing_equals(row_x1.at(ri), row_x2.at(ri)));
              ASSERT_TRUE(ml_testing_equals(row_x1.at(ri), row_x3.at(ri)));
            }

            ////////////////////////////////////////////////////////////////////////////////
            // Test the unobserved values

            it_1->fill_untranslated_values(xf1);
            it_2->fill_untranslated_values(xf2);
            it_3->fill_untranslated_values(xf3);

            ASSERT_TRUE(xf1 == xf2);
            ASSERT_TRUE(xf1 == xf3);
          }
          ASSERT_TRUE(it_2.done());
          ASSERT_TRUE(it_3.done());
        });
    }
  }

  ////////////////////////////////////////////////////////////////////////////////

  void test_row_bounds_000() {
    // All unique
    run_row_bounds_check_test(0, "n", target_column_type::NONE);
  }

  void test_row_bounds_0n() {
    // All unique
    run_row_bounds_check_test(5, "n", target_column_type::NONE);
  }

  void test_row_bounds_0b() {
    run_row_bounds_check_test(5, "b", target_column_type::NONE);
  }

  void test_row_bounds_0c() {
    // All unique
    run_row_bounds_check_test(5, "c", target_column_type::NONE);
  }

  void test_row_bounds_0C() {
    // All unique
    run_row_bounds_check_test(5, "C", target_column_type::NONE);
  }

  void test_row_bounds_1b_unsorted() {
    run_row_bounds_check_test(13, "b", target_column_type::NONE);
  }

  void test_row_bounds_1() {
    run_row_bounds_check_test(13, "bc", target_column_type::NONE);
  }

  void test_row_bounds_2() {
    run_row_bounds_check_test(13, "zc", target_column_type::NONE);
  }

  void test_row_bounds_3() {
    run_row_bounds_check_test(100, "Zc", target_column_type::NONE);
  }

  void test_row_bounds_4() {
    // Pretty much gonna be unique
    run_row_bounds_check_test(100, "Cc", target_column_type::NONE);
  }

  void test_row_bounds_5() {
    // 10 blocks of values.
    run_row_bounds_check_test(1000, "Zc", target_column_type::NONE);
  }

  void test_row_bounds_6() {
    // two large blocks of values
    run_row_bounds_check_test(1000, "bc", target_column_type::NONE);
  }

  void test_row_bounds_10() {
    // Yeah, a corner case
    run_row_bounds_check_test(1, "bc", target_column_type::NONE);
  }

  void test_row_bounds_11() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "u", target_column_type::NONE);
  }

  void test_row_bounds_12() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "d", target_column_type::NONE);
  }

  void test_row_bounds_13() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "cnv", target_column_type::NONE);
  }

  void test_row_bounds_14() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "du", target_column_type::NONE);
  }

  void test_row_bounds_15() {
    // One with just a lot of stuff
    run_row_bounds_check_test(3, "UDccccV", target_column_type::NONE);
  }

  void test_row_bounds_100() {
    // One with just a lot of stuff
    run_row_bounds_check_test(10, "Zcuvd", target_column_type::NONE);
  }

  void test_untranslated_columns_nn_1() {
    run_row_bounds_check_test(109, "nn", target_column_type::NONE, {1});
  }

  void test_untranslated_columns_nn_2() {
    run_row_bounds_check_test(109, "nn", target_column_type::NONE, {0});
  }

  void test_untranslated_columns_nn_3() {
    run_row_bounds_check_test(109, "nn", target_column_type::NONE, {0, 1});
  }

  void test_untranslated_columns_ssss_1() {
    run_row_bounds_check_test(109, "ssss", target_column_type::NONE, {1,3});
  }

  void test_untranslated_columns_ssss_2() {
    run_row_bounds_check_test(109, "ssss", target_column_type::NONE, {0,1,2,3});
  }

  void test_untranslated_columns_dd_1() {
    run_row_bounds_check_test(109, "dd", target_column_type::NONE, {1});
  }

  void test_untranslated_columns_dd_2() {
    run_row_bounds_check_test(109, "dd", target_column_type::NONE, {0});
  }

  void test_untranslated_columns_dd_3() {
    run_row_bounds_check_test(109, "dd", target_column_type::NONE, {0,1});
  }

  void test_untranslated_columns_v_1() {
    run_row_bounds_check_test(109, "v", target_column_type::NONE, {0});
  }

  void test_untranslated_columns_many_1() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::NONE,
                              {0, 2, 4, 6, 8, 10, 12, 14, 16, 18});
  }

  void test_untranslated_columns_many_2() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::NONE, {19});
  }

  ////////////////////////////////////////////////////////////////////////////////
  // All the ones with targets

  void test_row_bounds_000_tn() {
    // All unique
    run_row_bounds_check_test(0, "n", target_column_type::NUMERICAL);
  }

  void test_row_bounds_0n_tn() {
    // All unique
    run_row_bounds_check_test(5, "n", target_column_type::NUMERICAL);
  }

  void test_row_bounds_0C_tn() {
    // All unique
    run_row_bounds_check_test(5, "c", target_column_type::NUMERICAL);
  }

  void test_row_bounds_1_unsorted_tn() {
    run_row_bounds_check_test(5, "b", target_column_type::NUMERICAL);
  }

  void test_row_bounds_0b_tn() {
    // All unique
    run_row_bounds_check_test(13, "C", target_column_type::NUMERICAL);
  }

  void test_row_bounds_1b_unsorted_tn() {
    run_row_bounds_check_test(13, "b", target_column_type::NUMERICAL);
  }

  void test_row_bounds_1_tn() {
    run_row_bounds_check_test(13, "bc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_2_tn() {
    run_row_bounds_check_test(13, "zc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_3_tn() {
    run_row_bounds_check_test(100, "Zc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_4_tn() {
    // Pretty much gonna be unique
    run_row_bounds_check_test(100, "Cc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_5_tn() {
    // 10 blocks of values.
    run_row_bounds_check_test(1000, "Zc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_6_tn() {
    // two large blocks of values
    run_row_bounds_check_test(1000, "bc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_10_tn() {
    // Yeah, a corner case
    run_row_bounds_check_test(1, "bc", target_column_type::NUMERICAL);
  }

  void test_row_bounds_11_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "u", target_column_type::NUMERICAL);
  }

  void test_row_bounds_12_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "d", target_column_type::NUMERICAL);
  }

  void test_row_bounds_13_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "cnv", target_column_type::NUMERICAL);
  }

  void test_row_bounds_14_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "du", target_column_type::NUMERICAL);
  }

  void test_row_bounds_15_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(3, "UDccccV", target_column_type::NUMERICAL);
  }

  void test_row_bounds_100_tn() {
    // One with just a lot of stuff
    run_row_bounds_check_test(10, "Zcuvd", target_column_type::NUMERICAL);
  }

  void test_row_bounds_16_null_tn() {
    // two large blocks of values
    run_row_bounds_check_test(1000, "", target_column_type::NUMERICAL);
  }

  void test_untranslated_columns_nn_1_num() {
    run_row_bounds_check_test(109, "nn", target_column_type::NUMERICAL, {1});
  }

  void test_untranslated_columns_nn_2_num() {
    run_row_bounds_check_test(109, "nn", target_column_type::NUMERICAL, {0});
  }

  void test_untranslated_columns_nn_3_num() {
    run_row_bounds_check_test(109, "nn", target_column_type::NUMERICAL, {0, 1});
  }

  void test_untranslated_columns_ssss_1_num() {
    run_row_bounds_check_test(109, "ssss", target_column_type::NUMERICAL, {1,3});
  }

  void test_untranslated_columns_ssss_2_num() {
    run_row_bounds_check_test(109, "ssss", target_column_type::NUMERICAL, {0,1,2,3});
  }

  void test_untranslated_columns_dd_1_num() {
    run_row_bounds_check_test(109, "dd", target_column_type::NUMERICAL, {1});
  }

  void test_untranslated_columns_dd_2_num() {
    run_row_bounds_check_test(109, "dd", target_column_type::NUMERICAL, {0});
  }

  void test_untranslated_columns_dd_3_num() {
    run_row_bounds_check_test(109, "dd", target_column_type::NUMERICAL, {0,1});
  }

  void test_untranslated_columns_v_1_num() {
    run_row_bounds_check_test(109, "v", target_column_type::NUMERICAL, {0});
  }

  void test_untranslated_columns_many_1_num() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::NUMERICAL,
                              {0, 2, 4, 6, 8, 10, 12, 14, 16, 18});
  }

  void test_untranslated_columns_many_2_num() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::NUMERICAL, {19});
  }

  ////////////////////////////////////////////////////////////////////////////////
  // All the ones with targets

  void test_row_bounds_000_tc() {
    // All unique
    run_row_bounds_check_test(0, "n", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_0n_tc() {
    // All unique
    run_row_bounds_check_test(5, "n", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_0C_tc() {
    // All unique
    run_row_bounds_check_test(5, "c", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_1_unsorted_tc() {
    run_row_bounds_check_test(5, "b", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_0b_tc() {
    // All unique
    run_row_bounds_check_test(13, "C", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_1b_unsorted_tc() {
    run_row_bounds_check_test(13, "b", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_1_tc() {
    run_row_bounds_check_test(13, "bc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_2_tc() {
    run_row_bounds_check_test(13, "zc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_3_tc() {
    run_row_bounds_check_test(100, "Zc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_4_tc() {
    // Pretty much gonna be unique
    run_row_bounds_check_test(100, "Cc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_5_tc() {
    // 10 blocks of values.
    run_row_bounds_check_test(1000, "Zc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_6_tc() {
    // two large blocks of values
    run_row_bounds_check_test(1000, "bc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_10_tc() {
    // Yeah, a corner case
    run_row_bounds_check_test(1, "bc", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_11_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "u", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_12_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(200, "d", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_13_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "cnv", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_14_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(1000, "du", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_15_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(3, "UDccccV", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_100_tc() {
    // One with just a lot of stuff
    run_row_bounds_check_test(10, "Zcuvd", target_column_type::CATEGORICAL);
  }

  void test_row_bounds_16_null_tc() {
    // two large blocks of values
    run_row_bounds_check_test(1000, "", target_column_type::CATEGORICAL);
  }

  void test_untranslated_columns_nn_1_cat() {
    run_row_bounds_check_test(109, "nn", target_column_type::CATEGORICAL, {1});
  }

  void test_untranslated_columns_nn_2_cat() {
    run_row_bounds_check_test(109, "nn", target_column_type::CATEGORICAL, {0});
  }

  void test_untranslated_columns_nn_3_cat() {
    run_row_bounds_check_test(109, "nn", target_column_type::CATEGORICAL, {0, 1});
  }

  void test_untranslated_columns_ssss_1_cat() {
    run_row_bounds_check_test(109, "ssss", target_column_type::CATEGORICAL, {1,3});
  }

  void test_untranslated_columns_ssss_2_cat() {
    run_row_bounds_check_test(109, "ssss", target_column_type::CATEGORICAL, {0,1,2,3});
  }

  void test_untranslated_columns_dd_1_cat() {
    run_row_bounds_check_test(109, "dd", target_column_type::CATEGORICAL, {1});
  }

  void test_untranslated_columns_dd_2_cat() {
    run_row_bounds_check_test(109, "dd", target_column_type::CATEGORICAL, {0});
  }

  void test_untranslated_columns_dd_3_cat() {
    run_row_bounds_check_test(109, "dd", target_column_type::CATEGORICAL, {0,1});
  }

  void test_untranslated_columns_v_1_cat() {
    run_row_bounds_check_test(109, "v", target_column_type::CATEGORICAL, {0});
  }

  void test_untranslated_columns_many_1_cat() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::CATEGORICAL,
                              {0, 2, 4, 6, 8, 10, 12, 14, 16, 18});
  }

  void test_untranslated_columns_many_2_cat() {
    run_row_bounds_check_test(109, "cnsnscsnccccccccncss", target_column_type::CATEGORICAL, {19});
  }

};

BOOST_FIXTURE_TEST_SUITE(_test_row_bounds, test_row_bounds)
BOOST_AUTO_TEST_CASE(test_row_bounds_000) {
  test_row_bounds::test_row_bounds_000();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0n) {
  test_row_bounds::test_row_bounds_0n();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0b) {
  test_row_bounds::test_row_bounds_0b();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0c) {
  test_row_bounds::test_row_bounds_0c();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0C) {
  test_row_bounds::test_row_bounds_0C();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1b_unsorted) {
  test_row_bounds::test_row_bounds_1b_unsorted();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1) {
  test_row_bounds::test_row_bounds_1();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_2) {
  test_row_bounds::test_row_bounds_2();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_3) {
  test_row_bounds::test_row_bounds_3();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_4) {
  test_row_bounds::test_row_bounds_4();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_5) {
  test_row_bounds::test_row_bounds_5();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_6) {
  test_row_bounds::test_row_bounds_6();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_10) {
  test_row_bounds::test_row_bounds_10();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_11) {
  test_row_bounds::test_row_bounds_11();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_12) {
  test_row_bounds::test_row_bounds_12();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_13) {
  test_row_bounds::test_row_bounds_13();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_14) {
  test_row_bounds::test_row_bounds_14();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_15) {
  test_row_bounds::test_row_bounds_15();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_100) {
  test_row_bounds::test_row_bounds_100();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_1) {
  test_row_bounds::test_untranslated_columns_nn_1();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_2) {
  test_row_bounds::test_untranslated_columns_nn_2();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_3) {
  test_row_bounds::test_untranslated_columns_nn_3();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_1) {
  test_row_bounds::test_untranslated_columns_ssss_1();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_2) {
  test_row_bounds::test_untranslated_columns_ssss_2();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_1) {
  test_row_bounds::test_untranslated_columns_dd_1();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_2) {
  test_row_bounds::test_untranslated_columns_dd_2();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_3) {
  test_row_bounds::test_untranslated_columns_dd_3();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_v_1) {
  test_row_bounds::test_untranslated_columns_v_1();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_1) {
  test_row_bounds::test_untranslated_columns_many_1();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_2) {
  test_row_bounds::test_untranslated_columns_many_2();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_000_tn) {
  test_row_bounds::test_row_bounds_000_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0n_tn) {
  test_row_bounds::test_row_bounds_0n_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0C_tn) {
  test_row_bounds::test_row_bounds_0C_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1_unsorted_tn) {
  test_row_bounds::test_row_bounds_1_unsorted_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0b_tn) {
  test_row_bounds::test_row_bounds_0b_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1b_unsorted_tn) {
  test_row_bounds::test_row_bounds_1b_unsorted_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1_tn) {
  test_row_bounds::test_row_bounds_1_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_2_tn) {
  test_row_bounds::test_row_bounds_2_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_3_tn) {
  test_row_bounds::test_row_bounds_3_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_4_tn) {
  test_row_bounds::test_row_bounds_4_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_5_tn) {
  test_row_bounds::test_row_bounds_5_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_6_tn) {
  test_row_bounds::test_row_bounds_6_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_10_tn) {
  test_row_bounds::test_row_bounds_10_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_11_tn) {
  test_row_bounds::test_row_bounds_11_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_12_tn) {
  test_row_bounds::test_row_bounds_12_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_13_tn) {
  test_row_bounds::test_row_bounds_13_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_14_tn) {
  test_row_bounds::test_row_bounds_14_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_15_tn) {
  test_row_bounds::test_row_bounds_15_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_100_tn) {
  test_row_bounds::test_row_bounds_100_tn();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_16_null_tn) {
  test_row_bounds::test_row_bounds_16_null_tn();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_1_num) {
  test_row_bounds::test_untranslated_columns_nn_1_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_2_num) {
  test_row_bounds::test_untranslated_columns_nn_2_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_3_num) {
  test_row_bounds::test_untranslated_columns_nn_3_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_1_num) {
  test_row_bounds::test_untranslated_columns_ssss_1_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_2_num) {
  test_row_bounds::test_untranslated_columns_ssss_2_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_1_num) {
  test_row_bounds::test_untranslated_columns_dd_1_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_2_num) {
  test_row_bounds::test_untranslated_columns_dd_2_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_3_num) {
  test_row_bounds::test_untranslated_columns_dd_3_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_v_1_num) {
  test_row_bounds::test_untranslated_columns_v_1_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_1_num) {
  test_row_bounds::test_untranslated_columns_many_1_num();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_2_num) {
  test_row_bounds::test_untranslated_columns_many_2_num();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_000_tc) {
  test_row_bounds::test_row_bounds_000_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0n_tc) {
  test_row_bounds::test_row_bounds_0n_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0C_tc) {
  test_row_bounds::test_row_bounds_0C_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1_unsorted_tc) {
  test_row_bounds::test_row_bounds_1_unsorted_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_0b_tc) {
  test_row_bounds::test_row_bounds_0b_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1b_unsorted_tc) {
  test_row_bounds::test_row_bounds_1b_unsorted_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_1_tc) {
  test_row_bounds::test_row_bounds_1_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_2_tc) {
  test_row_bounds::test_row_bounds_2_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_3_tc) {
  test_row_bounds::test_row_bounds_3_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_4_tc) {
  test_row_bounds::test_row_bounds_4_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_5_tc) {
  test_row_bounds::test_row_bounds_5_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_6_tc) {
  test_row_bounds::test_row_bounds_6_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_10_tc) {
  test_row_bounds::test_row_bounds_10_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_11_tc) {
  test_row_bounds::test_row_bounds_11_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_12_tc) {
  test_row_bounds::test_row_bounds_12_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_13_tc) {
  test_row_bounds::test_row_bounds_13_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_14_tc) {
  test_row_bounds::test_row_bounds_14_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_15_tc) {
  test_row_bounds::test_row_bounds_15_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_100_tc) {
  test_row_bounds::test_row_bounds_100_tc();
}
BOOST_AUTO_TEST_CASE(test_row_bounds_16_null_tc) {
  test_row_bounds::test_row_bounds_16_null_tc();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_1_cat) {
  test_row_bounds::test_untranslated_columns_nn_1_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_2_cat) {
  test_row_bounds::test_untranslated_columns_nn_2_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_nn_3_cat) {
  test_row_bounds::test_untranslated_columns_nn_3_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_1_cat) {
  test_row_bounds::test_untranslated_columns_ssss_1_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_ssss_2_cat) {
  test_row_bounds::test_untranslated_columns_ssss_2_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_1_cat) {
  test_row_bounds::test_untranslated_columns_dd_1_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_2_cat) {
  test_row_bounds::test_untranslated_columns_dd_2_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_dd_3_cat) {
  test_row_bounds::test_untranslated_columns_dd_3_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_v_1_cat) {
  test_row_bounds::test_untranslated_columns_v_1_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_1_cat) {
  test_row_bounds::test_untranslated_columns_many_1_cat();
}
BOOST_AUTO_TEST_CASE(test_untranslated_columns_many_2_cat) {
  test_row_bounds::test_untranslated_columns_many_2_cat();
}
BOOST_AUTO_TEST_SUITE_END()

ext: cxx

max_stars_repo_name: LeeCenY/turicreate

max_issues_repo_name: LeeCenY/turicreate

max_forks_repo_name: ZeroInfinite/turicreate


text:
#include <thrift/concurrency/ThreadManager.h>
#include <thrift/concurrency/PosixThreadFactory.h>
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/server/TThreadPoolServer.h>
#include <thrift/server/TThreadedServer.h>
#include <thrift/transport/TTransportUtils.h>
#include <boost/shared_ptr.hpp>

#include <iostream>

#include "Amqp.h"
#include "AmqpFactory.h"
#include "AmqpServerTransport.h"

#include "Test.h"

using namespace std;
//using namespace boost;
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace apache::thrift::server;

using namespace waste;
using namespace test;

class Test : public TestIf {
 public:
    Test() {}

    void echo(string& _return, const string& text) {

        _return.append("echo ");
        _return.append("\"");
        _return.append(text);
        _return.append("\"");
    }
};

int main(int argc, char **argv) {

    const string hostName = "127.0.0.1";
    const int port = 5672;
    const string virtualHostName = "/";
    const string userName = "guest";
    const string password = "guest";
    const string exchangeName = "test";
    const string routingKey = "test";
    const string queueName = "test";

    boost::shared_ptr<Amqp> amqp = AmqpFactory::get(hostName, port, virtualHostName, userName, password);

    amqp->connect();
    boost::shared_ptr<Amqp::Channel> channel = amqp->open();

    boost::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
    boost::shared_ptr<Test> test(new Test());
    boost::shared_ptr<TProcessor> processor(new TestProcessor(test));
    boost::shared_ptr<TServerTransport> serverTransport(new AmqpServerTransport(channel, exchangeName, routingKey, queueName));
    boost::shared_ptr<TTransportFactory> transportFactory(new TFramedTransportFactory());

    TSimpleServer server(processor,
                         serverTransport,
                         transportFactory,
                         protocolFactory);

    /**
     * Or you could do one of these

     boost::shared_ptr<ThreadManager> threadManager =
     ThreadManager::newSimpleThreadManager(workerCount);
     boost::shared_ptr<PosixThreadFactory> threadFactory =
     boost::shared_ptr<PosixThreadFactory>(new PosixThreadFactory());
     threadManager->threadFactory(threadFactory);
     threadManager->start();
     TThreadPoolServer server(processor,
     serverTransport,
     transportFactory,
     protocolFactory,
     threadManager);

     TThreadedServer server(processor,
     serverTransport,
     transportFactory,
     protocolFactory);

    */

    cout << "Starting the server..." << endl;
    server.serve();
    cout << "done." << endl;

    channel->close();
    amqp->disconnect();
    return 0;
}

max_stars_repo_name: mille-printemps/waste

max_issues_repo_name: mille-printemps/waste

max_forks_repo_name: mille-printemps/waste