当前位置: 首页>>代码示例>>C++>>正文


C++ Bag类代码示例

本文整理汇总了C++中Bag的典型用法代码示例。如果您正苦于以下问题:C++ Bag类的具体用法?C++ Bag怎么用?C++ Bag使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Bag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: delta_ext

void SaccadeMotorProgram::delta_ext(double e, const Bag<IO_Type>& xb)
{
	_time += e;
	if (!_saccades.empty())
	{
		//Rcout << _time << " There are " << _saccades.size() << " saccades in the motor queue." << endl;
		list<Saccade*>::const_iterator si = _saccades.begin();
		for(; si != _saccades.end(); si++)
		{
			(*si)->nonlabile_t -= e;
		}
	}
	Bag<IO_Type>::const_iterator iter = xb.begin();
	for (; iter != xb.end(); iter++)
	{
		Saccade* s = new Saccade(*((*xb.begin()).value));
		s->labile_stop = _time;
		s->nonlabile_start = _time;
		s->nonlabile_t = ::Rf_rgamma(((_mean*_mean)/(_stdev*_stdev)),(_stdev*_stdev)/_mean);
		_saccades.push_back(s);
	}
	_saccades.sort(sortNonLabile);
	//printf("%f\t    SaccadeMotorProgram: Starting non-labile programming for saccade[id=%d]\n", _time, _saccade->id);
	//printf("%f\t    SaccadeMotorProgram: Next event at %f\n", _time, _time+_threshold);
}
开发者ID:RyanHope,项目名称:EMdevs,代码行数:25,代码来源:SaccadeMotorProgram.cpp

示例2: main

int main(int argc, char** argv)
{
	// Get the parameters for the experiment from the command line
	if (argc != 4) {
		cout << "freq left_throttle right_throttle" << endl;
		return 0;
	}
	// Get the frequency of the voltage signal from the first argument
	double freq = atof(argv[1]);
	// Create a command from the driver that contains the duty ratios and
	// directions.
	SimPacket sim_command;
	sim_command.left_power = atof(argv[2]);
	sim_command.right_power = atof(argv[3]);
	// Create computer, simulator, and event listener. 
	Computer* computer = new Computer(freq);
	Simulator<SimEvent>* sim = new Simulator<SimEvent>(computer);
	ComputerListener* l = new ComputerListener(computer);
	// Add an event listener to plot the voltage signals
	sim->addEventListener(l);
	// Inject the driver command into the simulation at time 0
	Bag<Event<SimEvent> > input;
	SimEvent cmd(sim_command);
	Event<SimEvent> event(computer,cmd);
	input.insert(event);
	sim->computeNextState(input,0.0);
	// Run the simulation 
	while (sim->nextEventTime() <= 0.004)
		sim->execNextEvent();
	// Clean up and exit
	delete sim; delete computer; delete l;
	return 0;
}
开发者ID:Network-Dynamics,项目名称:adevs,代码行数:33,代码来源:computerTest.cpp

示例3: delta_ext

void LoadControl::delta_ext(double e, const Bag<PortValue<BasicEvent*> >& xb)
{
	Bag<PortValue<BasicEvent*> >::const_iterator iter = xb.begin();
	for (; iter != xb.end(); iter++)
	{
		GenrSampleEvent* measurement = dynamic_cast<GenrSampleEvent*>((*iter).value);
		if (measurement->freqBreakerOpen()) fdata.erase(measurement->getBusID());
		else fdata[measurement->getBusID()] = measurement->getRotorSpeed();
	}
	// Compute adjustment fraction
	double modified_adjustment = 0.0;
	// Get average frequency
	map<unsigned,double>::iterator fiter = fdata.begin();
	for (; fiter != fdata.end(); fiter++)
	{
		modified_adjustment += (*fiter).second;
	}
	modified_adjustment /= fdata.size();
	// Normalize to a percentage and apply the gain
	modified_adjustment *= (K/FreqTol);
	// Signal?
	if (!(fabs(modified_adjustment) <= max_adjust))
	{
		if (modified_adjustment > 0.0) modified_adjustment = max_adjust;
		else modified_adjustment = -max_adjust;
	}
	signal = adjustment != modified_adjustment;
	adjustment = modified_adjustment;
	assert(fabs(adjustment) <= max_adjust);
}
开发者ID:Network-Dynamics,项目名称:adevs,代码行数:30,代码来源:LoadControl.cpp

示例4: newarray_atomic

