Esempio n. 1
0
inline bool
operator == (range<char const*> const &value, range<char const*> const &other) {
	if (value.size() == other.size()) {
		return value.empty() ? true : strncmp(value.begin(), other.begin(), value.size()) == 0;
	}
	return false;
}
Esempio n. 2
0
template <typename Iter, typename Other> inline bool
operator == (range<Iter> const &value, range<Other> const &other) {
	if (value.size() == other.size()) {
		return value.empty() ? true : std::equal(value.begin(), value.end(), other.begin());
	}
	return false;
}
Esempio n. 3
0
inline range<Iter2_t> init_move ( const range<Iter2_t> & dest,
                                  const range<Iter1_t> & src)
{   //------------- static checking ------------------------------------------
    typedef typename iterator_traits<Iter1_t>::value_type type1 ;
    typedef typename iterator_traits<Iter2_t>::value_type type2 ;
    static_assert ( std::is_same<type1, type2>::value,
                    "Incompatible iterators\n");

    //------------------------------- begin ----------------------------------
    if ( src.size() == 0 ) return range<Iter2_t>(dest.first, dest.first);
    init_move(dest.first ,src.first, src.last  );
    return range<Iter2_t>(dest.first, dest.first + src.size()) ;
};
Esempio n. 4
0
void generic_par_for_wg(range<Dimensions> k_range,
                        range<Dimensions> workgroup_size) {
  queue my_queue;

  // the product of all Dimensions e.g. 10*10*10 for {10,10,10}
  auto linr_size = k_range.size(), linwg_size = workgroup_size.size();

  // these will simply have the group, local and global linear ids assigned to
  // them
  auto group_lin = buffer<int>(linr_size / linwg_size);
  auto loc_lin = buffer<int>(linr_size);
  auto gl_lin = buffer<int>(linr_size);

  my_queue.submit([&](handler &cgh) {
    auto group_lin_acc = group_lin.get_access<access::mode::write>(cgh);
    auto loc_lin_acc = loc_lin.get_access<access::mode::write>(cgh);
    auto gl_lin_acc = gl_lin.get_access<access::mode::read_write>(cgh);

    cgh.parallel_for_work_group<kernel_name>(
        nd_range<Dimensions>(k_range, workgroup_size),
        [=](group<Dimensions> group) {
          group_lin_acc[group.get_linear_id()] = group.get_linear_id();

          group.parallel_for_work_item([=](h_item<Dimensions> tile) {
            loc_lin_acc[tile.get_global_linear_id()] =
                tile.get_local_linear_id();
            gl_lin_acc[tile.get_global_linear_id()] =
                tile.get_global_linear_id();
          });
        });
  });

  auto loc_lin_out = loc_lin.get_access<access::mode::read>();
  auto group_lin_out = group_lin.get_access<access::mode::read>();
  auto gl_lin_out = gl_lin.get_access<access::mode::read>();

  for (int i = 0; i < linr_size / linwg_size; ++i) {
    BOOST_CHECK(group_lin_out[i] == i); // group id
  }

  for (int i = 0; i < linr_size; ++i) {
    BOOST_CHECK(gl_lin_out[i] == i);                            // w1 global id
    BOOST_CHECK(loc_lin_out[i] == loc_lin_out[i] % linwg_size); // local id
  }

  /* We must wait for for the queue to finish as none of buffer's destruction
     is blocking.
   */
  my_queue.wait();
}
Esempio n. 5
0
void database::add(range key, range data)
{
    assert(_db);
    struct slice sk, sv;

    sk.data  = const_cast<char*>(key.begin());
    sk.len = key.size();
    sv.data  = const_cast<char*>(data.begin());
    sv.len = data.size();

    if (::db_add(_db, &sk, &sv) == 0)
    {
        throw exception("error adding to ness backend");
    }
}
Esempio n. 6
0
 virtual std::size_t take (const range& data)
 {
     detail::dummy_input_take_impl ();
     typename range::value_type zero (
         sound::sample_traits<
             typename sound::sample_type<range>::type
             >::zero_value ());
     fill_frames (data, zero);
     return data.size ();
 }
