示例#1
0
文件: Grid.hpp 项目: uzgoren/girdap
  // // //Add cell to the list
  void addCell(initializer_list<int_8 > l) {    
    if (l.size() == 2) {
      listCell.emplace_back( shared_ptr<Cell > (new Line(l)) ); 
 //     //listCell.emplace_back(shared_ptr<Cell > (new Line(tmp)) );
    } else if (l.size() == 3) {
  //     //listCell.emplace_back(shared_ptr<Cell > (new Tri(tmp)) ); 
    } else if (l.size() == 4) {
      listCell.emplace_back( shared_ptr<Cell > (new Quad(l)) ); 
    } else if (l.size() == 8) {
       //listCell.emplace_back( shared_ptr<Cell > (new Hexa(tmp)) ); 
    } else {
      cout << "Cell type not understood!"<<endl; 
      exit(1); 
    }
    nCellSize += l.size() + 1;
    auto c = *(listCell.rbegin()); 

    c->id = listCell.size()-1;
    c->grid = this; 
    c->assignCelltoNode();
    for (auto v: listVar) {
      if (v->loc == 0) {
	v->data.push_back(0); 
	v->data.uncompress();
      }
    }
    c->masterx.resize(levelHighBound[0]+1, false); 
    c->mastery.resize(levelHighBound[1]+1, false); 
    c->masterz.resize(levelHighBound[2]+1, false); 
  }
int makeSum(initializer_list<int> lst)
{
    int total = 0;
    for(auto iter = lst.begin(); iter!=lst.end(); ++iter)
	total += (*iter);
    return total;
}
	PointSequence(initializer_list<double> args)
	{
		if (args.size() % 2 != 0)
			throw invalid_argument("initializer_list should contain even number of elements.");
		for (auto iter = args.begin(); iter != args.end(); ++iter)
			mVecPoints.push_back(*iter);
	}
示例#4
0
	Animation(int x, int y, initializer_list<char> chars, int speed = 5) : speed(speed), frame(1), counter(0)
	{
		Collision = true;
		Pos.Set(x, y);
		for(auto i = chars.begin(); i != chars.end(); ++i) frames.push_back(*i);
		Visual = frames[0];
	}
示例#5
0
SparseVector::SparseVector(long size, long default_val, initializer_list<pair<long,long> > list)
{
    if (size < 0) {
        throw range_error("SparseVector size cannot be negative.");
    } else {
        fixed_size_ = size;
        unset_val_ = default_val;
    }      
    
    long count = 0;
    for (auto i = list.begin(); i != list.end(); i++) {
        
        if (i->first < (fixed_size_ - 1) && i->first >= 0) {
                      
            if (i->second != unset_val_) {
                data_[i->first] = data_[i->second];
            }
            
        } else {
            throw range_error("Cannot set value at an index greater than the size - 1 or less than 0.");
        }
        
        ++count;
    }
}
EvenSequenceStr::EvenSequenceStr(initializer_list<string> args)
{
  if (args.size() % 2 != 0)
    throw invalid_argument(" initializer_list should contain even number of elements!");
  sSequence.reserve(args.size());
  //for (auto value : args)  sSequence.push_back(value);
  sSequence.insert(cend(sSequence), cbegin(args), cend(args)); // alternate to the above for loop
}
EvenSequenceNum::EvenSequenceNum(initializer_list<double> args)
{
  if (args.size() % 2 != 0)
    throw invalid_argument(" initializer_list should contain even number of elements!");
  mSequence.reserve(args.size());
  for (auto value : args)  mSequence.push_back(value);
   //mSequence.insert(cend(mSequence), cbegin(args), cend(args)); // alternate to the above for loop
}
示例#8
0
		Function(const char* name, const char* returns, initializer_list<char*> takes, const char* description) : Type(name) {
			this->takes = new char*[takes.size() + 1];
			int index = 0;
			for (auto i : takes) { this->takes[index++] = i; }
			this->takes[takes.size()] = 0;
			this->returns = returns;
			this->description = description;
		}
示例#9
0
 Vector(initializer_list<T> list) : size{list.size()}
 {
     cout << "initializer list constructor" << endl;
     int i = 0;
     a.reset(new T[size]);
     for (auto iter = list.begin(); iter != list.end(); ++iter, ++i)
         a.get()[i] = *iter;
 }
