Exemplo n.º 1
0
int main() 
{
	int array[ 17 ] = { 7,3,3,7,6,5,8,7,2,1,3,8,7,3,8,4,3 };
	
	int elem = array[ 9 ];
	int *found_it;
		
	found_it = find( &array[0], &array[17], elem );


	// generates: find the first occurrence of 1 found!

	cout << "find the first occurrence of "
	     << elem << "\t"
	     << ( found_it ? "found!\n" : "not found!\n" );

        string beethoven[] = { 
 	"Sonata31", "Sonata32", "Quartet14", "Quartet15", 
	"Archduke", "Symphony7" };

	string s_elem( beethoven[ 1 ] );

        list< string, allocator > slist( beethoven, beethoven+6 );
	list< string, allocator >::iterator iter;

	iter = find( slist.begin(), slist.end(), s_elem );

	// generates: find the first occurrence of Sonata32  found!

	cout << "find the first occurrence of "
	     << s_elem << "\t"
	     << ( found_it ? "found!\n" : "not found!\n" );

	return 0;
}
Exemplo n.º 2
0
KateSessionOpenDialog::KateSessionOpenDialog(QWidget *parent)
    : KDialogBase(parent, "", true, i18n("Open Session"), KDialogBase::User1 | KDialogBase::User2, KDialogBase::User2, false, KStdGuiItem::cancel(),
                  KGuiItem(i18n("&Open"), "fileopen"))
{
    QHBox *page = new QHBox(this);
    page->setMinimumSize(400, 200);
    setMainWidget(page);

    QHBox *hb = new QHBox(page);

    QVBox *vb = new QVBox(hb);

    m_sessions = new KListView(vb);
    m_sessions->addColumn(i18n("Session Name"));
    m_sessions->addColumn(i18n("Open Documents"));
    m_sessions->setResizeMode(QListView::AllColumns);
    m_sessions->setSelectionMode(QListView::Single);
    m_sessions->setAllColumnsShowFocus(true);

    connect(m_sessions, SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)), this, SLOT(slotUser2()));

    KateSessionList &slist(KateSessionManager::self()->sessionList());
    for(unsigned int i = 0; i < slist.count(); ++i)
    {
        new KateSessionChooserItem(m_sessions, slist[i]);
    }

    setResult(resultCancel);
}
int main()
{
    
	std::list<unsigned int> l1(100);
	std::generate(std::begin(l1),std::end(l1),RandomNumber);
	std::vector<unsigned int> v(l1.size());
	std::copy(std::begin(l1), std::end(l1),std::begin(v));
	std::copy(std::begin(v), std::end(v), std::ostream_iterator<unsigned int>(std::cout," | "));
	std::cout<<std::endl;
	std::cout<<std::endl;
	std::cout<<"Die Liste beschteht aus "<<l1.size()<<" elementen."<<std::endl;
	std::cout<<std::endl;
	std::set<unsigned int> slist(std::begin(l1),std::end(l1));
	std::cout << "Diese Zahlen haben es leider nicht in die Liste geschaft (Doffes standart RAND) : "<<std::endl;
	for (unsigned int i = 0; i<=100; ++i ){
		if (slist.count(i) != true){
			std::cout<< i << " | ";
		}
	}
	std::cout<<std::endl;
	std::map<unsigned int, unsigned int> mliste;
    for (std::list<unsigned int>::iterator i = l1.begin(); i != l1.end(); ++i) {
    ++mliste[*i];
  	}
    std::cout<<std::endl;
  	std::cout << "Uuuund sooooo haeufig sind alle vorgekommen :" << std::endl;
  	for (int i = 0; i <= 100; ++i) {
    	std::cout << i << " : " << mliste[i] << " | ";
	}
	return 0;
}
Exemplo n.º 4
0
void KateSessionsAction::openSession(int i)
{
    KateSessionList &slist(KateSessionManager::self()->sessionList());

    if((uint)i >= slist.count())
        return;

    KateSessionManager::self()->activateSession(slist[(uint)i]);
}
Exemplo n.º 5
0
void
IpVerify::fill_table(PermTypeEntry * pentry, char * list, bool allow)
{
    assert(pentry);

	NetStringList * whichHostList = new NetStringList();
    UserHash_t * whichUserHash = new UserHash_t(1024, compute_host_hash);

    StringList slist(list);
	char *entry, * host, * user;
	slist.rewind();
	while ( (entry=slist.next()) ) {
		if (!*entry) {
			// empty string?
			slist.deleteCurrent();
			continue;
		}
		split_entry(entry, &host, &user);
		ASSERT( host );
		ASSERT( user );

			// If this is a hostname, get all IP addresses for it and
			// add them to the list.  This ensures that if we are given
			// a cname, we do the right thing later when trying to match
			// this record with the official hostname.
		StringList host_addrs;
		ExpandHostAddresses(host,&host_addrs);
		host_addrs.rewind();

		char const *host_addr;
		while( (host_addr=host_addrs.next()) ) {
			MyString hostString(host_addr);
			StringList * userList = 0;
				// add user to user hash, host to host list
			if (whichUserHash->lookup(hostString, userList) == -1) {
				whichUserHash->insert(hostString, new StringList(user)); 
				whichHostList->append(hostString.Value());
			}
			else {
				userList->append(user);
			}
		}

		free(host);
		free(user);
	}

    if (allow) {
        pentry->allow_hosts = whichHostList;
        pentry->allow_users  = whichUserHash;
    }
    else {
        pentry->deny_hosts = whichHostList;
        pentry->deny_users = whichUserHash;
    }
}
Exemplo n.º 6
0
void KateSessionsAction::slotAboutToShow()
{
    popupMenu()->clear();

    KateSessionList &slist(KateSessionManager::self()->sessionList());
    for(unsigned int i = 0; i < slist.count(); ++i)
    {
        popupMenu()->insertItem(slist[i]->sessionName(), this, SLOT(openSession(int)), 0, i);
    }
}
Exemplo n.º 7
0
void KateSessionManageDialog::updateSessionList()
{
    m_sessions->clear();

    KateSessionList &slist(KateSessionManager::self()->sessionList());
    for(unsigned int i = 0; i < slist.count(); ++i)
    {
        new KateSessionChooserItem(m_sessions, slist[i]);
    }
}
Exemplo n.º 8
0
void 
InfoTypeConverter< std::list< std::string > >::get(cURLpp::Easy & handle,
						   CURLINFO info,
						   std::list< std::string > &value)
{ 
  curl_slist * tmpList = NULL;
  InfoGetter::get(handle, info, tmpList);
  SList slist(tmpList);
  value = slist.list();
}
Exemplo n.º 9
0
int main() {
	std::array<int, 42> arr = {0};
	std::array<std::string, 10> sarr;

	std::list<std::string> slist(1);
	slist.assign(10, "Hi!");
	for (const auto cstr : slist) {
		std::cout << cstr << std::endl;
	}

	return 0;
}
Exemplo n.º 10
0
ade::TensptrT reduce (ade::Opcode opcode, ade::TensptrT tens,
	uint8_t start, uint8_t end)
{
	if (end < start)
	{
		logs::fatalf("end index %d must be after start %d", end, start);
	}
	ade::Shape shape = tens->shape();
	auto it = shape.begin();
	std::vector<ade::DimT> slist(it + start, it + end);
	auto out = ade::Functor::get(opcode, {
		ade::reduce_map(tens, start, slist),
	});
	return ade::TensptrT(out);
}
Exemplo n.º 11
0
KateSessionChooser::KateSessionChooser(QWidget *parent, const QString &lastSession)
    : KDialogBase(parent, "", true, i18n("Session Chooser"), KDialogBase::User1 | KDialogBase::User2 | KDialogBase::User3, KDialogBase::User2, true,
                  KStdGuiItem::quit(), KGuiItem(i18n("Open Session"), "fileopen"), KGuiItem(i18n("New Session"), "filenew"))
{
    QHBox *page = new QHBox(this);
    page->setMinimumSize(400, 200);
    setMainWidget(page);

    QHBox *hb = new QHBox(page);
    hb->setSpacing(KDialog::spacingHint());

    QLabel *label = new QLabel(hb);
    label->setPixmap(UserIcon("sessionchooser"));
    label->setFrameStyle(QFrame::Panel | QFrame::Sunken);

    QVBox *vb = new QVBox(hb);
    vb->setSpacing(KDialog::spacingHint());

    m_sessions = new KListView(vb);
    m_sessions->addColumn(i18n("Session Name"));
    m_sessions->addColumn(i18n("Open Documents"));
    m_sessions->setResizeMode(QListView::AllColumns);
    m_sessions->setSelectionMode(QListView::Single);
    m_sessions->setAllColumnsShowFocus(true);

    connect(m_sessions, SIGNAL(selectionChanged()), this, SLOT(selectionChanged()));
    connect(m_sessions, SIGNAL(doubleClicked(QListViewItem *, const QPoint &, int)), this, SLOT(slotUser2()));

    KateSessionList &slist(KateSessionManager::self()->sessionList());
    for(unsigned int i = 0; i < slist.count(); ++i)
    {
        KateSessionChooserItem *item = new KateSessionChooserItem(m_sessions, slist[i]);

        if(slist[i]->sessionFileRelative() == lastSession)
            m_sessions->setSelected(item, true);
    }

    m_useLast = new QCheckBox(i18n("&Always use this choice"), vb);

    setResult(resultNone);

    // trigger action update
    selectionChanged();
}
Exemplo n.º 12
0
// Helper function to display results of a vertex inquiry
// Accepts a dgraph reference, prompts for user input for a vertex name
// Attempts to display the adjacency list of that vertex
// Or catches VertexNotFound if not.
void reportAdjacencyList(dgraph& myGraph)
{
	slist adj_list = slist();
	
	cout << "Enter the vertex you would like to search for:" << endl;

	string input_expr;
	cin >> input_expr;
	
	char vertex_name = toupper(input_expr[0]);

	cout << "Searching for vertex " << vertex_name << endl;
	try
	{
		adj_list = myGraph.findAdjacencyList(vertex_name);
		cout << "The adjacency list for that vertex is:" << endl;
		adj_list.displayAll();
	}
	catch (dgraph::VertexNotFound)
	{
		cout << "Sorry, couldn't find that vertex in the graph." << endl;
	}
}
Exemplo n.º 13
0
template <class T> PCrsMatrix<U>::PCrsMatrix(const CrsMatrix<T>& s, const  MPI_Comm ncomm)
{
    mpi_init(ncomm);
    
    int iamsender=(s.rows()>0?1:0);    //! we rely on the fact that only one node has this cond. fulfilled.

    // now we let everyone know who is the sender
    std::valarray<int> slist(mysize);
    MPI_Allgather(&iamsender, 1, MPI_INTEGER, &slist[0], 1, MPI_INTEGER, mycomm);
    int sender=-1;
    
    for (int i=0; i< mysize; ++i) 
        if (slist[i]==1) if(sender==-1) sender=i; else ERROR("More than one process qualified as sender!");
    if (sender==-1) ERROR("No process qualified as sender!");
    
    // now we get the matrix size and resize it.
    typename PCrsMatrix<U>::index_type dim[2];
    if (iamsender) { dim[0]=s.rows(); dim[1]=s.cols(); }
    MPI_Bcast(dim,2,mpi_index,sender,mycomm);
    resize(dim[0],dim[1]);
    
    // now we copy the options, as if it were an array of char...
    MPI_Bcast(&(const_cast<CrsMatrix<T> &>(s).pops),sizeof(pops),MPI_CHAR,sender,mycomm);
    setops(s.pops);
    
    // now we can send out the row indices to the nodes.
    unsigned long nmyrows=nroots[myrank+1]-nroots[myrank];
    MPI_Request rreq;
    MPI_Irecv(&pmat.rpoints[0],nmyrows+1,mpi_index,sender,101,mycomm,&rreq);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).rpoints[nroots[i]]),nroots[i+1]-nroots[i]+1,mpi_index,i,101,mycomm);
    };
    
    //wait for receive
    MPI_Status rstatus;
    MPI_Wait(&rreq, &rstatus);
    //then shift the indices as necessary, since we are getting chunks of data
    for (typename PCrsMatrix<U>::index_type i=1;i<=nmyrows; ++i)
        pmat.rpoints[i]-=pmat.rpoints[0];
    pmat.rpoints[0]=0;
    pmat.presize(pmat.rpoints[nmyrows]);
    
    //very well. now we can share the column indices and the data!
    MPI_Request rreq_i, rreq_d;
    MPI_Irecv(&pmat.indices[0],pmat.rpoints[nmyrows],mpi_index,sender,202,mycomm,&rreq_i);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).indices[s.rpoints[nroots[i]]]),
                     s.rpoints[nroots[i+1]]-s.rpoints[nroots[i]],mpi_index,i,202,mycomm);
    };
    
    MPI_Irecv(&pmat.values[0],pmat.rpoints[nmyrows],mpi_data,sender,303,mycomm,&rreq_d);
    
    if (iamsender) {
        for (int i=0; i<mysize; ++i)
            MPI_Send(&(const_cast<CrsMatrix<T> &>(s).values[s.rpoints[nroots[i]]]),
                     s.rpoints[nroots[i+1]]-s.rpoints[nroots[i]],mpi_data,i,303,mycomm);
    };
    MPI_Wait(&rreq_i, &rstatus);
    MPI_Wait(&rreq_d, &rstatus);
}
Exemplo n.º 14
0
void
pcode(Node *n, int d)
{
	Node *r, *l;

	if(n == 0)
		return;

	r = n->right;
	l = n->left;

	switch(n->op) {
	default:
		Bprint(bout, "%.*s", d, tabs);
		pexpr(n);
		Bprint(bout, ";\n");
		break;
	case OLIST:
		pcode(n->left, d);
		pcode(n->right, d);
		break;
	case OLOCAL:
		Bprint(bout, "%.*slocal", d, tabs);
		while(l) {
			Bprint(bout, " %s", l->sym->name);
			l = l->left;
			if(l == 0)
				Bprint(bout, ";\n");
			else
				Bprint(bout, ",");
		}
		break;
	case OCOMPLEX:
		Bprint(bout, "%.*scomplex %s %s;\n", d, tabs, n->sym->name, l->sym->name);
		break;
	case OIF:
		Bprint(bout, "%.*sif ", d, tabs);
		pexpr(l);
		d++;
		Bprint(bout, " then\n");
		if(r && r->op == OELSE) {
			slist(r->left, d);
			Bprint(bout, "%.*selse\n", d-1, tabs);
			slist(r->right, d);
		}
		else
			slist(r, d);
		break;
	case OWHILE:
		Bprint(bout, "%.*swhile ", d, tabs);
		pexpr(l);
		d++;
		Bprint(bout, " do\n");
		slist(r, d);
		break;
	case ORET:
		Bprint(bout, "%.*sreturn ", d, tabs);
		pexpr(l);
		Bprint(bout, ";\n");
		break;
	case ODO:
		Bprint(bout, "%.*sloop ", d, tabs);
		pexpr(l->left);
		Bprint(bout, ", ");
		pexpr(l->right);
		Bprint(bout, " do\n");
		slist(r, d+1);
	}
}
Exemplo n.º 15
0
bool test_osc_StateList()
{
  size_t i;
  osc::StateList slist(4096);

  // KEEP IN MIND that each state take its own size PLUS 64 BYTES.

  TEST_ASSERT_EQUAL(slist.numberOfStates(),0);
  TEST_ASSERT_EQUAL(slist.getQuota(),4096);

  osc::byte_t bytes1[] = {0,1,2,3,4};
  osc::Buffer buff1(bytes1,sizeof(bytes1));
  osc::State s1(buff1);

  // Test single add
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  slist.addState(&s1, 1, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);

  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test reset
  slist.reset();
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);

  // Test double add (same priority)
  slist.addState(&s1, 1, false);
  slist.addState(&s1, 1, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test multiple add (lower priority)
  slist.addState(&s1, 2, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test multiple add (higher priority)
  slist.addState(&s1, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Test adding second state
  osc::byte_t bytes2[] = {0,2,2,3,4};
  osc::Buffer buff2(bytes2,sizeof(bytes2));
  osc::State s2(buff2);
  slist.addState(&s2, 1, false);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),
                    4096 - sizeof(bytes1) - sizeof(bytes2) - 128);

  // Test adding big state that removes other two
  osc::byte_t bigBytes1[4096 - 64];
  for (i = 0; i < sizeof(bigBytes1); i++)
  {
    bigBytes1[i] = (i & 0xff);
  }
  osc::Buffer bigBuff1(bigBytes1, sizeof(bigBytes1));
  osc::State bigState1(bigBuff1);
  slist.addState(&bigState1, 0, false);
  TEST_ASSERT_EQUAL(bigState1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);

  // Test adding state that bumps exactly one state out (based on time).
  slist.reset();
  osc::Buffer bigBuff2(bigBytes1, sizeof(bigBytes1) - 64 - sizeof(bytes1));
  osc::State bigState2(bigBuff2);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 0, false);
  slist.addState(&s1, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Lowest priority = freed first

  // Test adding state that bumps exactly one state out (based on priority).
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 1, false);
  slist.addState(&s1, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Same test, but with state reprioritization
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 0, false);
  slist.addState(&s1, 1, false);
  slist.addState(&s2, 2, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Make sure insertion at a lower priority doesn't downgrade
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 2, false);
  slist.addState(&s1, 1, false);
  slist.addState(&s2, 0, false);
  slist.addState(&bigState2, 0, false);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),1);

  // Now, bump out the big state by lowering the quota
  slist.setQuota(2048);
  TEST_ASSERT_EQUAL(s1.getRefCount(),0);
  TEST_ASSERT_EQUAL(s2.getRefCount(),1);
  TEST_ASSERT_EQUAL(bigState2.getRefCount(),0);
  slist.setQuota(4096);

  // Try removing a state manually
  slist.reset();
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096);
  slist.addState(&s2, 2, false);
  slist.addState(&s1, 1, false);
  slist.removeState(s2.getStateId());
  TEST_ASSERT_EQUAL(s1.getRefCount(),1);
  TEST_ASSERT_EQUAL(s2.getRefCount(),0);
  TEST_ASSERT_EQUAL(slist.getQuotaLeft(),4096 - sizeof(bytes1) - 64);

  // Insert a pre-acked state, check acked state retreival
  slist.addState(&s2, 1, true);
  slist.addState(&s1, 1, false);
  TEST_ASSERT(!(slist.isStateAcked(s1.getStateId())));
  TEST_ASSERT(slist.isStateAcked(s2.getStateId()));
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2);
  slist.ackState(s1.getStateId());
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s1);
  slist.addState(&s2, 1, false);
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(1),&s2);

  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(0),0);
  TEST_ASSERT_EQUAL(slist.getMostRecentAckedState(2),0);

  return true;
}
Exemplo n.º 16
0
void scenario_settings_table(display& gui, int selected)
{
	std::stringstream heading;
	heading << HEADING_PREFIX << _("scenario settings^Leader") << COLUMN_SEPARATOR
			<< COLUMN_SEPARATOR
			<< _("scenario settings^Side")              << COLUMN_SEPARATOR
			<< _("scenario settings^Start\nGold")       << COLUMN_SEPARATOR
			<< _("scenario settings^Base\nIncome")      << COLUMN_SEPARATOR
			<< _("scenario settings^Gold Per\nVillage") << COLUMN_SEPARATOR
			<< _("scenario settings^Support Per\nVillage") << COLUMN_SEPARATOR
			<< _("scenario settings^Fog")               << COLUMN_SEPARATOR
			<< _("scenario settings^Shroud");

	gui::menu::basic_sorter sorter;
	sorter.set_redirect_sort(0,1).set_alpha_sort(1).set_numeric_sort(2)
		  .set_numeric_sort(3).set_numeric_sort(4).set_numeric_sort(5)
		  .set_numeric_sort(6).set_alpha_sort(7).set_alpha_sort(8);

	std::vector<std::string> items;
	std::vector<bool> leader_bools;
	items.push_back(heading.str());

	//const gamemap& map = gui.get_map();
	const unit_map& units = gui.get_units();
	const std::vector<team>& teams = gui.get_teams();

	const team& viewing_team = teams[gui.viewing_team()];
	bool settings_table_empty = true;
	bool fogged;

	for(size_t n = 0; n != teams.size(); ++n) {
		if(teams[n].hidden()) {
			continue;
		}
		settings_table_empty = false;

		std::stringstream str;
		unit_map::const_iterator leader = units.find_leader(n + 1);

		if(leader != units.end()) {
			// Add leader image. If it's fogged
			// show only a random leader image.
			fogged=viewing_team.fogged(leader->get_location());
			if (!fogged || viewing_team.knows_about_team(n, network::nconnections() > 0) || game_config::debug) {
				str << IMAGE_PREFIX << leader->absolute_image();
				leader_bools.push_back(true);
			} else {
				str << IMAGE_PREFIX << std::string("units/unknown-unit.png");
				leader_bools.push_back(false);
			}
#ifndef LOW_MEM
			str << "~RC(" << leader->team_color() << '>'
			    << team::get_side_color_index(n+1) << ")";
#endif
		} else {
			leader_bools.push_back(false);
		}

		str << COLUMN_SEPARATOR	<< team::get_side_highlight(n)
			<< teams[n].current_player() << COLUMN_SEPARATOR
			<< n + 1 << COLUMN_SEPARATOR
			<< teams[n].start_gold() << COLUMN_SEPARATOR
			<< teams[n].base_income() << COLUMN_SEPARATOR
			<< teams[n].village_gold() << COLUMN_SEPARATOR
			<< teams[n].village_support() << COLUMN_SEPARATOR
			<< (teams[n].uses_fog()    ? _("yes") : _("no")) << COLUMN_SEPARATOR
			<< (teams[n].uses_shroud() ? _("yes") : _("no")) << COLUMN_SEPARATOR;

		items.push_back(str.str());
	}

	if (settings_table_empty)
	{
		// no sides to show - display empty table
		std::stringstream str;
		for (int i=0;i<8;++i)
			str << " " << COLUMN_SEPARATOR;
		leader_bools.push_back(false);
		items.push_back(str.str());
	}
	int result = 0;
	{
		leader_scroll_dialog slist(gui, _("Scenario Settings"), leader_bools, selected, gui::DIALOG_BACK);
		slist.set_menu(items, &sorter);
		slist.get_menu().move_selection(selected);
		slist.add_button(new gui::dialog_button(gui.video(), _(" < Back"),
				gui::button::TYPE_PRESS, gui::DIALOG_BACK),
				gui::dialog::BUTTON_EXTRA_LEFT);
		result = slist.show();
		selected = slist.get_menu().selection();
	} // this will kill the dialog before scrolling

	if (result >= 0) {
		//TODO
		//gui_->scroll_to_leader(units_, selected+1);
	}
	else if (result == gui::DIALOG_BACK)
		status_table(gui, selected);
}
Exemplo n.º 17
0
void status_table(display& gui, int selected)
{
	std::stringstream heading;
	heading << HEADING_PREFIX << _("Leader") << COLUMN_SEPARATOR << ' ' << COLUMN_SEPARATOR
			<< _("Team")         << COLUMN_SEPARATOR
			<< _("Gold")         << COLUMN_SEPARATOR
			<< _("Villages")     << COLUMN_SEPARATOR
			<< _("status^Units") << COLUMN_SEPARATOR
			<< _("Upkeep")       << COLUMN_SEPARATOR
			<< _("Income");

	gui::menu::basic_sorter sorter;
	sorter.set_redirect_sort(0,1).set_alpha_sort(1).set_alpha_sort(2).set_numeric_sort(3)
		  .set_numeric_sort(4).set_numeric_sort(5).set_numeric_sort(6).set_numeric_sort(7);

	std::vector<std::string> items;
	std::vector<bool> leader_bools;
	items.push_back(heading.str());

	const gamemap& map = gui.get_map();
	const unit_map& units = gui.get_units();
	assert(&gui.get_teams() == resources::teams);
	const std::vector<team>& teams = gui.get_teams();

	const team& viewing_team = teams[gui.viewing_team()];

	unsigned total_villages = 0;
	// a variable to check if there are any teams to show in the table
	bool status_table_empty = true;

	//if the player is under shroud or fog, they don't get
	//to see details about the other sides, only their own
	//side, allied sides and a ??? is shown to demonstrate
	//lack of information about the other sides But he see
	//all names with in colors
	for(size_t n = 0; n != teams.size(); ++n) {
		if(teams[n].hidden()) {
			continue;
		}
		status_table_empty=false;

		const bool known = viewing_team.knows_about_team(n, network::nconnections() > 0);
		const bool enemy = viewing_team.is_enemy(n+1);

		std::stringstream str;

		const team_data data = gui.get_disp_context().calculate_team_data(teams[n],n+1);

		unit_map::const_iterator leader = units.find_leader(n + 1);
		std::string leader_name;
		//output the number of the side first, and this will
		//cause it to be displayed in the correct color
		if(leader != units.end()) {
			const bool fogged = viewing_team.fogged(leader->get_location());
			// Add leader image. If it's fogged
			// show only a random leader image.
			if (!fogged || known || game_config::debug) {
				str << IMAGE_PREFIX << leader->absolute_image();
				leader_bools.push_back(true);
				leader_name = leader->name();
			} else {
				str << IMAGE_PREFIX << std::string("units/unknown-unit.png");
				leader_bools.push_back(false);
				leader_name = "Unknown";
			}
	//	if (gamestate_.classification().campaign_type == game_classification::MULTIPLAYER)
	//			leader_name = teams[n].current_player();

#ifndef LOW_MEM
			str << leader->image_mods();
#endif
		} else {
			leader_bools.push_back(false);
		}
		str << COLUMN_SEPARATOR	<< team::get_side_highlight(n)
			<< leader_name << COLUMN_SEPARATOR
			<< (data.teamname.empty() ? teams[n].team_name() : data.teamname)
			<< COLUMN_SEPARATOR;

		if(!known && !game_config::debug) {
			// We don't spare more info (only name)
			// so let's go on next side ...
			items.push_back(str.str());
			continue;
		}

		if(game_config::debug) {
			str << utils::half_signed_value(data.gold) << COLUMN_SEPARATOR;
		} else if(enemy && viewing_team.uses_fog()) {
			str << ' ' << COLUMN_SEPARATOR;
		} else {
			str << utils::half_signed_value(data.gold) << COLUMN_SEPARATOR;
		}
		str << data.villages;
                if(!(viewing_team.uses_fog() || viewing_team.uses_shroud())) {
                        str << "/" << map.villages().size();
                }
		str << COLUMN_SEPARATOR
			<< data.units << COLUMN_SEPARATOR << data.upkeep << COLUMN_SEPARATOR
			<< (data.net_income < 0 ? font::BAD_TEXT : font::NULL_MARKUP) << utils::signed_value(data.net_income);
		total_villages += data.villages;
		items.push_back(str.str());
	}
	if (total_villages > map.villages().size()) {
		//TODO
//		ERR_NG << "Logic error: map has " << map.villages().size()
//				<< " villages but status table shows " << total_villages << " owned in total\n";
	}

	if (status_table_empty)
	{
		// no sides to show - display empty table
		std::stringstream str;
		str << " ";
		for (int i=0;i<7;++i)
			str << COLUMN_SEPARATOR << " ";
		leader_bools.push_back(false);
		items.push_back(str.str());
	}
	int result = 0;
	{
		leader_scroll_dialog slist(gui, _("Current Status"), leader_bools, selected, gui::DIALOG_FORWARD);
		slist.add_button(new gui::dialog_button(gui.video(), _("More >"),
												 gui::button::TYPE_PRESS, gui::DIALOG_FORWARD),
												 gui::dialog::BUTTON_EXTRA_LEFT);
		slist.set_menu(items, &sorter);
		slist.get_menu().move_selection(selected);
		result = slist.show();
		selected = slist.get_menu().selection();
	} // this will kill the dialog before scrolling

	if (result >= 0) {
		//TODO
	//	gui.scroll_to_leader(units_, selected+1);
	}
	else if (result == gui::DIALOG_FORWARD)
		scenario_settings_table(gui, selected);
}
Exemplo n.º 18
0
void mergeProdLocal(const Char_t *list, Bool_t doMC=kFALSE, const Int_t nwrite=10000)
{
  gSystem->Load("libANALYSIS.so");
  gSystem->Load("libANALYSISalice.so");
  gSystem->Load("libTender.so");
  //gSystem->Load("libCORRFW.so");
  gSystem->Load("libPWGLFspectra.so");

  FILE *fp(NULL);
  if(!(fp = fopen(list, "rt"))){
    Error("mergeProd.C", "Missing input list \"%s\".", list);
    return;
  }
  printf("Usage : mergeProdLocal(list, doMC, n)\n"
    "  list : the list of AnalysisResults file to be merged. Files can be root or zip archived.\n"
    "       : using \"%s\".\n"
    "  doMC : true if production is MC. Default false.\n"
    "       : using \"%s\".\n"
    "  n    : Optional parameter to specify the number of files to be added until a flush of the\n"
    "         merged file is performed. Use only for large productions.\n"
    "       : using %d.\n", list, (doMC?"true":"false"), nwrite
  );
  
  // build out filename
  TString s, s1, slist=list;
  Char_t fn[200];
  for(Int_t i(slist.Length()); --i;) {
    if(slist(i)!='.') continue;
    s1 = slist(0, i);
    snprintf(fn, 200, "Merged_%s.root", s1.Data());
    break;
  }
  printf("Opening merged file \"%s\"...\n", fn);
  fOut = TFile::Open(fn, "RECREATE");
  fOut->mkdir(nameTask)->Write();

  // read task descriptors a
  for(Int_t it(0); it<ntasks; it++){
    s=taskConfig[it]; 
    s1=s(0, s.Index('_')); sprintf(taskName[it], "%s", s1.Data());
    s = s(s.Index('_')+1, 200); plots[it] = s.Tokenize(":");
  }
  mc = doMC;
  Int_t ifile(0);
  if(!kVerbose) printf("Merging ");
  while(slist.Gets(fp)){
    if(slist.EndsWith("zip")) snprintf(fn, 200, "%s#AnalysisResults.root", slist.Data());
    else if(slist.EndsWith("root")) snprintf(fn, 200, "%s", slist.Data());
    else{
      Warning("mergeProd", "Don't know what to do with file \"%s\". Skip file.", slist.Data());
      continue;
    }
    if(!(file = TFile::Open(fn))) continue;
    if(kVerbose) Info("mergeProd", "Adding file %s ...", fn);
    else printf(".");fflush(stdout);
    if(!file->cd(nameTask)){ 
      Warning("mergeProd", "Missing %s. Skip file.", nameTask);
      continue;
    }
      
    if((ifile%nwrite)==(nwrite-1)){ 
      kWrite = kTRUE;
      if(!kVerbose) printf("\nMerging ");
      else printf(" ... Flushing merged file ...");
    }
    
    for(Int_t itask(0); itask<ntasks; itask++){
      file->cd(nameTask);
      if(!(arr = (TObjArray*)gDirectory->Get(taskName[itask]))){
        Warning("mergeEntry", "Missing %s. Skip task.", taskName[itask]);
        continue;
      }
      fOut->cd(nameTask);
      addPerformance(itask);
      arr->Delete(); delete arr;
    }
    file->Close(); delete file;
    ifile++; kWrite = kFALSE;
    //if(ifile>=35) break; 
  }
  
  if(!kVerbose) printf("\n");
  Info("mergeProd", "Flushing merged file ...");
  fOut->cd(nameTask);
  for(Int_t it(0); it<ntasks; it++){
    //if(!(arr = (TObjArray*)gDirectory->Get(taskName[it]))) continue;
    //arr->Write(taskName[it], TObject::kSingleKey);
    narr[it]->Write(taskName[it], TObject::kSingleKey);
  }  
  fOut->Close();
}