Exemplo n.º 1
0
void collection_get_primitive(Collection* collection, size_t ndx, PrimitiveValue& value, NativeException::Marshallable& ex)
{
    handle_errors(ex, [&]() {
        const size_t count = collection->size();
        if (ndx >= count)
            throw IndexOutOfRangeException("Get from Collection", ndx, count);
        
        value.has_value = true;
        switch (value.type) {
            case realm::PropertyType::Bool:
                value.value.bool_value = collection->template
                get<bool>(ndx);
                break;
            case realm::PropertyType::Bool | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<bool>>(ndx);
                value.has_value = !!result;
                value.value.bool_value = result.value_or(false);
                break;
            }
            case realm::PropertyType::Int:
                value.value.int_value = collection->template get<int64_t>(ndx);
                break;
            case realm::PropertyType::Int | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<int64_t>>(ndx);
                value.has_value = !!result;
                value.value.int_value = result.value_or(0);
                break;
            }
            case realm::PropertyType::Float:
                value.value.float_value = collection->template get<float>(ndx);
                break;
            case realm::PropertyType::Float | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<float>>(ndx);
                value.has_value = !!result;
                value.value.float_value = result.value_or((float)0);
                break;
            }
            case realm::PropertyType::Double:
                value.value.double_value = collection->template get<double>(ndx);
                break;
            case realm::PropertyType::Double | realm::PropertyType::Nullable: {
                auto result = collection->template get<Optional<double>>(ndx);
                value.has_value = !!result;
                value.value.double_value = result.value_or((double)0);
                break;
            }
            case realm::PropertyType::Date:
                value.value.int_value = to_ticks(collection->template get<Timestamp>(ndx));
                break;
            case realm::PropertyType::Date | realm::PropertyType::Nullable: {
                auto result = collection->template get<Timestamp>(ndx);
                value.has_value = !result.is_null();
                value.value.int_value = result.is_null() ? 0 : to_ticks(result);
                break;
            }
            default:
                REALM_UNREACHABLE();
        }
    });
}
Exemplo n.º 2
0
bool LineLayer::Impl::queryIntersectsGeometry(
        const GeometryCollection& queryGeometry,
        const GeometryCollection& geometry,
        const float bearing,
        const float pixelsToTileUnits) const {

    const float halfWidth = getLineWidth() / 2.0 * pixelsToTileUnits;

    auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
            queryGeometry, paint.lineTranslate, paint.lineTranslateAnchor, bearing, pixelsToTileUnits);
    auto offsetGeometry = offsetLine(geometry, paint.lineOffset * pixelsToTileUnits);

    return util::multiPolygonIntersectsBufferedMultiLine(
            translatedQueryGeometry.value_or(queryGeometry),
            offsetGeometry.value_or(geometry),
            halfWidth);
}
Exemplo n.º 3
0
    fs::path get_user_dir()
    {
#if defined(_WIN32)
        return get_localappdata() / "vcpkg";
#else
        auto maybe_home = System::get_environment_variable("HOME");
        return fs::path(maybe_home.value_or("/var")) / ".vcpkg";
#endif
    }
Exemplo n.º 4
0
// this is how'd you do it with std::optional
int task_std(const std::string& str)
{
    auto c = back(str);
    if (!c)
        return 0;
    auto upper_case = std::toupper(c.value());
    auto result     = lookup(upper_case);
    return result.value_or(0);
}
Exemplo n.º 5
0
Arquivo: main.cpp Projeto: CCJY/coliru
int main()
{
    optional<std::string> opt;                        /* opt is empty */
    std::cout << opt << std::endl;                    /* >$ nothing */
    opt = "Hi";                                       /* opt is "Hi" */
    std::cout << opt << std::endl;                    /* >$ just Hi */
    opt = nullopt;                                    /* opt is empty */
    std::cout << opt << std::endl;                    /* >$ nothing */
    opt = "Hi";                                       /* opt is "Hi" */
    auto opt2 = opt;                                  /* opt2 is "Hi" */
    std::cout << opt2 << std::endl;                   /* >$ just Hi */
    auto opt3 = std::move(opt);                       /* opt3 is "Hi", opt is garbage (!!!) */
    std::cout << opt3 << std::endl;                   /* >$ just Hi */
    opt3 = nullopt;                                   /* opt3 is empty */
    std::cout << opt3 << std::endl;                   /* >$ nothing */
    std::cout << opt3.value_or("smth") << std::endl;  /* >$ smth */
    std::cout << opt2.value_or("smth") << std::endl;  /* >$ Hi   */
    std::cout << sizeof(opt) << std::endl;            /* no dynamic memory is use so sizeof is the complete size of the object */
                                                      /* = sizeof(std::string) + sizeof(bool) + few bytes of alignment */
                                                      /* prints 16 for g++-4.8, may be different*/
}
Exemplo n.º 6
0
bool CircleLayer::Impl::queryIntersectsGeometry(
        const GeometryCoordinates& queryGeometry,
        const GeometryCollection& geometry,
        const float bearing,
        const float pixelsToTileUnits) const {

    auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
            queryGeometry, paint.evaluated.get<CircleTranslate>(), paint.evaluated.get<CircleTranslateAnchor>(), bearing, pixelsToTileUnits);

    auto circleRadius = paint.evaluated.get<CircleRadius>() * pixelsToTileUnits;

    return util::polygonIntersectsBufferedMultiPoint(
            translatedQueryGeometry.value_or(queryGeometry), geometry, circleRadius);
}
bool RenderFillExtrusionLayer::queryIntersectsFeature(
        const GeometryCoordinates& queryGeometry,
        const GeometryTileFeature& feature,
        const float,
        const float bearing,
        const float pixelsToTileUnits) const {

    auto translatedQueryGeometry = FeatureIndex::translateQueryGeometry(
            queryGeometry,
            evaluated.get<style::FillExtrusionTranslate>(),
            evaluated.get<style::FillExtrusionTranslateAnchor>(),
            bearing,
            pixelsToTileUnits);

    return util::polygonIntersectsMultiPolygon(translatedQueryGeometry.value_or(queryGeometry), feature.getGeometries());
}
Exemplo n.º 8
0
 constexpr auto operator()(Def) const
 {
   constexpr auto children = hana::second(Def{});
   constexpr auto single_provider = hana::transform(hana::find(children, tag::Provider),
       hana::partial(mpdef::make_tree_node, tag::Provider));
   constexpr auto providers = hana::find(children, tag::Providers);
   static_assert(hana::value(
     ((single_provider == hana::nothing) || (providers == hana::nothing))
     && hana::not_(single_provider == hana::nothing && providers == hana::nothing)
   ), "A definition of a Provider or Providers is required.");
   return decltype(
     helper(providers.value_or(
         hana::maybe(mpdef::make_list(), mpdef::make_list, single_provider)
       )
     )
   ){};
 }