示例#10
0
StrVec::StrVec(initializer_list<string> il)
{
	reallocate(il.size());
	auto p = begin_iter;
	for (auto beg = il.begin(); beg != il.end(); ++beg)
		alloc.construct(p++, *beg);
	end_iter = p;
}
示例#11
0
int cal_sum(initializer_list<int> &list)
{
	int sum = 0;
	for (auto i = list.begin(); i != list.end(); ++i) {
		sum += *i;
	}
	return sum;
}
示例#12
0
int summation(initializer_list<int> val)
{
	int ret = 0;
	for (auto beg = val.begin(); beg != val.end(); ++beg)
	{
		ret += *beg;
	}
	return ret;
} 
示例#13
0
Image::Image(int _rows,int _cols,initializer_list<float> _data):rows(_rows),cols(_cols){
	this->allocate();

	#if IMAGE_SAFE == 1
		assert(_data.size() == rows*cols);
	#endif

	std::copy(_data.begin(), _data.end(), data.get());
}
示例#14
0
文件: Vector.cpp 项目: 3A9C/ITstep
Vector::Vector(initializer_list<double> args)
{
	auto it = args.begin();
	element_count = args.size();
	memory_size = element_count * 2;
	vector = (double*)malloc(memory_size * sizeof(double));
	int i;
	for (it, i = 0; it != args.end(); it++, i++)
		vector[i] = *it;
}
示例#15
0
	//local->world
	Matrix44 TransformHelper::CreateWorld(initializer_list<Matrix44> matrixOrder)
	{	//스케일, 자전, 이동, 공전, 부모 순으로 넣으면 된다.
		Matrix44 matWorld;
		for( auto iter = matrixOrder.begin(); iter != matrixOrder.end(); ++iter )
		{
			matWorld = (*iter) * matWorld;
		}

		return matWorld;
	}
示例#16
0
文件: Army.cpp 项目: Jakz/openmom
Army::Army(Player* owner, initializer_list<Unit*> units) : owner(owner), isPatrol(false), position(Position(-1, -1, ARCANUS)), route(nullptr)
{
    owner->add(this);

    for (auto u : units)
        add(u);

    if (units.begin() != units.end())
        updateMovementType();
}
Vector<T>::Vector(const initializer_list<T>& l) {
    static_assert(is_move_assignable<T>::value, "Type is not move assignable.");
    static_assert(is_move_constructible<T>::value, "Type is not move constructible."); // Can be constructed fr rvalue
    vectorsize = l.size();
    heap_size = l.size();
    array = new T[vectorsize];
    for (int i = 0; i < vectorsize; ++i) {
        array[i] = l.begin()[i];
    }
}
示例#18
0
void subscriptCheck(initializer_list<int> lst)
{
	cout<<"initializer_list subscript check\n";

	// for(int i = 0; i < lst.size(); ++i)
	// 	cout<<lst[i]<<'\n';   // error

	const int* p = lst.begin();
	for(int i = 0; i <  lst.size(); ++i)
		cout<<p[i]<<'\n';
}
示例#19
0
RunTimeContainer::RunTimeContainer(initializer_list<RunTime> initializer) {
	if (ZoneHandler::getZoneCount() != initializer.size()) {
		throw logic_error("ZoneHandler::getZoneCount() != initializer.size()");
	}

	container.reserve(ZoneHandler::getZoneCount());
	for (size_t i = 0; i < ZoneHandler::getZoneCount(); ++i) {
		shared_ptr<RunTime> runTime(new RunTime(*next(initializer.begin(), i)));
		container.push_back(make_pair(i, runTime));
	}
}
示例#20
0
    template<typename T> Polynomial(initializer_list<T> list){
        coeffs.resize(list.size());

        int i=list.size()-1;
        for(T t:list){
            coeffs[i]=t;
            i--;
        }

        reduce();
    }
示例#21
0
StateTreeNode::StateTreeNode(
	initializer_list<double> center,
	double halfSize,
	int maxDepth
) :
	numSpacePartitions(pow(2, center.size()))
{
	for(unsigned int n = 0; n < center.size(); n++)
		this->center.push_back(*(center.begin() + n));

	this->halfSize = halfSize;
	this->maxDepth = maxDepth;
}
示例#22
0
StrVec::StrVec(const initializer_list<string> &slist)
{
	size_t len = slist.size();
	auto newdata = alloc.allocate(len);
	auto dest = newdata;
	auto beg = slist.begin();
	while(beg != slist.end()){
		alloc.construct(dest++, std::move(*beg++));
	}
	
	elements = newdata;
	first_free = cap = dest;
}
示例#23
0
    Foo(initializer_list<Foo> list){
        cout << "initializer "<< list.size() << "-list: \n";

        size_t index = 0;
        for (const Foo &it : list){
            cout << "\titem " << index++ << " ";
            it.printValues();
        }

        cout << endl << "\tcopying values from first element of init_list.\n\t";
        *this = *list.begin();
        cout << endl;
    }