static MonomialIdeal *FrobbyAlexanderDual(const MonomialIdeal *I,
                                          const mpz_t *topvec)
{
  int nv = I->topvar() + 1;
  int *exp = newarray_atomic(int, nv);
  Frobby::Ideal F(nv);
  for (Index<MonomialIdeal> i = I->first(); i.valid(); i++)
    {
      Bag *b = I->operator[](i);
      varpower::to_ntuple(nv, b->monom().raw(), exp);

      if (M2_gbTrace >= 4) fprintf(stderr, "adding ");
      for (int j = 0; j < nv; j++)
        {
          if (M2_gbTrace >= 4) fprintf(stderr, "%d ", exp[j]);
          F.addExponent(exp[j]);
        }
      if (M2_gbTrace >= 4) fprintf(stderr, "\n");
    }

  // Now create the consumer object, and call Frobby
  MyIdealConsumer M(I->get_ring(), nv);
  Frobby::alexanderDual(F, topvec, M);
  deletearray(exp);
  // Extract the answer as a MonomialIdeal
  return M.result();
}
开发者ID:DanGrayson,项目名称:M2,代码行数:27,代码来源:x-monideal.cpp

示例5: main

int main()
{
	CircuitExt* test_model = new CircuitExt();
	Hybrid<OMC_ADEVS_IO_TYPE>* hybrid_model =
		new Hybrid<OMC_ADEVS_IO_TYPE>(
		test_model,
		new rk_45<OMC_ADEVS_IO_TYPE>(test_model,1E-7,0.001),
		new linear_event_locator<OMC_ADEVS_IO_TYPE>(test_model,1E-7));
        // Create the simulator
        Simulator<OMC_ADEVS_IO_TYPE>* sim =
			new Simulator<OMC_ADEVS_IO_TYPE>(hybrid_model);
		// Check initial values
		test_model->print_state();
		// Run the simulation, testing the solution as we go
        while (sim->nextEventTime() <= 1.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
		Bag<Event<double> > xb;
		Event<double> event(hybrid_model,0.0);
		xb.insert(event);
		sim->computeNextState(xb,1.0);
		while (sim->nextEventTime() <= 5.0)
		{
			sim->execNextEvent();
			test_model->print_state();
			test_model->test_state();
		}
        delete sim;
		delete hybrid_model;
        return 0;
}
开发者ID:Network-Dynamics,项目名称:adevs,代码行数:34,代码来源:main_test3.cpp

示例6: printf

Digraph& Digraph::operator=(const Digraph& G) {
	printf("Assigning Digraph\n");
	if (this == &G) return *this;

	// Free memory
	delete[] adj_;

	// Allocate memory
	V_ = G.V_;
	E_ = G.E_;
	Bag<int>* new_adj = new Bag<int>[G.V_];

	// Copy elements
	for (int v = 0; v < G.V_; v++) {
		// reverse so that adjacency list is in the same order as original
		Bag<int> reverse;
		for (int w : G.adj_[v])
			reverse.add(w);
		for (int w : reverse)
			new_adj[v].add(w);
	}

	// Reassign variables
	adj_ = new_adj;

	return *this;
}
开发者ID:yehted,项目名称:Digraph,代码行数:27,代码来源:Digraph.cpp

示例7: test1

/**
 * This is to test the use of template iterators inside of
 * a template class. The main purpose of the test is to
 * make sure the template instantiation works as intended.
 */
void test1()
{
	Bag<int> b;
	b.insert(0);
	template_test<int> t;
	int* array = t.to_array(b);
	assert(array[0]==0);
}
开发者ID:Network-Dynamics,项目名称:adevs,代码行数:13,代码来源:bagtst.cpp

示例8: while

void engine<VertexType, EdgeType>::run(){
  int iterationCount = 0;
  Bag<Scheduler::update_task>* b = scheduler->get_task_bag();
  while (b->numElements() > 0 /*&& iterationCount < 40*/) {
    iterationCount++;
    parallel_process(b); 
    b = scheduler->get_task_bag(); 
  }
}
开发者ID:michaelkook,项目名称:cilk-graphlab,代码行数:9,代码来源:engine.cpp

示例9:

	Component * EntityManager::getComponent(Entity & e, ComponentType & type) {
		Bag<Component*>* bag = componentsByType.get(type.getId());
    
		if (bag != NULL && e.getId() < bag->getCapacity()) {
			return bag->get(e.getId());
		}
    
		return NULL;
	}
开发者ID:Axodoss,项目名称:Carbon,代码行数:9,代码来源:EntityManager.cpp

示例10: min

typename Bag::value_type min(const Bag & b)
{
    typename Bag::const_iterator it;
    typename Bag::value_type m = *b.begin();
    for (it = b.begin(); it != b.end(); ++it)
        if (*it < m)
            m = *it;
    return m;
}
开发者ID:Admiri92,项目名称:CPP_Primer_Plus,代码行数:9,代码来源:appg02.cpp

示例11: gc_output

void Generator::gc_output(Bag<IO_Type>& g)
{
	// Delete the customer that was produced as output
	Bag<IO_Type>::iterator i;
	for (i = g.begin(); i != g.end(); i++)
	{
		delete (*i).value;
	}
}
开发者ID:Network-Dynamics,项目名称:adevs,代码行数:9,代码来源:Generator.cpp

示例12: while

void DirectedDFS::dfs(DirGraph& G, int v){
	marked[v] = true;
	Bag *TempBag = G.Iterator(v);
	TempBag->BeginIter();
	int iter;
	while(TempBag->HasNext())
		if(!marked[(iter = TempBag->Next())])
			dfs(G,iter);
}
开发者ID:hzc9107,项目名称:GraphLib,代码行数:9,代码来源:DirGraphProc.cpp

示例13: ShowTransmogItems

    void ShowTransmogItems(Player* player, Creature* creature, uint8 slot) // Only checks bags while can use an item from anywhere in inventory
    {
        WorldSession* session = player->GetSession();
        Item* oldItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, slot);
        if (oldItem)
        {
            uint32 limit = 0;
            uint32 price = sT->GetSpecialPrice(oldItem->GetTemplate());
            price *= sT->GetScaledCostModifier();
            price += sT->GetCopperCost();
            std::ostringstream ss;
            ss << std::endl;
            if (sT->GetRequireToken())
                ss << std::endl << std::endl << sT->GetTokenAmount() << " x " << sT->GetItemLink(sT->GetTokenEntry(), session);

            for (uint8 i = INVENTORY_SLOT_ITEM_START; i < INVENTORY_SLOT_ITEM_END; ++i)
            {
                if (limit > MAX_OPTIONS)
                    break;
                Item* newItem = player->GetItemByPos(INVENTORY_SLOT_BAG_0, i);
                if (!newItem)
                    continue;
                if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
                    continue;
                if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
                    continue;
                ++limit;
                player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
            }

            for (uint8 i = INVENTORY_SLOT_BAG_START; i < INVENTORY_SLOT_BAG_END; ++i)
            {
                Bag* bag = player->GetBagByPos(i);
                if (!bag)
                    continue;
                for (uint32 j = 0; j < bag->GetBagSize(); ++j)
                {
                    if (limit > MAX_OPTIONS)
                        break;
                    Item* newItem = player->GetItemByPos(i, j);
                    if (!newItem)
                        continue;
                    if (!sT->CanTransmogrifyItemWithItem(player, oldItem->GetTemplate(), newItem->GetTemplate()))
                        continue;
                    if (sT->GetFakeEntry(oldItem->GetGUID()) == newItem->GetEntry())
                        continue;
                    ++limit;
                    player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, sT->GetItemIcon(newItem->GetEntry(), 30, 30, -18, 0)+sT->GetItemLink(newItem, session), slot, newItem->GetGUIDLow(), "Using this item for transmogrify will bind it to you and make it non-refundable and non-tradeable.\nDo you wish to continue?\n\n"+sT->GetItemIcon(newItem->GetEntry(), 40, 40, -15, -10)+sT->GetItemLink(newItem, session)+ss.str(), price, false);
                }
            }
        }

        player->ADD_GOSSIP_ITEM_EXTENDED(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/INV_Enchant_Disenchant:30:30:-18:0|tRemove transmogrification", EQUIPMENT_SLOT_END+3, slot, "Remove transmogrification from the slot?", 0, false);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/PaperDollInfoFrame/UI-GearManager-Undo:30:30:-18:0|tUpdate menu", EQUIPMENT_SLOT_END, slot);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_MONEY_BAG, "|TInterface/ICONS/Ability_Spy:30:30:-18:0|tBack..", EQUIPMENT_SLOT_END+1, 0);
        player->SEND_GOSSIP_MENU(DEFAULT_GOSSIP_MESSAGE, creature->GetGUID());
    }
开发者ID:HevdavDEV,项目名称:MiscTC,代码行数:57,代码来源:Transmogrifier.cpp

示例14: delta_ext

void Payer::delta_ext(double e, const Bag<IO>& xb)
{
	// Record the times at which the bene left the provider.
	Bag<IO>::const_iterator i;
	for (i = xb.begin(); i != xb.end(); i++)
	{
		//const Signal* c = (*i).value;
		total_number_of_patients += 1;
	}
}
开发者ID:cengover,项目名称:ACO,代码行数:10,代码来源:Payer.cpp

示例15: tilesNotOnBoard

Bag Board::tilesNotOnBoard() const
{
	Bag ret;

	for (int row = 0; row < m_height; row++)
		for (int col = 0; col < m_width; col++)
			if (m_letters[row][col] != QUACKLE_NULL_MARK)
				ret.removeLetter(m_isBlank[row][col]? QUACKLE_BLANK_MARK : m_letters[row][col]);

	return ret;
}
开发者ID:quackle,项目名称:quackle,代码行数:11,代码来源:board.cpp


注:本文中的Bag类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。