Exemplo n.º 9
0
    //! Allocate storage and populate the volume.
    void AMRVolume::commit()
    {
      updateEditableParameters();

      // Make the voxel value range visible to the application.
      if (findParam("voxelRange") == nullptr)
        setParam("voxelRange", voxelRange);
      else
        voxelRange = getParam2f("voxelRange", voxelRange);

      auto methodStringFromEnv =
          utility::getEnvVar<std::string>("OSPRAY_AMR_METHOD");

      std::string methodString =
          methodStringFromEnv.value_or(getParamString("amrMethod","current"));

      if (methodString == "finest" || methodString == "finestLevel")
        ispc::AMR_install_finest(getIE());
      else if (methodString == "current" || methodString == "currentLevel")
        ispc::AMR_install_current(getIE());
      else if (methodString == "octant")
        ispc::AMR_install_octant(getIE());

      if (data != nullptr) //TODO: support data updates
        return;

      brickInfoData = getParamData("brickInfo");
      assert(brickInfoData);
      assert(brickInfoData->data);

      brickDataData = getParamData("brickData");
      assert(brickDataData);
      assert(brickDataData->data);

      data  = make_unique<amr::AMRData>(*brickInfoData,*brickDataData);
      accel = make_unique<amr::AMRAccel>(*data);

      // finding coarset cell size + finest level cell width
      float coarsestCellWidth = 0.f;
      float finestLevelCellWidth = data->brick[0].cellWidth;
      box3i rootLevelBox = empty;

      for (auto &b : data->brick) {
        if (b.level == 0)
          rootLevelBox.extend(b.box);
        finestLevelCellWidth = min(finestLevelCellWidth, b.cellWidth);
        coarsestCellWidth    = max(coarsestCellWidth, b.cellWidth);
      }

      vec3i rootGridDims = rootLevelBox.size() + vec3i(1);
      ospLogF(1) << "found root level dimensions of " << rootGridDims;
      ospLogF(1) << "coarsest cell width is " << coarsestCellWidth << std::endl;

      auto rateFromEnv =
          utility::getEnvVar<float>("OSPRAY_AMR_SAMPLING_STEP");

      float samplingStep = rateFromEnv.value_or(0.1f * coarsestCellWidth);

      box3f worldBounds = accel->worldBounds;

      const vec3f gridSpacing = getParam3f("gridSpacing", vec3f(1.f));
      const vec3f gridOrigin  = getParam3f("gridOrigin", vec3f(0.f));

      voxelType =  getParamString("voxelType", "unspecified");
      auto voxelTypeID = getVoxelType();

      switch (voxelTypeID) {
      case OSP_UCHAR:
        break;
      case OSP_SHORT:
        break;
      case OSP_USHORT:
        break;
      case OSP_FLOAT:
        break;
      case OSP_DOUBLE:
        break;
      default:
        throw std::runtime_error("amrVolume unsupported voxel type '"
                                 + voxelType + "'");
      }

      ispc::AMRVolume_set(getIE(), (ispc::box3f&)worldBounds, samplingStep,
                          (const ispc::vec3f&)gridOrigin,
                          (const ispc::vec3f&)gridSpacing);

      ispc::AMRVolume_setAMR(getIE(),
                             accel->node.size(),
                             &accel->node[0],
                             accel->leaf.size(),
                             &accel->leaf[0],
                             accel->level.size(),
                             &accel->level[0],
                             voxelTypeID,
                             (ispc::box3f &)worldBounds);

      tasking::parallel_for(accel->leaf.size(),[&](size_t leafID) {
        ispc::AMRVolume_computeValueRangeOfLeaf(getIE(), leafID);
      });
    }