示例#24
0
/**
 * @brief calc_back_project : encapsulate calcHist, provide friendly api, all of the parameters meaning are same as
 * the calcHist
 */
void calc_histogram(initializer_list<Mat> images, OutputArray output, initializer_list<int> channels,
                    initializer_list<int> hist_sizes, initializer_list<float[2]> ranges,
InputArray mask, bool uniform, bool accumulate)
{
    size_t const sizes = ranges.size();
    vector<float const*> d_ranges(sizes);
    for(size_t i = 0; i != sizes; ++i){
        d_ranges[i] = *(begin(ranges) + i);
    }

    calcHist(begin(images), images.size(), begin(channels), mask, output,
                 channels.size(), begin(hist_sizes), &d_ranges[0], uniform ,accumulate);
}
    PointSequence(initializer_list<double> args)
    {
	cout << "size : " << args.size() << endl;
	if(args.size() % 2 != 0)
	{
	    throw invalid_argument("initializer_list should"
				   "contain even number of elements.");
	}

	for(auto iter = args.begin(); iter != args.end(); ++iter)
	{
	    mVecPoints.push_back(*iter);
	}
    }
示例#26
0
	/// Construct a matrix with the data given in two nested
	/// initializer_list's
	dense_matrix( const initializer_list<initializer_list<value_type>> &l )
	{
		// Compute sizes
		const initializer_list<value_type>* prow = l.begin();
		int	I = l.size();
		int	J = prow[0].size();
		for( int i = 1; i < I; i++ )
			assert( J == (int)prow[i].size() );

		// Fill the matrix
		this->resize(I,J);
		for( int i = 0; i < I; i++ )
			for( int j = 0; j < J; j++ )
				(*this)(i,j) = prow[i].begin()[j];
	}
示例#27
0
void Transformation::setTransformations(int _num, initializer_list<string> st)
{
	numOfOperations = _num;

	left.insert(left.begin(), st.begin(), st.begin() + _num);
	right.insert(right.begin(), st.begin() + _num, st.end());

	for (size_t i = 0; i < numOfOperations; ++i)
	{
		if (right[i] == ".")
		{
			right[i] = "";
		}
	}
}
示例#28
0
  Vector(initializer_list<_Tp> __li, const _Allocator& __a = _Allocator()) :
		alloc(__a), __size(0), __capacity(0) {
      buffer = alloc.allocate(__li.size());
      for (auto _list : __li)
        push_back(_list);
      __capacity = __size;
    }
示例#29
0
Model::Model(initializer_list<string> meshNames,
			 const string& diffuseName,
			 const string& specularName,
		 	 const string& ambientName,
		 	 const string& normalName,
		 	 float uniformScale,
			 float translateY,
			 float rotateY) {
	// Load meshes
	meshes.resize(meshNames.size());
	int i = 0;
	for (auto name : meshNames) {
		meshes[i].load(name);
		i += 1;
	}
	// Load textures
	diffuse.loadImage(diffuseName);
	specular.loadImage(specularName);
	if (useNormalMapping) {
		ambient.loadImage(ambientName);
		normal.loadImage(normalName);
		// Generate tangent values for normal mapping
		transform(begin(meshes), end(meshes), back_inserter(tangents), Model::generateTangents);
	}
	// Save scaling and translation values
	this->uniformScale = uniformScale;
	this->translateY = translateY;
	this->rotateY = rotateY;
}
示例#30
0
static const pair<vector<string>, unordered_map<string, int> > computeHashes(initializer_list<const char *> names)
{
	pair <vector<string>, unordered_map<string, int> > result;

	result.first.reserve(names.size());
	for (const char *name : names) {
		result.first.emplace_back(name);
	}

	result.second.reserve(names.size());
	for(typeof(names.size()) i = 0; i < names.size(); i++) {
		result.second.emplace(result.first[i], i);
	}

	return result;
}