Пример #1
0
CachedPalette CachedPalette::fromColors(std::initializer_list<Color>v) {
  CachedPalette pal(v.size());
  auto it = v.begin();
  for (int i = 0; i < pal.levels(); i++)
    pal[i] = *(it++);
  return pal;
}
Пример #2
0
void test ( const std::initializer_list<T> &vals ) {
    typedef std::dynarray<T> dynA;
    
    dynA d1 ( vals );
    assert ( d1.size () == vals.size() );
    assert ( std::equal ( vals.begin (), vals.end (), d1.begin (), d1.end ()));
    }
Пример #3
0
Matrix::Matrix(std::initializer_list<double> v) : nr(v.size()), nc(1) {
  data = new double [nr];

  int i = 0;
  for (double d : v)
    data[i++] = d;
}
Пример #4
0
	bool setHeader(std::initializer_list<std::string> list) {
		if (list.size() != Columns) {
			return false;
		}
		header.insert(header.begin(), list);
		return true;
	}
double comb(std::initializer_list<double> values) {
    double sum = 0.0;
    for (double value: values) {
        sum += value;
    }
    return (sum/values.size());
}
void		IGraphicObject::mFunction_AddVertices2D(NOISE_GRAPHIC_OBJECT_TYPE buffType, std::initializer_list<NVECTOR2> vertexList, std::initializer_list<NVECTOR4> colorList, std::initializer_list<NVECTOR2> texcoordList)
{

	N_SimpleVertex tmpVertex;
	auto vertexIter = vertexList.begin();
	auto colorIter = colorList.begin();
	auto texcoordIter = texcoordList.begin();

	//construct a N_SimpleVertex
	for (UINT i = 0;i < vertexList.size();i++)
	{

		tmpVertex = 
		{
			NVECTOR3(vertexIter->x+m_pBaseScreenSpacePosOffset->x,vertexIter->y + m_pBaseScreenSpacePosOffset->y,0.0f),
			*colorIter++,
			*texcoordIter++
		};
		vertexIter++;

		m_pVB_Mem[buffType]->push_back(tmpVertex);
	}

	//now it is allowed to update because of modification
	mCanUpdateToGpu[buffType] = TRUE;
}
Пример #7
0
ProtocolDescriptorTestNode::ProtocolDescriptorTestNode(QString name, std::initializer_list<ProtocolDescriptorTestNode> init) {
    qDebug() << "*** CONSTRUCTOR CALLED - 2 *** ";
    qDebug() << init.size();
    for(ProtocolDescriptorTestNode x : init) {
        qDebug() << x.name << x.id;
    }
}
Пример #8
0
Set<T>::Set(std::initializer_list<T> args) : map()
{
  reserve(args.size());
  for (const auto &elm : args) {
    insert(elm);
  }
}
UIntVector::UIntVector(const std::initializer_list<unsigned int>& list) : count(list.size()), max_size(1 << static_cast<int>(ceil(log2(count)))), data(new unsigned int[max_size]) {
  size_t i;
  std::initializer_list<unsigned int>::iterator item;
  for(i = 0, item = list.begin(); item != list.end(); ++i, ++item) {
    data[i] = *item;
  }
}
Пример #10
0
// Constructor with initializer list
DNA::DNA(const std::initializer_list<unsigned char> inputList) {
    dataSize = inputList.size();

    // Initialize genes
    dataGenes = (unsigned char*) malloc(dataSize * sizeof(unsigned char));
    std::memcpy(dataGenes, inputList.begin(), dataSize);
}
Пример #11
0
std::string format(const char* fmt, std::initializer_list<Printable> values)
{
    std::stringstream ss;
    while (*fmt) {
        auto next = strchr(fmt, '%');

        // emit the rest of the format string if there are no more percents
        if (!next) {
            ss << fmt;
            break;
        }

        // emit everything up to the next percent
        ss.write(fmt, next - fmt);
        ++next;
        REALM_ASSERT(*next);

        // %% produces a single escaped %
        if (*next == '%') {
            ss << '%';
            fmt = next + 1;
            continue;
        }
        REALM_ASSERT(isdigit(*next));

        // The const_cast is safe because stroul does not actually modify
        // the pointed-to string, but it lacks a const overload
        auto index = strtoul(next, const_cast<char**>(&fmt), 10) - 1;
        REALM_ASSERT(index < values.size());
        (values.begin() + index)->print(ss);
    }
    return ss.str();
}
Пример #12
0
std::shared_ptr<cainteoir::buffer> zip_archive::read(const char *aFilename) const
{
	std::string filename = aFilename;
	auto entry = data.find(filename);
	if (entry == data.end())
	{
		size_t pos = 0;
		while ((pos = filename.find("%20", pos)) != std::string::npos)
		{
			filename.replace(pos, 3, " ");
			++pos;
		}
		entry = data.find(filename);
	}
	if (entry == data.end())
		return std::shared_ptr<cainteoir::buffer>();

	const zip_data &item = entry->second;
	if (item.cached) return item.cached;

	auto decoder = *(zip_compression.begin() + item.compression_type);
	if (item.compression_type >= zip_compression.size() || decoder == nullptr)
		throw std::runtime_error(i18n("decompression failed (unsupported compression type)"));

	cainteoir::buffer compressed { item.begin, item.begin + item.compressed };

	return const_cast<zip_data &>(item).cached = decoder(compressed, item.uncompressed);
}
Пример #13
0
	// Set with initializer list
	Set(const std::initializer_list<value_type>& l) {
		_set.reserve(l.size());
		
		for (const auto& value : l) {
			insert(value);
		}
	}
