Esempio n. 1
0
	void testAuthor() {
		String *lname, *fname;
		lname = new String("Erdos");
		fname = new String("P.");
		Author *n = new Author(fname, lname);
		Set<Author> *targets = new Set<Author>();
		Author *x, *k;
		for (int i = 0; i < MAX_AUTHORS; i++) {
			lname = new String(i);
			fname = new String(i);
			x = new Author(fname, lname);
			n->publicouCom(x);

			lname = new String(i);
			fname = new String(i);
			k  = new Author(fname, lname);
			x->publicouCom(k);
			targets->add(k);
		}
		if (k != null) {
			targets->add(k);
		}

		printf("targets %d\n", targets->size());
		getchar();
		
		Author::erdosPtr->process(targets);
	}
Esempio n. 2
0
void Worker::doIt()
{
    Author author;
    author.setName("someone");
    QVERIFY(author.save());

    emit done();
}
Esempio n. 3
0
File: author.cpp Progetto: KDE/simon
/**
 * Factory function
 * \author Peter Grasch
 */
Author* Author::createAuthor(Scenario *parent, const QDomElement& elem)
{
  Author *a = new Author(parent);
  if (!a->deSerialize(elem)) {
    delete a;
    a=0;
  }
  return a;
}
int main(){
    Author author = Author("Douglas", "Adams", 1952);
    // Author { firstName: 'Douglas', lastName: 'Adams', yearBorn: 1952 }

    author.firstName = "Doug";
    // Author { firstName: 'Doug', lastName: 'Adams', yearBorn: 1952 }

    string fullName = author.getFullName();
    // "Doug Adams"

	return 0;
}
Esempio n. 5
0
void Publish::show()
{
	Author *p = head;
	while (p)
	{
		cout << "Name: " << p->getName() << endl;
		cout << "Lastname: " << p->getLastname() << endl;
		cout << "Type: Book" << endl;
		cout << "Title: " << p->getTitle() << endl;
		cout << "Number of pages: " << p->getKol() << endl; 
		p = p->next;
	}
}
Esempio n. 6
0
///@brief Adds author described in the form.
void AddAuthor::save()
{
	if(!validateInput())
		return;
	Author a;
	a.setFirstName(firstNameLineEdit->text());
	a.setLastName(lastNameLineEdit->text());
	a.setDescription(descriptionLineEdit->text());
	a.setCritique(critiqueLineEdit->text());
	a.setPicture(pictureLineEdit->text());
	a.setRating(ratingWidget->getRating());

	a.setThemes(getSelectedThemes());

	try
	{
		c->insertAuthor(a);
	}
	catch(DataBaseException dbe)
	{
		MessageBoxDataBaseException q(&dbe, this);
		q.appendText(tr("The author has not been added."));
		q.exec();
	}
	emit closeRequested();
}
Esempio n. 7
0
void UploadDialog::slotOk()
{
    if (mNameEdit->text().isEmpty()) {
        KMessageBox::error(this, i18n("Please put in a name."));
        //return;
        reject(); // FIXME - huh? return should work here but it accept()s!
    }

    QString language = m_languages.value(mLanguageCombo->currentText());

    Author author;
    author.setName(mAuthorEdit->text());
    author.setEmail(mEmailEdit->text());

    KTranslatable previewurl;
    KUrl purl = mPreviewUrl->url();
    //purl.setFileName(QString());
    // FIXME: what does this do?
    previewurl.addString(language, purl.url());

    KTranslatable summary;
    summary.addString(language, mSummaryEdit->toPlainText());

    KTranslatable name;
    name.addString(language, mNameEdit->text());

    m_entry = new Entry;
    m_entry->setName(name);
    m_entry->setAuthor(author);
    m_entry->setVersion(mVersionEdit->text());
    m_entry->setLicense(mLicenseCombo->currentText());
    m_entry->setPreview(previewurl);
    m_entry->setSummary(summary);

    if (mPayloadUrl.isValid()) {
        KConfigGroup cg(KGlobal::config(), QString("KNewStuffUpload:%1").arg(mPayloadUrl.fileName()));
        cg.writeEntry("name", mNameEdit->text());
        cg.writeEntry("author", mAuthorEdit->text());
        cg.writeEntry("author-email", mEmailEdit->text());
        cg.writeEntry("version", mVersionEdit->text());
        cg.writeEntry("license", mLicenseCombo->currentText());
        cg.writeEntry("preview", mPreviewUrl->url().url());
        cg.writeEntry("summary", mSummaryEdit->toPlainText());
        cg.writeEntry("language", mLanguageCombo->currentText());
        KGlobal::config()->sync();
    }

    accept();
}
Esempio n. 8
0
void pgBook::addAuthorToBook(Book book, Author author)
{
	pgAuthorsBooks authorsBooksRelation(this->driver);
	data authorBookData;
	authorBookData["author_id"] = author.getId();
	authorBookData["book_id"] = book.getId();
	AuthorsBooks item(authorBookData);
	authorsBooksRelation.create(item);
}
Esempio n. 9
0
void testDataStructures(){
	printf("number of unique authors: %d \n", (int)author_id_name.size());
	printf("number of unique articles: %d \n", (int)article_id_art.size());
	
	printf("created authors: %d \n", (int) authors.size());
	
	Article * lastarticle = articles.back();
	vector<string> lastauthors = lastarticle->authorsList();
	
	for (int s=0; s < lastauthors.size(); s++) {
		printf("author %d is: %s \n", s+1, lastauthors.at(s).c_str());
	}
	
	Author * lastauthor = authors.back();
	vector<string> lastauthpubs = lastauthor->pubsList();
	
	for (int p=0; p < lastauthpubs.size(); p++) {
		printf("pubs %d is: %s \n", p+1, lastauthpubs.at(p).c_str());
	}
	
}
Esempio n. 10
0
void displayBooks(const vector<Book*>& books)
{
	// set up cout to display currency
	cout.setf(ios::fixed);
	cout.setf(ios::showpoint);
	cout.precision(2);

	// display heading
	cout << "\nRecommended Reading List\n";

	// you provide the rest of this code
	// display each account
	for (int i = 0; i < books.size(); i++)
	{
		Author* pointer = books[i]->getAuthor();
		cout << books[i]->getTitle() << '\n';
		cout << pointer->getName() << '\n';
		cout << pointer->getAddress() << '\n';
		cout << books[i]->getPages() << " pages\n";

		// use rtti to see what kind of object is being pointed to, and display the 
		// appropriate child class data values
		AudioBook* bp = dynamic_cast<AudioBook*>(books[i]);
		if (bp)
		{
			cout << "The length of this audio book is " << bp->getAudioLength() << " minutes." << endl;
		}
		else
		{
			DigitalBook* bp = dynamic_cast<DigitalBook*>(books[i]);
			if (bp)
			{
				cout << "The format of this digital book is " << bp->getFormat() << endl;
			}
		} // end else

		cout << '$' << books[i]->getPrice() << "\n\n\n";
	}
}
Esempio n. 11
0
AuthorDetails::AuthorDetails(Author &a, QWidget* parent): QWidget(parent)
{
	setupUi(this);
	firstName->setText(a.getFirstName());
	lastName->setText(a.getLastName());
	picture->setPixmap(QPixmap(a.getPicture()));
	descriptionTextBrowser->setText(a.getDescription());
	critiqueTextBrowser->setText(a.getCritique());
	themes->setText(a.getThemesNames());
	QString wikiLink = wikipediaLink->text();
	QString lc = QLocale::system().name();
	lc.truncate(2);
	wikiLink.replace("<lc>", lc);
	wikiLink.replace("<title>", a.getFirstName().append(a.getLastName()).replace(" ", "_"));
	wikipediaLink->setText(wikiLink);
}
Esempio n. 12
0
Module* XmlModLoader::parsXml(const char* szFile)
{
    module.clear();
    ErrorLogger* logger  = ErrorLogger::Instance();

    TiXmlDocument doc(szFile);
    if(!doc.LoadFile())
    {
        OSTRINGSTREAM err;
        err<<"Syntax error while loading "<<szFile<<" at line "\
           <<doc.ErrorRow()<<": ";
        err<<doc.ErrorDesc();
        logger->addError(err);
        return nullptr;
    }

    /* retrieving root module */
    TiXmlElement *root = doc.RootElement();
    if(!root)
    {
        OSTRINGSTREAM err;
        err<<"Syntax error while loading "<<szFile<<" . ";
        err<<"No root element.";
        logger->addError(err);
        return nullptr;
    }

    if(!compareString(root->Value(), "module"))
    {
        /*
        OSTRINGSTREAM msg;
        msg<<szFile<<" is not a module descriptor file.";
        logger->addWarning(msg);
        */
        return nullptr;
    }

    /* retrieving name */
    auto* name = (TiXmlElement*) root->FirstChild("name");
    if(!name || !name->GetText())
    {
        OSTRINGSTREAM err;
        err<<"Module from "<<szFile<<" has no name.";
        logger->addError(err);
        //return NULL;
    }

    for(TiXmlElement* var = root->FirstChildElement("var"); var; var = var->NextSiblingElement())
    {
        if(var->Attribute("name") && var->GetText())
        {
            parser->addVariable(var->Attribute("name"), var->GetText());
        }
    }

    module.setXmlFile(szFile);

    if(name)
        module.setName(parser->parseText(name->GetText()).c_str());

    /* retrieving description */
    TiXmlElement* desc;
    if((desc = (TiXmlElement*) root->FirstChild("description")))
        module.setDescription(parser->parseText(desc->GetText()).c_str());

    /* retrieving version */
    TiXmlElement* ver;
    if((ver = (TiXmlElement*) root->FirstChild("version")))
        module.setVersion(parser->parseText(ver->GetText()).c_str());


    /* retrieving parameter */
    TiXmlElement* arguments;
    if((arguments = (TiXmlElement*) root->FirstChild("arguments")))
        for(TiXmlElement* param = arguments->FirstChildElement(); param;
                param = param->NextSiblingElement())
        {
            if(compareString(param->Value(), "param"))
            {
                if(param->GetText())
                {
                    bool brequired = false;
                    if(compareString(param->Attribute("required"), "yes"))
                        brequired = true;
                    Argument arg(parser->parseText(param->GetText()).c_str(),
                                 brequired,
                                 param->Attribute("desc"));
                    arg.setDefault(param->Attribute("default"));
                    module.addArgument(arg);
                }
            }
            else
            if(compareString(param->Value(), "switch"))
            {
                if(param->GetText())
                {
                    bool brequired = false;
                    if(compareString(param->Attribute("required"), "yes"))
                        brequired = true;
                    Argument arg(parser->parseText(param->GetText()).c_str(),
                                 brequired,
                                 param->Attribute("desc"), true);
                    arg.setDefault(param->Attribute("default"));
                    module.addArgument(arg);
                }
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Unrecognized tag from "<<szFile<<" at line "\
                   <<param->Row()<<".";
                logger->addWarning(war);
            }

        }


    /* retrieving rank */
    TiXmlElement* rank;
    if((rank = (TiXmlElement*) root->FirstChild("rank")) &&
        rank->GetText())
        module.setRank(atoi(parser->parseText(rank->GetText()).c_str()));


    /* retrieving authors information*/
    TiXmlElement* authors;
    if((authors = (TiXmlElement*) root->FirstChild("authors")))
        for(TiXmlElement* ath = authors->FirstChildElement(); ath;
                ath = ath->NextSiblingElement())
        {
            if(compareString(ath->Value(), "author"))
            {
                Author author;
                if(ath->GetText())
                    author.setName(parser->parseText(ath->GetText()).c_str());
                if(ath->Attribute("email"))
                    author.setEmail(ath->Attribute("email"));
                module.addAuthor(author);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Unrecognized tag from "<<szFile<<" at line "\
                   <<ath->Row()<<".";
                logger->addWarning(war);
            }

        }


   /* retrieving data */
    if(root->FirstChild("data"))
        for(TiXmlElement* data = root->FirstChild("data")->FirstChildElement();
            data; data = data->NextSiblingElement())
        {
            /* output data */
            if(compareString(data->Value(), "output"))
            {
                OutputData output;

                if(compareString(data->Attribute("port_type"), "stream") || !data->Attribute("port_type"))
                    output.setPortType(STREAM_PORT);
                else if(compareString(data->Attribute("port_type"), "event"))
                    output.setPortType(EVENT_PORT);
                else if(compareString(data->Attribute("port_type"), "service"))
                    output.setPortType(SERVICE_PORT);
                else
                {
                    OSTRINGSTREAM war;
                    war<<"Unknown port type \'"<<data->Attribute("port_type")<<"\' from "<<szFile<<" at line "\
                       <<data->Row()<<". Available types : stream, event, service";
                    logger->addWarning(war);
                }


                TiXmlElement* element;
                if(output.getPortType() != SERVICE_PORT )
                {
                    if((element = (TiXmlElement*) data->FirstChild("type")))
                        output.setName(parser->parseText(element->GetText()).c_str());
                    else
                    {
                        OSTRINGSTREAM war;
                        war<<"Output data from "<<szFile<<" at line "\
                           <<data->Row()<<" has no type.";
                        logger->addWarning(war);
                    }
                }
                else
                    output.setName("*");

                if((element = (TiXmlElement*) data->FirstChild("port")))
                {
                    output.setPort(parser->parseText(element->GetText()).c_str());
                    output.setCarrier(element->Attribute("carrier"));
                }
                else
                {
                    OSTRINGSTREAM war;
                    war<<"Output data from "<<szFile<<" at line "\
                       <<data->Row()<<" has no port.";
                    logger->addWarning(war);
                }

                if((element = (TiXmlElement*) data->FirstChild("description")))
                    output.setDescription(parser->parseText(element->GetText()).c_str());

                module.addOutput(output);
            } // end of output data

            /* input data */
            if(compareString(data->Value(), "input"))
            {
                InputData input;

                if(compareString(data->Attribute("port_type"), "stream") || !data->Attribute("port_type"))
                    input.setPortType(STREAM_PORT);
                else if(compareString(data->Attribute("port_type"), "event"))
                    input.setPortType(EVENT_PORT);
                else if(compareString(data->Attribute("port_type"), "service"))
                    input.setPortType(SERVICE_PORT);
                else
                {
                    OSTRINGSTREAM war;
                    war<<"Unknown port type \'"<<data->Attribute("port_type")<<"\' from "<<szFile<<" at line "\
                       <<data->Row()<<". Available types : stream, event, service";
                    logger->addWarning(war);
                }

                TiXmlElement* element;
                if(input.getPortType() != SERVICE_PORT )
                {

                    if((element = (TiXmlElement*) data->FirstChild("type")))
                        input.setName(parser->parseText(element->GetText()).c_str());
                    else
                    {
                        OSTRINGSTREAM war;
                        war<<"Input data from "<<szFile<<" at line "\
                           <<data->Row()<<" has no type.";
                        logger->addWarning(war);
                    }
                }
                else
                    input.setName("rpc");

                if((element = (TiXmlElement*) data->FirstChild("port")))
                {
                    input.setPort(parser->parseText(element->GetText()).c_str());
                    input.setCarrier(element->Attribute("carrier"));
                }
                else
                {
                    OSTRINGSTREAM war;
                    war<<"Input data from "<<szFile<<" at line "\
                       <<data->Row()<<" has no port.";
                    logger->addWarning(war);
                }

                if((element = (TiXmlElement*) data->FirstChild("description")))
                    input.setDescription(parser->parseText(element->GetText()).c_str());

                if((element = (TiXmlElement*) data->FirstChild("required")))
                    if(compareString(parser->parseText(element->GetText()).c_str(), "yes"))
                        input.setRequired(true);

                if((element = (TiXmlElement*) data->FirstChild("priority")))
                    if(compareString(parser->parseText(element->GetText()).c_str(), "yes"))
                        input.setPriority(true);

                module.addInput(input);
            } // end of input data

        }

    if(root->FirstChild("services")) {
        for(TiXmlElement* services = root->FirstChild("services")->FirstChildElement();
            services; services = services->NextSiblingElement())
        {
            /* server */
            if(compareString(services->Value(), "server"))
            {
                InputData input;
                input.setPortType(SERVICE_PORT);
                TiXmlElement* element;
                if((element = (TiXmlElement*) services->FirstChild("port"))) {
                    input.setPort(parser->parseText(element->GetText()).c_str());
                    input.setCarrier("tcp");
                }
                if((element = (TiXmlElement*) services->FirstChild("description")))
                    input.setDescription(parser->parseText(element->GetText()).c_str());
                if((element = (TiXmlElement*) services->FirstChild("type")))
                    input.setName(parser->parseText(element->GetText()).c_str());
                else
                    input.setName("rpc");
                module.addInput(input);
            }
            /* client */
            if(compareString(services->Value(), "client"))
            {
                OutputData output;
                output.setPortType(SERVICE_PORT);
                TiXmlElement* element;
                if((element = (TiXmlElement*) services->FirstChild("port"))) {
                    output.setPort(parser->parseText(element->GetText()).c_str());
                    output.setCarrier("tcp");
                }
                if((element = (TiXmlElement*) services->FirstChild("description")))
                    output.setDescription(parser->parseText(element->GetText()).c_str());
                if((element = (TiXmlElement*) services->FirstChild("type")))
                    output.setName(parser->parseText(element->GetText()).c_str());
                else
                    output.setName("rpc");
                module.addOutput(output);
            }
        }

    }

    /* retrieving broker*/
    TiXmlElement* element;
    if((element = (TiXmlElement*) root->FirstChild("deployer")))
    {
        module.setBroker(parser->parseText(element->GetText()).c_str());
        module.setNeedDeployer(true);
    }

    /* retrieving dependencies*/
    if(root->FirstChild("dependencies"))
        for(TiXmlElement* restag = root->FirstChild("dependencies")->FirstChildElement();
            restag; restag = restag->NextSiblingElement())
        {
            Computer computer;
            if(compareString(restag->Value(), "computer"))
            {
                Computer computer;
                computer.setXmlFile(szFile);
                for(TiXmlElement* comptag = restag->FirstChildElement();
                    comptag; comptag = comptag->NextSiblingElement())
                {
                     /* retrieving name */
                    if(compareString(comptag->Value(), "name"))
                        computer.setName(parser->parseText(comptag->GetText()).c_str());

                    /* retrieving description */
                     if(compareString(comptag->Value(), "description"))
                        computer.setDescription(parser->parseText(comptag->GetText()).c_str());

                    // platform
                    if(compareString(comptag->Value(), "platform"))
                    {
                        Platform os;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("name")))
                            os.setName(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("distribution")))
                            os.setDistribution(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("release")))
                            os.setRelease(parser->parseText(element->GetText()).c_str());
                        computer.setPlatform(os);
                    } // end of platform tag

                    /*
                    //multiplatform
                    if(compareString(comptag->Value(), "multiplatform"))
                    {
                        MultiPlatform mltPlatform;
                        for(TiXmlElement* mptag = comptag->FirstChild("multiplatform")->FirstChildElement();
                            mptag; mptag = mptag->NextSiblingElement())
                        {
                            // platform
                            if(compareString(mptag->Value(), "platform"))
                            {
                                Platform os;
                                TiXmlElement* element;
                                if((element = (TiXmlElement*) mptag->FirstChild("name")))
                                    os.setName(element->GetText());
                                if((element = (TiXmlElement*) mptag->FirstChild("distribution")))
                                    os.setDistribution(element->GetText());
                                if((element = (TiXmlElement*) mptag->FirstChild("release")))
                                    os.setDistribution(element->GetText());
                                mltPlatform.addPlatform(os);
                            }
                        }
                        module.addResource(mltPlatform);
                    }
                    // end of multiplatform tag
                    */
                    // memory
                    if(compareString(comptag->Value(), "memory"))
                    {
                        Memory mem;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("total_space")))
                            mem.setTotalSpace((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("free_space")))
                            mem.setFreeSpace((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        computer.setMemory(mem);
                    } // end of memory tag

                    // storage
                    if(compareString(comptag->Value(), "storage"))
                    {
                        Storage stg;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("total_space")))
                            stg.setTotalSpace((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("free_space")))
                            stg.setFreeSpace((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        computer.setStorage(stg);
                    } // end of storage tag

                    // processor
                    if(compareString(comptag->Value(), "processor"))
                    {
                        Processor proc;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("architecture")))
                            proc.setArchitecture(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("model")))
                            proc.setModel(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("cores")))
                            proc.setCores((size_t)atoi(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("siblings")))
                            proc.setSiblings((size_t)atoi(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("frequency")))
                            proc.setFrequency(atof(parser->parseText(element->GetText()).c_str()));
                        computer.setProcessor(proc);
                    } // end of processor tag

                    // network
                    if(compareString(comptag->Value(), "network"))
                    {
                        Network net;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("ip4")))
                            net.setIP4(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("ip6")))
                            net.setIP6(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("mac")))
                            net.setMAC(parser->parseText(element->GetText()).c_str());
                        module.addResource(net);
                        computer.setNetwork(net);
                    } // end of network tag

                    // yarp_port
                    if(compareString(comptag->Value(), "yarp_port"))
                    {
                        ResYarpPort yport;
                        auto* element = (TiXmlElement*) comptag->FirstChild("name");
                        if(element && element->GetText())
                        {
                            yport.setName(parser->parseText(element->GetText()).c_str());
                            yport.setPort(parser->parseText(element->GetText()).c_str());
                            computer.addPeripheral(yport);
                        }
                        else
                        {
                            OSTRINGSTREAM war;
                            war<<"yarp_port from "<<szFile<<" at line " <<comptag->Row()<<" has no name.";
                            logger->addWarning(war);
                        }
                    }

                    // gpu
                    if(compareString(comptag->Value(), "gpu"))
                    {
                        GPU gpu;
                        TiXmlElement* element;
                        if((element = (TiXmlElement*) comptag->FirstChild("name")))
                            gpu.setName(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("capability")))
                            gpu.setCompCompatibility(parser->parseText(element->GetText()).c_str());
                        if((element = (TiXmlElement*) comptag->FirstChild("cores")))
                            gpu.setCores((size_t)atoi(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("frequency")))
                            gpu.setFrequency(atof(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("register_block")))
                            gpu.setResgisterPerBlock((size_t)atoi(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("thread_block")))
                            gpu.setThreadPerBlock((size_t)atoi(parser->parseText(element->GetText()).c_str()));
                        if((element = (TiXmlElement*) comptag->FirstChild("overlap")))
                        {
                            if(compareString(parser->parseText(element->GetText()).c_str(), "yes"))
                                gpu.setOverlap(true);
                            else
                                gpu.setOverlap(false);
                        }


                        // global memory
                        if(comptag->FirstChild("global_memory"))
                        {
                            TiXmlElement* element;
                            element = (TiXmlElement*) comptag->FirstChild("global_memory");
                            if((element = (TiXmlElement*) element->FirstChild("total_space")))
                                gpu.setGlobalMemory((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        } // end of global memory tag

                        // shared memory
                        if(comptag->FirstChild("shared_memory"))
                        {
                            TiXmlElement* element;
                            element = (TiXmlElement*) comptag->FirstChild("shared_memory");
                            if((element = (TiXmlElement*) element->FirstChild("total_space")))
                                gpu.setSharedMemory((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        } // end of shared memory tag

                        // constant memory
                        if(comptag->FirstChild("constant_memory"))
                        {
                            TiXmlElement* element;
                            element = (TiXmlElement*) comptag->FirstChild("constant_memory");
                            if((element = (TiXmlElement*) element->FirstChild("total_space")))
                                gpu.setConstantMemory((Capacity)atol(parser->parseText(element->GetText()).c_str()));
                        } // end of shared memory tag
                        computer.addPeripheral(gpu);
                    } // end of gpu tag
                } // end of computer tag loop
                module.addResource(computer);
            } //end of if computer tag
        }// end of dependecnies tag

    return &module;
}
Esempio n. 13
0
void Pretreatment::authorDatePretreat(string path)
{
	int maxPc = 0,  maxCn = 0;
	double maxHi = 0, maxPi = 0, maxUpi = 0;
	int minPc = INT_MAX, minCn = INT_MAX;
	double minHi = DBL_MAX, minPi = DBL_MAX, minUpi = DBL_MAX;
	
	AuthorReader ar(path);

	Author au;

	while(ar.getNextAuthor(au))
	{
		cout<<au.getIndex()<<endl;
		if(au.getPc() < minPc && au.getPc() >= 0)
		{
			minPc = au.getPc();
		}
		
		if(au.getCn() < minCn && au.getCn() >= 0)
		{
			minCn = au.getCn();
		}

		if(au.getHi() < minHi && au.getHi() >= 0)
		{
			minHi = au.getHi();
		}

		if(au.getPi() < minPc && au.getPi() >= 0)
		{
			minPi = au.getPi();
		}
		if(au.getUpi() < minUpi && au.getUpi() >= 0)
		{
			minUpi = au.getUpi();
		}

		if(au.getPc() > maxPc)
		{
			maxPc = au.getPc();
		}
		if(au.getCn() > maxCn)
		{
			maxCn = au.getCn();
		}
		if(au.getHi() > maxHi)
		{
			maxHi = au.getHi();
		}
		if(au.getPi() > maxPi)
		{
			maxPi = au.getPi();
		}
		if(au.getUpi() > maxUpi)
		{
			maxUpi = au.getUpi();
		}
	}
	ofstream fout;
	fout.open("./authorResult", ios::out);
	fout<<"minPc : "<<minPc<<" maxPc : "<<maxPc<<endl;
	fout<<"minCn : "<<minCn<<" maxCn : "<<maxCn<<endl;
	fout<<"minHi : "<<minHi<<" maxHi : "<<maxHi<<endl;
	fout<<"minPi : "<<minPi<<" maxPi : "<<maxPi<<endl;
	fout<<"minUpi : "<<minUpi<<" maxUpi : "<<maxUpi<<endl;
	fout.close();
}
Esempio n. 14
0
Application* XmlAppLoader::parsXml(const char* szFile)
{
    app.clear();

    ErrorLogger* logger  = ErrorLogger::Instance();

    TiXmlDocument doc(szFile);
    if(!doc.LoadFile())
    {
        OSTRINGSTREAM err;
        err<<"Syntax error while loading "<<szFile<<" at line "\
           <<doc.ErrorRow()<<": ";
        err<<doc.ErrorDesc();
        logger->addError(err);
        return NULL;
    }

    /* retrieving root element */
    TiXmlElement *root = doc.RootElement();
    if(!root)
    {
        OSTRINGSTREAM err;
        err<<"Syntax error while loading "<<szFile<<" . ";
        err<<"No root element.";
        logger->addError(err);
        return NULL;
    }

    if(!compareString(root->Value(), "application"))
    {
        //OSTRINGSTREAM err;
        //err<<"File "<<szFile<<" has no tag <application>.";
        //logger->addError(err);
        return NULL;
    }

    /* retrieving name */
    TiXmlElement* name = (TiXmlElement*) root->FirstChild("name");
    if(!name || !name->GetText())
    {
        OSTRINGSTREAM err;
        err<<"Module from "<<szFile<<" has no name.";
        logger->addError(err);
        //return NULL;
    }

    app.setXmlFile(szFile);

    if(name)
    {
        string strname = name->GetText();
        for(unsigned int i=0; i<strname.size(); i++)
            if(strname[i] == ' ')
                strname[i] = '_';
        app.setName(strname.c_str());
    }

    /* retrieving description */
    TiXmlElement* desc;
    if((desc = (TiXmlElement*) root->FirstChild("description")))
        app.setDescription(desc->GetText());

    /* retrieving version */
    TiXmlElement* ver;
    if((ver = (TiXmlElement*) root->FirstChild("version")))
        app.setVersion(ver->GetText());

    /*
     * TODO: setting prefix of the main application is inactivated.
     * Check this should be supported in future or not!
     */
    /*
    //retrieving application prefix
    TiXmlElement* pref;
    if((pref = (TiXmlElement*) root->FirstChild("prefix")))
        app.setPrefix(pref->GetText());
    */

    /* retrieving authors information*/
    TiXmlElement* authors;
    if((authors = (TiXmlElement*) root->FirstChild("authors")))
        for(TiXmlElement* ath = authors->FirstChildElement(); ath;
                ath = ath->NextSiblingElement())
        {
            if(compareString(ath->Value(), "author"))
            {
                Author author;
                if(ath->GetText())
                    author.setName(ath->GetText());
                if(ath->Attribute("email"))
                    author.setEmail(ath->Attribute("email"));
                app.addAuthor(author);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Unrecognized tag from "<<szFile<<" at line "\
                   <<ath->Row()<<".";
                logger->addWarning(war);
            }
        }

    /* retrieving resources information*/
    TiXmlElement* resources;
    if((resources = (TiXmlElement*) root->FirstChild("dependencies")))
        for(TiXmlElement* res = resources->FirstChildElement(); res;
                res = res->NextSiblingElement())
        {
            if(compareString(res->Value(), "port"))
            {
                if(res->GetText())
                {
                    ResYarpPort resource(res->GetText());
                    resource.setPort(res->GetText());
                    app.addResource(resource);
                }
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Unrecognized tag from "<<szFile<<" at line "\
                   <<res->Row()<<".";
                logger->addWarning(war);
            }
        }

    /* retrieving modules information*/
    for(TiXmlElement* mod = root->FirstChildElement(); mod;
            mod = mod->NextSiblingElement())
    {
        if(compareString(mod->Value(), "module"))
        {
            TiXmlElement* element;
            if((element = (TiXmlElement*) mod->FirstChild("name")))
            {
                ModuleInterface module(element->GetText());
                if((element = (TiXmlElement*) mod->FirstChild("node")))
                    module.setHost(element->GetText());

                if((element = (TiXmlElement*) mod->FirstChild("parameters")))
                    module.setParam(element->GetText());

                if((element = (TiXmlElement*) mod->FirstChild("stdio")))
                    module.setStdio(element->GetText());

                if((element = (TiXmlElement*) mod->FirstChild("workdir")))
                    module.setWorkDir(element->GetText());

                if((element = (TiXmlElement*) mod->FirstChild("deployer")))
                    module.setBroker(element->GetText());
                if((element = (TiXmlElement*) mod->FirstChild("prefix")))
                    module.setPrefix(element->GetText());

                if((element = (TiXmlElement*) mod->FirstChild("rank")))
                    module.setRank(atoi(element->GetText()));

#ifdef WITH_GEOMETRY
                element = (TiXmlElement*) mod->FirstChild("geometry");
                if(element && element->GetText())
                {
                    yarp::os::Property prop(element->GetText());
                    GraphicModel model;
                    GyPoint pt;
                    if(prop.check("Pos"))
                    {
                        pt.x = prop.findGroup("Pos").find("x").asDouble();
                        pt.y = prop.findGroup("Pos").find("y").asDouble();
                        model.points.push_back(pt);
                        module.setModelBase(model);
                    }
                }
#endif
                /* retrieving resources information*/
                TiXmlElement* resources;
                if((resources = (TiXmlElement*) mod->FirstChild("dependencies")))
                {
                    for(TiXmlElement* res = resources->FirstChildElement(); res;
                            res = res->NextSiblingElement())
                    {
                        if(compareString(res->Value(), "port"))
                        {
                            if(res->GetText())
                            {
                                ResYarpPort resource(res->GetText());
                                resource.setPort(res->GetText());
                                if(res->Attribute("timeout"))
                                    resource.setTimeout(atof(res->Attribute("timeout")));
                                if(res->Attribute("request"))
                                    resource.setRequest(res->Attribute("request"));
                                if(res->Attribute("reply"))
                                    resource.setReply(res->Attribute("reply"));
                                module.addResource(resource);
                            }
                        }
                        else
                        {
                            OSTRINGSTREAM war;
                            war<<"Unrecognized tag from "<<szFile<<" at line "\
                               <<res->Row()<<".";
                            logger->addWarning(war);
                        }
                    }
                }
                /* retrieving portmaps */
                for(TiXmlElement* map = mod->FirstChildElement(); map;
                            map = map->NextSiblingElement())
                    if(compareString(map->Value(), "portmap"))
                    {
                        TiXmlElement* first;
                        TiXmlElement* second;
                        if((first=(TiXmlElement*) map->FirstChild("old")) &&
                           (second=(TiXmlElement*) map->FirstChild("new")) )
                        {
                            Portmap portmap(first->GetText(), second->GetText());
                            module.addPortmap(portmap);
                        }
                    }

                app.addImodule(module);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Module from "<<szFile<<" at line "\
                   <<mod->Row()<<" has not name tag.";
                logger->addWarning(war);
            }

        }
    }

    /* retrieving embedded application information*/
    for(TiXmlElement* embApp = root->FirstChildElement(); embApp;
            embApp = embApp->NextSiblingElement())
    {
        if(compareString(embApp->Value(), "application"))
        {
            TiXmlElement* name;
            TiXmlElement* prefix;
            if((name=(TiXmlElement*) embApp->FirstChild("name")))
            {
                ApplicationInterface IApp(name->GetText());
                if((prefix=(TiXmlElement*) embApp->FirstChild("prefix")))
                    IApp.setPrefix(prefix->GetText());
#ifdef WITH_GEOMETRY
                TiXmlElement* element = (TiXmlElement*) embApp->FirstChild("geometry");
                if(element && element->GetText())
                {
                    yarp::os::Property prop(element->GetText());
                    GraphicModel model;
                    GyPoint pt;
                    if(prop.check("Pos"))
                    {
                        pt.x = prop.findGroup("Pos").find("x").asDouble();
                        pt.y = prop.findGroup("Pos").find("y").asDouble();
                        model.points.push_back(pt);
                        IApp.setModelBase(model);
                    }
                }
#endif
                app.addIapplication(IApp);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Incomplete application tag from "<<szFile<<" at line "\
                   <<embApp->Row()<<". (no name)";
                logger->addWarning(war);
            }
        }
    }


    /* retrieving arbitrator information*/
    for(TiXmlElement* arb = root->FirstChildElement(); arb;
            arb = arb->NextSiblingElement())
    {
        if(compareString(arb->Value(), "arbitrator"))
        {
            TiXmlElement* port = (TiXmlElement*) arb->FirstChild("port");
            if(port && port->GetText())
            {
                Arbitrator arbitrator(port->GetText());

                // retrieving rules
                for(TiXmlElement* rule = arb->FirstChildElement(); rule;
                    rule = rule->NextSiblingElement())
                {
                    if(compareString(rule->Value(), "rule"))
                    {
                        if(rule->Attribute("connection"))
                            arbitrator.addRule(rule->Attribute("connection"), rule->GetText());
                    }
                }
#ifdef WITH_GEOMETRY
                TiXmlElement* geometry = (TiXmlElement*) arb->FirstChild("geometry");
                if(geometry && geometry->GetText())
                {
                    yarp::os::Property prop(geometry->GetText());
                    GraphicModel model;
                    if(prop.check("Pos"))
                    {
                        yarp::os::Bottle pos = prop.findGroup("Pos");
                        for(int i=1; i<pos.size(); i++)
                        {
                            GyPoint pt;
                            pt.x = pos.get(i).find("x").asDouble();
                            pt.y = pos.get(i).find("y").asDouble();
                            model.points.push_back(pt);
                        }
                        arbitrator.setModelBase(model);
                    }
                }
#endif
                app.addArbitrator(arbitrator);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Incomplete arbitrator tag from "<<szFile<<" at line "\
                   <<arb->Row()<<".";
                logger->addWarning(war);
            }
        }
    }

    /* retrieving connections information*/
    for(TiXmlElement* cnn = root->FirstChildElement(); cnn;
            cnn = cnn->NextSiblingElement())
    {
        if(compareString(cnn->Value(), "connection"))
        {
            TiXmlElement* from = (TiXmlElement*) cnn->FirstChild("from");
            TiXmlElement* to = (TiXmlElement*) cnn->FirstChild("to");

            if(!from)
                from = (TiXmlElement*) cnn->FirstChild("output");
            if(!to)
                to = (TiXmlElement*) cnn->FirstChild("input");

            TiXmlElement* protocol;
            if(from && to)
            {
                string strCarrier;
                if((protocol=(TiXmlElement*) cnn->FirstChild("protocol")) &&
                    protocol->GetText())
                    strCarrier = protocol->GetText();
                Connection connection(from->GetText(),
                                    to->GetText(),
                                    strCarrier.c_str());
                if(from->Attribute("external") &&
                    compareString(from->Attribute("external"), "true"))
                {
                    connection.setFromExternal(true);
                    if(from->GetText())
                    {
                        ResYarpPort resource(from->GetText());
                        resource.setPort(from->GetText());
                        app.addResource(resource);
                    }
                }
                if(to->Attribute("external") &&
                    compareString(to->Attribute("external"), "true"))
                {
                    if(to->GetText())
                    {
                        connection.setToExternal(true);
                        ResYarpPort resource(to->GetText());
                        resource.setPort(to->GetText());
                        app.addResource(resource);
                    }
                }

                //Connections which have the same port name in Port Resources
                // should also be set as external
                for(int i=0; i<app.resourcesCount(); i++)
                {
                    ResYarpPort res = app.getResourceAt(i);
                    if(compareString(res.getPort(), connection.from()))
                        connection.setFromExternal(true);
                    if(compareString(res.getPort(), connection.to()))
                        connection.setToExternal(true);
                }

                if(cnn->Attribute("id"))
                    connection.setId(cnn->Attribute("id"));

                if(cnn->Attribute("persist") &&
                        compareString(cnn->Attribute("persist"), "true"))
                    connection.setPersistent(true);

#ifdef WITH_GEOMETRY
                TiXmlElement* geometry = (TiXmlElement*) cnn->FirstChild("geometry");
                if(geometry && geometry->GetText())
                {
                    yarp::os::Property prop(geometry->GetText());
                    GraphicModel model;
                    if(prop.check("Pos"))
                    {
                        yarp::os::Bottle pos = prop.findGroup("Pos");
                        for(int i=1; i<pos.size(); i++)
                        {
                            GyPoint pt;
                            pt.x = pos.get(i).find("x").asDouble();
                            pt.y = pos.get(i).find("y").asDouble();
                            model.points.push_back(pt);
                        }
                        connection.setModelBase(model);
                    }
                }
#endif

                app.addConnection(connection);
            }
            else
            {
                OSTRINGSTREAM war;
                war<<"Incomplete connection tag from "<<szFile<<" at line "\
                   <<cnn->Row()<<".";
                logger->addWarning(war);
            }
        }
    }


    return &app;

}
Esempio n. 15
0
bool AuthorNode::setValue (const String& strMemberName, const String* pstrValue)
{
    bool bValueSet = false;
    Author* pObject = dynamic_cast<Author*>(m_pObject);
    if (strMemberName == L"CreatedBy")
    {
        if (!pstrValue)
        {
            pObject->resetValue_CreatedBy();
        }
        else
        {
            pObject->setCreatedBy(StringObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    if (strMemberName == L"CreatedByEmail")
    {
        if (!pstrValue)
        {
            pObject->resetValue_CreatedByEmail();
        }
        else
        {
            pObject->setCreatedByEmail(StringObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    if (strMemberName == L"Company")
    {
        if (!pstrValue)
        {
            pObject->resetValue_Company();
        }
        else
        {
            pObject->setCompany(StringObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    if (strMemberName == L"CompanyURL")
    {
        if (!pstrValue)
        {
            pObject->resetValue_CompanyURL();
        }
        else
        {
            pObject->setCompanyURL(StringObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    if (strMemberName == L"TimeStamp")
    {
        if (!pstrValue)
        {
            pObject->resetValue_TimeStamp();
        }
        else
        {
            pObject->setTimeStamp(StringObjectImpl::parseString(pstrValue->c_str(), pstrValue->length()));
            bValueSet = true;
        }
    }
    return bValueSet;
}
Esempio n. 16
0
bool AuthorNode::getValue (const String& strMemberName, String& strValue)
{
    bool bValueSet = false;
    Author* pObject = dynamic_cast<Author*>(m_pObject);
    if (strMemberName == L"value")
    {
        ValueObject* pValueObj = dynamic_cast<ValueObject*>(m_pObject);
        if (pValueObj)
        {
            if (!pValueObj->isNothing())
            {
                strValue = pValueObj->toString();
                bValueSet = true;
            }
        }
    }
    else if (strMemberName == L"CreatedBy")
    {
        if (pObject->hasValue_CreatedBy())
        {
            strValue = (StringObjectImpl(pObject->getCreatedBy())).toString();
            bValueSet = true;
        }
    }
    else if (strMemberName == L"CreatedByEmail")
    {
        if (pObject->hasValue_CreatedByEmail())
        {
            strValue = (StringObjectImpl(pObject->getCreatedByEmail())).toString();
            bValueSet = true;
        }
    }
    else if (strMemberName == L"Company")
    {
        if (pObject->hasValue_Company())
        {
            strValue = (StringObjectImpl(pObject->getCompany())).toString();
            bValueSet = true;
        }
    }
    else if (strMemberName == L"CompanyURL")
    {
        if (pObject->hasValue_CompanyURL())
        {
            strValue = (StringObjectImpl(pObject->getCompanyURL())).toString();
            bValueSet = true;
        }
    }
    else if (strMemberName == L"TimeStamp")
    {
        if (pObject->hasValue_TimeStamp())
        {
            strValue = (StringObjectImpl(pObject->getTimeStamp())).toString();
            bValueSet = true;
        }
    }
    return bValueSet;
}
void PropertiesTable::showModuleTab(Module *mod)
{
    modules.clear();
    disconnect(moduleProperties,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModItemChanged(QTreeWidgetItem*,int)));
    disconnect(moduleProperties,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onModItemDoubleClicked(QTreeWidgetItem*,int)));

    currentApplication = NULL;
    currentModule = mod;
    propertiesTab->clear();
    propertiesTab->addTab(moduleProperties,"Module Properties");
    propertiesTab->addTab(moduleDescription,"Description");
    moduleProperties->clear();
    moduleDescription->clear();

    appProperties->hide();
    moduleProperties->show();
    moduleDescription->show();

    modName = new QTreeWidgetItem(moduleProperties,QStringList() << "Name" << mod->getName());
    modNode = new QTreeWidgetItem(moduleProperties,QStringList() << "Node");
    modStdio = new QTreeWidgetItem(moduleProperties,QStringList() << "Stdio" << mod->getStdio());
    modWorkDir = new QTreeWidgetItem(moduleProperties,QStringList() << "Workdir" << mod->getWorkDir());
    modPrefix = new QTreeWidgetItem(moduleProperties,QStringList() << "Prefix" << mod->getBasePrefix());
    modDeployer = new QTreeWidgetItem(moduleProperties,QStringList() << "Deployer");
    modParams = new QTreeWidgetItem(moduleProperties,QStringList() << "Parameters" << mod->getParam());

    lastPrefix = mod->getBasePrefix();

    modStdio->setFlags(modStdio->flags() | Qt::ItemIsEditable);
    modWorkDir->setFlags(modWorkDir->flags() | Qt::ItemIsEditable);
    modPrefix->setFlags(modPrefix->flags() | Qt::ItemIsEditable);

    moduleProperties->addTopLevelItem(modName);
    moduleProperties->addTopLevelItem(modNode);
    moduleProperties->addTopLevelItem(modStdio);
    moduleProperties->addTopLevelItem(modWorkDir);
    moduleProperties->addTopLevelItem(modPrefix);
    moduleProperties->addTopLevelItem(modDeployer);
    moduleProperties->addTopLevelItem(modParams);

    if(deployerCombo){
        delete deployerCombo;
        deployerCombo = NULL;
    }

    if(nodeCombo){
        delete nodeCombo;
        nodeCombo = NULL;
    }
    deployerCombo = new QComboBox();
    nodeCombo = new QComboBox();

    deployerCombo->setEditable(true);
    nodeCombo->setEditable(true);

    if(compareString(mod->getBroker(),"yarpdev")){
        deployerCombo->addItem("yarpdev");
    }else if(compareString(mod->getBroker(),"icubmoddev")){
        deployerCombo->addItem("icubmoddev");
    }else{
        deployerCombo->addItem("local");
        deployerCombo->addItem("yarprun");
    }

    if(strlen(mod->getBroker())){
        deployerCombo->setCurrentText(mod->getBroker());
    }else if(compareString(mod->getHost(),"localhost")){
        deployerCombo->setCurrentText("local");
    }
    if(mod->getNeedDeployer()){
        deployerCombo->setEditable(false);
    }


    nodeCombo->addItem(mod->getHost());
    if(QString(mod->getHost()) != "localhost"){
        nodeCombo->addItem("localhost");
    }
    ResourcePContainer resources = manager->getKnowledgeBase()->getResources();
    for(ResourcePIterator itr=resources.begin(); itr!=resources.end(); itr++){
        Computer* comp = dynamic_cast<Computer*>(*itr);
        if(comp && !compareString(comp->getName(), "localhost")){
            nodeCombo->addItem(comp->getName());
        }
    }
    connect(nodeCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
    connect(nodeCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
    paramsSignalMapper->setMapping(nodeCombo,nodeCombo);

    connect(deployerCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
    connect(deployerCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
    paramsSignalMapper->setMapping(deployerCombo,deployerCombo);




     /*****************************/
     // Populate paramters
     for(int i=0;i<mod->argumentCount();i++){
         Argument a = mod->getArgumentAt(i);
         QTreeWidgetItem *it = new QTreeWidgetItem(modParams,QStringList() << a.getParam());
         QComboBox *paramCombo = new QComboBox();
         paramCombo->setEditable(true);
         paramCombo->addItem(a.getValue());
         if(strcmp(a.getDefault(),a.getValue()) != 0 ){
            paramCombo->addItem(a.getDefault());
         }
         moduleProperties->setItemWidget(it,1,paramCombo);
         connect(paramCombo, SIGNAL(editTextChanged(QString)), paramsSignalMapper, SLOT(map()));
         connect(paramCombo, SIGNAL(currentIndexChanged(int)), paramsSignalMapper, SLOT(map()));
         paramsSignalMapper->setMapping(paramCombo,paramCombo);
     }
     /*****************************/

    moduleProperties->setItemWidget(modDeployer,1,deployerCombo);
    moduleProperties->setItemWidget(modNode,1,nodeCombo);
    modParams->setExpanded(true);


    QTreeWidgetItem *nameItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Name" << mod->getName());
    QTreeWidgetItem *versionItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Version" << mod->getVersion());
    QTreeWidgetItem *descriptionItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Description" << mod->getDescription());
    QTreeWidgetItem *parametersItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Parameters");
    for(int i=0;i<mod->argumentCount();i++){
        Argument a = mod->getArgumentAt(i);
        QTreeWidgetItem *it = new QTreeWidgetItem(parametersItem,QStringList() << a.getParam() << a.getDescription());

    }

    QTreeWidgetItem *authorsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Authors" );
    for(int i=0;i<mod->authorCount();i++){
        Author a = mod->getAuthorAt(i);
        QTreeWidgetItem *it = new QTreeWidgetItem(authorsItem,QStringList() << a.getName() << a.getEmail());
    }

    QTreeWidgetItem *inputsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Inputs" );
    for(int i=0;i<mod->inputCount();i++){
        InputData a = mod->getInputAt(i);

        QTreeWidgetItem *type = new QTreeWidgetItem(inputsItem,QStringList() << "Type" << a.getName());
        QTreeWidgetItem *port = new QTreeWidgetItem(type,QStringList() << "Port" << a.getPort());
        QTreeWidgetItem *desc = new QTreeWidgetItem(type,QStringList() << "Description" << a.getDescription());
        QTreeWidgetItem *req = new QTreeWidgetItem(type,QStringList() << "Required" << (a.isRequired() ? "yes" : "no"));
        Q_UNUSED(port);
        Q_UNUSED(desc);
        Q_UNUSED(req);
    }

    QTreeWidgetItem *outputsItem = new QTreeWidgetItem(moduleDescription,QStringList() << "Outputs" );
    for(int i=0;i<mod->outputCount();i++){
        OutputData a = mod->getOutputAt(i); //TODO controllare

        QTreeWidgetItem *type = new QTreeWidgetItem(outputsItem,QStringList() << "Type" << a.getName());
        QTreeWidgetItem *port = new QTreeWidgetItem(type,QStringList() << "Port" << a.getPort());
        QTreeWidgetItem *desc = new QTreeWidgetItem(type,QStringList() << "Description" << a.getDescription());
        Q_UNUSED(port);
        Q_UNUSED(desc);
    }

    moduleDescription->addTopLevelItem(nameItem);
    moduleDescription->addTopLevelItem(versionItem);
    moduleDescription->addTopLevelItem(descriptionItem);
    moduleDescription->addTopLevelItem(parametersItem);
    moduleDescription->addTopLevelItem(authorsItem);
    moduleDescription->addTopLevelItem(inputsItem);
    moduleDescription->addTopLevelItem(outputsItem);

    connect(moduleProperties,SIGNAL(itemChanged(QTreeWidgetItem*,int)),this,SLOT(onModItemChanged(QTreeWidgetItem*,int)));
    connect(moduleProperties,SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)),this,SLOT(onModItemDoubleClicked(QTreeWidgetItem*,int)));

}
Esempio n. 18
0
bool operator==(Author const & l, Author const & r)
{
	return l.name() == r.name() && l.email() == r.email();
}
int main()
{
    Author authors;
    string authorName, authorWork, searchItem;
    // Preparation Work : cin some items
    do{
        cout << "Enter author name(Ctrl+Z to quit):" << endl;
        cin >> authorName;
        if ( ! cin )
            break;
        cout << "Enter author's work (Ctrl+Z to quit)" << endl;
        while ( cin >> authorWork )
            authors.insert( make_pair(authorName,authorWork) );
        cin.clear();
    } while ( cin );
    cin.clear();

    // Search and Erasure work
    cout << "Who is the author that you want to erase? :" << endl;
    cin >> searchItem;
    Author::iterator iter;

    // for Exercise 10.26
    iter = authors.find( searchItem );
    if ( iter != authors.end() )
        authors.erase( searchItem );
    else
        cout << "No match found!" << endl;
    // end for Exercise 10.26

    // for Exercise 10.27
    pair<AuIter, AuIter> pos = authors.equal_range( searchItem );
    if ( pos.first != pos.second )
        authors.erase( pos.first, pos.second );
     else
        cout << "No match found!" << endl;
    // end for Exercise 10.27

    // Final stored items Output
    cout << "author\t\twork:" << endl;
    for( iter = authors.begin(); iter != authors.end(); iter++)
        cout << iter->first << "\t\t" << iter->second << endl;

    // for Exercise 10.28
    iter = authors.begin();
    if ( iter == authors.end() )
    {
        cout << "Empty multimap!" << endl;
        return 0;
    }
    string currAuthor, preAuthor;
    do{
        currAuthor = iter->first;
        if ( preAuthor.empty() || currAuthor[0] != preAuthor[0] )
            cout << "Author Names Begining with '" << currAuthor[0] << "' :" <<endl;
        cout << currAuthor;
        for (pos = authors.equal_range(currAuthor); pos.first != pos.second; pos.first++)
            cout << ", " << pos.first->second;
        cout << endl;
        iter = pos.second;
        preAuthor = currAuthor;
    } while ( iter != authors.end() );
    // end for Exercise 10.28

    return 0;
}