Esempio n. 7
0
void database::del(range key)
{
    assert(_db);
    struct slice sk;

    sk.data  = const_cast<char*>(key.begin());
    sk.len = key.size();

    ::db_remove(_db, &sk);
}
 __forceinline NodeRef operator() (const PrimRef* prims, const range<size_t>& set, const FastAllocator::CachedAllocator& alloc) const
 {
   size_t n = set.size();
   size_t items = Primitive::blocks(n);
   size_t start = set.begin();
   Primitive* accel = (Primitive*) alloc.malloc1(items*sizeof(Primitive),BVH::byteAlignment);
   typename BVH::NodeRef node = BVH::encodeLeaf((char*)accel,items);
   for (size_t i=0; i<items; i++) {
     accel[i].fill(prims,start,set.end(),bvh->scene);
   }
   return node;
 }
Esempio n. 9
0
	[[nodiscard]]
	inline size_t read(std::istream& Stream, const range<char*>& Buffer)
	{
		{
			const auto Exceptions = Stream.exceptions();
			Stream.exceptions(Exceptions & ~(Stream.failbit | Stream.eofbit));
			SCOPE_EXIT{ Stream.exceptions(Exceptions); };

			Stream.read(Buffer.data(), Buffer.size());
			if (!Stream.bad() && Stream.eof())
				Stream.clear();
		}

		return Stream.gcount();
	}
Esempio n. 10
0
			range<byte*> read(const range<byte*>& buf)
			{
				zstream.avail_out = uInt(buf.size());
				zstream.next_out = (Bytef*)buf.begin();

				for(;zstream.avail_out != 0;){
					if (zstream.avail_in == 0){
						new_input_();
					}

					auto res = ::inflate(&zstream, Z_NO_FLUSH);
					switch(res)
					{
						case Z_NEED_DICT:
							{
								if (dict.empty())
									AIO_THROW(inflate_exception)("Need dictionary");
								auto dic_err = inflateSetDictionary(&zstream, (Bytef*)dict.begin(), dict.size());
								if (dic_err != Z_OK)
									AIO_THROW(inflate_exception)("Bad dictionary");
							}
						case Z_OK:
							break;
						case Z_DATA_ERROR:
							AIO_THROW(inflate_exception)("Z_DATA_ERROR");
						case Z_MEM_ERROR:
							AIO_THROW(inflate_exception)("Z_MEM_ERROR");
						case Z_STREAM_END:
							uncompressed_size = zstream.total_out;
							return range<byte*>((buf.size() - zstream.avail_out) + buf.begin(), buf.end());
						default:
							AIO_THROW(inflate_exception)("zlib internal error");
					}
				}
				return range<byte*>(buf.end() - zstream.avail_out, buf.end());
			}
Esempio n. 11
0
std::string database::get(range key)
{
    assert(_db);
    struct slice sk, sv;

    sk.data  = const_cast<char*>(key.begin());
    sk.len = key.size();

    if (::db_get(_db, &sk, &sv) == 0)
    {
        throw exception("error reading from ness backend");
    }

    // copy the data out
    std::string result(sv.data, sv.len);
    ::free(sv.data);
    return result;
}
Esempio n. 12
0
			range<const byte*> write(const range<const byte*>& buf){
				AIO_PRE_CONDITION(!finished);
				AIO_PRE_CONDITION(zstream.avail_in == 0);
				crc = crc32(buf, crc);
				zstream.next_in = (Bytef*)buf.begin();
				zstream.avail_in = uInt(buf.size());

				for(;zstream.avail_in != 0;){
					if (zstream.avail_out ==0 )
						new_buffer_();

					switch (deflate(&zstream, Z_NO_FLUSH)){
						case Z_OK:
						case Z_BUF_ERROR:
							break;
						default:
							AIO_THROW(deflate_exception)("deflate with Z_NO_FLUSH failed");
					}
				}
				return range<const byte*>(buf.end(), buf.end());
			}