Пример #14
0
BinTree::BinTree(std::initializer_list<int> inlist)
{
	if (inlist.size()==0) return;
	root = new Node(*inlist.begin());
	for (auto& el : inlist)
		insert(el);
}
Пример #15
0
Vector<T>::Vector(const std::initializer_list<T> args) : size_array(args.size()), cap_array(args.size()*2), array(new T[cap_array]) {
	int i = 0;
	for (auto iter = args.begin(); iter != args.end(); ++iter) {
		array[i] = *iter;
		++i;
	}
}
Пример #16
0
static void emitDeallocatingCall(IRGenFunction &IGF, llvm::Constant *fn,
                                 std::initializer_list<llvm::Value *> args) {
  llvm::CallInst *call =
    IGF.Builder.CreateCall(fn, makeArrayRef(args.begin(), args.size()));
  call->setCallingConv(IGF.IGM.RuntimeCC);
  call->setDoesNotThrow();
}
Пример #17
0
long int VariableSet::var(std::string name,
                          std::initializer_list<unsigned int > coord)
{
    unsigned int index = subset_indices[name];
    if (coord.size() != subset_dimensions[index].size())
        throw std::domain_error(
            "Too much coordinates for VariableSet.var().");
    unsigned int i = 0;
    long int code = 0;
    for (auto c = coord.begin(); c != coord.end(); c++)
    {
        if (*c >= subset_dimensions[index][i])
        {
            std::stringstream msg;
            msg << "Coordinate " << i
                << " for VariableSet.var() is too large ("
                << (*c) << " >= " << subset_dimensions[index][i] << ").";
            throw std::out_of_range(msg.str());
        }
        if (i == 0)
            code = *c;
        else
            code = *c + subset_dimensions[index][i]*code;
        i++;
    }
    code += subset_cumulated_sizes[index] + 1;

    return code;
}
bool TestReadWrite(typename T::type_t value, std::initializer_list<uint8_t> expected)
{
    Buffer buffer(T::size);

    auto dest = buffer.as_wslice();
    if (!T::write_to(dest, value)) return false;

    if(dest.is_not_empty()) return false;

    if (expected.size() != T::size)
    {
        return false;
    }

    auto i = 0;

    for (auto& byte : expected)
    {
        if (buffer.as_rslice()[i] != byte)
        {
            return false;
        }
        ++i;
    }

    typename T::type_t read_value;

    auto input = buffer.as_rslice();

    return T::read_from(input, read_value) && input.is_empty() && (read_value == value);

}
Пример #19
0
bool Reader::peekList(std::initializer_list<unsigned char> list) {
  if (list.size() == 0) {
    return false;
  }
  const QByteArray parr = dev.peek(list.size());
  if (parr.size() != list.size()) {
    return false;
  }
  int i{0};
  for (auto it = list.begin(); it != list.end(); it++, i++) {
    if (*it != (unsigned char) parr[i]) {
      return false;
    }
  }
  return true;
}
Пример #20
0
template<UnsignedInt dimensions> void Listener<dimensions>::update(std::initializer_list<std::reference_wrapper<PlayableGroup<dimensions>>> groups) {

    /* Check if active listener just changed to this */
    if(this != Implementation::activeListener) {
        /* Ensure that clean() is called also when switching between (clean)
           listeners */
        Implementation::activeListener = this;
        this->object().setDirty();

        /* Listener gain needs to be updated only when active listener changed
           and in setGain() */
        Renderer::setListenerGain(_gain);
    }

    /* Add all objects of the Playables in the PlayableGroups to a vector to
       later setClean() */
    std::vector<std::reference_wrapper<AbstractObject<dimensions, Float>>> objects;

    objects.push_back(this->object());
    for(PlayableGroup<dimensions>& group : groups) {
        for(UnsignedInt i = 0; i < groups.size(); ++i) {
            objects.push_back(group[i].object());
        }
    }

    /* Use the more performant way to set multiple objects clean */
    AbstractObject<dimensions, Float>::setClean(objects);
}
Пример #21
0
Polynomial PolyDomain::operator()(const std::initializer_list<BigUnsigned>& c) const {
    std::vector<FieldElement> coeffs(c.size());
    std::transform(c.begin(), c.end(), coeffs.begin(), [&](const BigUnsigned& b) {
                        return field->makeElement(b);
                   });
    return makeElement(coeffs);
}
Пример #22
0
void testVarint(uint64_t val, std::initializer_list<uint8_t> bytes) {
  size_t n = bytes.size();
  ByteRange expected(&*bytes.begin(), n);

  {
    uint8_t buf[kMaxVarintLength64];
    EXPECT_EQ(expected.size(), encodeVarint(val, buf));
    EXPECT_TRUE(ByteRange(buf, expected.size()) == expected);
  }

  {
    ByteRange r = expected;
    uint64_t decoded = decodeVarint(r);
    EXPECT_TRUE(r.empty());
    EXPECT_EQ(val, decoded);
  }

  if (n < kMaxVarintLength64) {
    // Try from a full buffer too, different code path
    uint8_t buf[kMaxVarintLength64];
    memcpy(buf, &*bytes.begin(), n);

    uint8_t fills[] = {0, 0x7f, 0x80, 0xff};

    for (uint8_t fill : fills) {
      memset(buf + n, fill, kMaxVarintLength64 - n);
      ByteRange r(buf, kMaxVarintLength64);
      uint64_t decoded = decodeVarint(r);
      EXPECT_EQ(val, decoded);
      EXPECT_EQ(kMaxVarintLength64 - n, r.size());
    }
  }
}
Пример #23
0
void addToMatrix(PETScMatrix& m,
                 std::initializer_list<double> values)
{
    using IndexType = PETScMatrix::IndexType;

    auto const rows = m.getNumberOfRows();
    auto const cols = m.getNumberOfColumns();

    assert((IndexType) values.size() == rows*cols);

    Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> tmp(rows, cols);

    auto it = values.begin();
    for (IndexType r=0; r<rows; ++r) {
        for (IndexType c=0; c<cols; ++c) {
            tmp(r, c) = *(it++);
        }
    }

    std::vector<IndexType> row_idcs(rows);
    std::vector<IndexType> col_idcs(cols);

    std::iota(row_idcs.begin(), row_idcs.end(), 0);
    std::iota(col_idcs.begin(), col_idcs.end(), 0);

    m.add(row_idcs, col_idcs, tmp);
}
 OpenGlVec(std::initializer_list<T> list)
 {
   assert(list.size() <= N);
   auto itr = list.begin();
   for(std::size_t i = 0; i < N; ++i)
     std::array<T,N>::operator[](i) = itr != list.end() ? *(itr++) : T(0);
 }