Esempio n. 13
0
static bool ProcessServiceModes(range<const wchar_t* const*> const Args, int& ServiceResult)
{
	const auto& isArg = [](const wchar_t* Arg, string_view const Name)
	{
		return (*Arg == L'/' || *Arg == L'-') && equal_icase(Arg + 1, Name);
	};

	if (Args.size() == 4 && IsElevationArgument(Args[0])) // /service:elevation {GUID} PID UsePrivileges
	{
		ServiceResult = ElevationMain(Args[1], std::wcstoul(Args[2], nullptr, 10), *Args[3] == L'1');
		return true;
	}

	if (InRange(2u, Args.size(), 5u) && (isArg(Args[0], L"export"sv) || isArg(Args[0], L"import"sv)))
	{
		const auto Export = isArg(Args[0], L"export"sv);
		string strProfilePath(Args.size() > 2 ? Args[2] : L""), strLocalProfilePath(Args.size() > 3 ? Args[3] : L""), strTemplatePath(Args.size() > 4 ? Args[4] : L"");
		InitTemplateProfile(strTemplatePath);
		InitProfile(strProfilePath, strLocalProfilePath);
		Global->m_ConfigProvider = new config_provider(Export? config_provider::mode::m_export : config_provider::mode::m_import);
		ServiceResult = !ConfigProvider().ServiceMode(Args[1]);
		return true;
	}

	if (InRange(1u, Args.size(), 3u) && isArg(Args[0], L"clearcache"sv))
	{
		string strProfilePath(Args.size() > 1 ? Args[1] : L"");
		string strLocalProfilePath(Args.size() > 2 ? Args[2] : L"");
		InitProfile(strProfilePath, strLocalProfilePath);
		config_provider::ClearPluginsCache();
		ServiceResult = 0;
		return true;
	}

	return false;
}
Esempio n. 14
0
 vector_range(VectorType & v, range const & entry_range)
  : base_type(v.handle(), entry_range.size(), v.start() + v.stride() * entry_range.start(), v.stride()) {}
Esempio n. 15
0
 virtual std::size_t put (const range& data)
 {
     detail::dummy_output_put_impl ();
     return data.size ();
 }
Esempio n. 16
0
void DialogBuilder::AddButtons(range<const lng*> const Buttons, size_t const OkIndex, size_t const CancelIndex)
{
	base::AddButtons(static_cast<int>(Buttons.size()), reinterpret_cast<const int*>(Buttons.data()), static_cast<int>(OkIndex), static_cast<int>(CancelIndex));
}
Esempio n. 17
0
 matrix_range(matrix_range<MatrixType> const & A,
              range const & row_range,
              range const & col_range) : base_type(const_cast<handle_type &>(A.handle()),
                                                   row_range.size(), row_range.start() * A.stride1() + A.start1(), A.stride1(), A.internal_size1(),
                                                   col_range.size(), col_range.start() * A.stride2() + A.start2(), A.stride2(), A.internal_size2(),
                                                   A.row_major()) {}
Esempio n. 18
0
inline bool
operator > (range<char const*> const &value, range<char const*> const &other) {
	return (!value.empty() && !other.empty()) ? (strncmp(value.begin(), other.begin(), std::max(value.size(), other.size())) > 0) : !value.empty();
}
Esempio n. 19
0
 vector_range(vector_range<VectorType> const & v, range const & entry_range)
   : base_type(const_cast<handle_type &>(v.handle()),
               entry_range.size(), v.start() + v.stride() * entry_range.start(), v.stride()) {}
Esempio n. 20
0
	uint32_t crc32(range<const byte*> src, uint32_t crc /* = crc32_init() */){
		return ::crc32(crc, (const Bytef*)src.begin(), (uInt)src.size());
	}