Пример #25
0
CommandExecutor::CommandExecutor(State::Value state, 
	const std::initializer_list<Commandable*> commandables) :
	_state(state),
	_commandables(commandables.size())
{
	std::copy(commandables.begin(), commandables.end(), _commandables.begin());
}
Пример #26
0
static SliceElem startFromList(const std::initializer_list<T>& list)
{
    if(list.size() >= 1)
        return SliceElem(*list.begin());
    
    return SliceElem();
}
Пример #27
0
Edge::Edge(std::initializer_list<std::string> verts)
    : weight(0)
{
    assert(verts.size() == 2);
    this->vertexA = *verts.begin();
    this->vertexB = *std::next(verts.begin());
}
Пример #28
0
const wchar_t* Networking::NetworkEnumNames::GetIANAInterfaceTypeName(uint32_t interfaceType)
{
	if (interfaceType < kIANAInterfaceTypeNames.size())
		return *(kIANAInterfaceTypeNames.begin() + interfaceType);

	return L"Unknown";
}
Пример #29
0
 // cross-list operation
 void operator =(std::initializer_list<T> vallist){ //List a = {a, b};
     clear();
     std::vector<T> v;
     v.insert(v.end(), vallist.begin(), vallist.end());
     for(int i=0;i<vallist.size();i++)
         add(v[i]);
 }
Пример #30
0
bool SAVectorInterval::setAt(const QVariant &val, const std::initializer_list<size_t> &index)
{
    if(1 == index.size())
    {
        return SAVectorDatas<QwtIntervalSample>::setAt(val,index);
    }
    else if(index.size()>=2)
    {
        for(auto i=(index.begin()+2);i!=index.end();++i)
        {
            if(0!=(*i))
            {
                return false;
            }
        }
        int r = *(index.begin());
        if(r < 0 || r >  getValueDatas().size())
        {
            return false;
        }
        QwtIntervalSample& sam = get(r);
        int c = *(index.begin()+1);
        bool isOK = false;
        double d = val.toDouble(&isOK);
        if(!isOK)
            return false;
        if(0 == c)
        {
            sam.value = d;
        }
        else if(1 == c)
        {
            sam.interval.setMinValue(d);
        }
        else if(2 == c)
        {
            sam.interval.setMaxValue(d);
        }
        else
        {
            return false;
        }
        setDirty(true);
        return true;
    }
    return false;
}