Ejemplo n.º 1
0
bool Tobias::isSolved( size_t max ) const {
	// Each student assigned to exactly one slot:
	for( size_t s = 0; s < getNames().size(); s++ ) {
		size_t count = 0;
		for( size_t i = 0; i < slots(); i++ ) {
			if( schedule.at( s * slots() + i ) ) {
				count++;
			}
		}
		if( count != 1 ) {
			return false;
		}
	}
	// Each slot at most max students:
	for( size_t i = 0; i < slots(); i++ ) {
		size_t count = 0;
		for( size_t s = 0; s < getNames().size(); s++ ) {
			if( schedule.at( s * slots() + i ) ) {
				count++;
			}
		}
		if( count > max ) {
			return false;
		}
	}
	return true;
}
Ejemplo n.º 2
0
static  void
getNames(symbol *s, char **nameptr, int *numvar, int maxptr, int *i)
{
   if (s)
   {
      getNames(s->left, nameptr, numvar, maxptr, i);
      if (*i < maxptr)
      {
	 /* v = (varInfo *)s->val; */
	 /* if (v->T.size > 1) */
	 {
	    if (nameptr != NULL)/* if nameptr is null just count vars */
	    {
	       nameptr[*i] = s->name;
	       *i += 1;
	    }
	    *numvar += 1;
	 }
	 if (bgflag > 1)
	    fprintf(stderr, "name: '%s', i = %d, number: %d \n",
		    s->name, *i, *numvar);
      }
      else
      {
	 *numvar = -1;		/* mark error */
      }
      getNames(s->right, nameptr, numvar, maxptr, i);
   }
}
Ejemplo n.º 3
0
// This test represents an invariant test. First, several phases, components,
// and properties are generated (more or less randomly).
// Then, an XML-tree is generated from those information. The XML tree is then
// parsed into a configTree, from which an MPL::MaterialObject is generated.
// Last step compares the names (as well as the topology) of the Material object
// with the specified parameters.
TEST(Material, parseMaterials)
{
    // This is the topology of our new material: The size of the
    // topology vector determines the number of phases, while each
    // vector component refers to the number of components of that
    // phase.
    // The number of properties is fixed in each case and is
    // determined by the size of the PropertyEnum enumerator.
    std::vector<std::size_t> const mediumTopology = {1, 1, 1};

    Medium medium(mediumTopology);

    // the omnivagant medium:
    medium.property[MPL::name] = "luminiferous_aether";

    medium.phases[0].property[MPL::name] = "Solid";
    medium.phases[1].property[MPL::name] = "AqueousLiquid";
    medium.phases[2].property[MPL::name] = "Gas";

    medium.phases[0].component[0].property[MPL::thermal_conductivity] = "0.654";
    medium.phases[0].component[0].property[MPL::reference_temperature] = "333";
    medium.phases[0].component[0].property[MPL::reference_density] = "2100.0";
    medium.phases[0].component[0].property[MPL::drhodT] = "-0.4";

    medium.phases[0].component[0].property[MPL::name] = "VerySolid";
    medium.phases[1].component[0].property[MPL::name] = "Water";
    medium.phases[2].component[0].property[MPL::name] = "SuperFluid";
    medium.phases[2].component[0].property[MPL::thermal_conductivity] = "1";
    medium.property[MPL::permeability] = "1.0e-12";

    // create an actual MaterialProperty-Medium out of the specifier object
    auto const m = createTestMaterial(makeMedium(medium));

    // those two vectors will actually be compared
    std::vector<std::string> expected;
    std::vector<std::string> observed;

    // now we roam through all phases and components, finding their names
    // and storing them in the two vectors
    for (std::size_t p = 0; p < m->numberOfPhases(); ++p)
    {
        const auto& phase = m->phase(p);
        getNames(phase.name(), medium.phases[p].property[MPL::name], "no_name",
                 observed, expected);

        for (std::size_t c = 0; c < phase.numberOfComponents(); ++c)
        {
            const auto& component = phase.component(c);
            getNames(component.name(),
                     medium.phases[p].component[c].property[MPL::name],
                     "no_name", observed, expected);
        }
    }

    // Now, the two vectors are compared. If there is some derivation,
    // we can easily locate the problem.
    ASSERT_EQ(expected, observed);
}
Ejemplo n.º 4
0
void H5Dataset::getAccessibleAttribute(const std::string & _name, const int pos, void * pvApiCtx) const
{
    std::string lower(_name);

    std::transform(_name.begin(), _name.end(), lower.begin(), tolower);

    if (lower == "attributes")
    {
        std::vector<std::string> names;
        getNames(*this, names, ATTRIBUTE);
        H5BasicData<char>::putStringVectorOnStack(names, (int)names.size(), 1, pos, pvApiCtx);

        return;
    }
    else if (lower == "type")
    {
        const H5Type & type = const_cast<H5Dataset *>(this)->getDataType();
        type.createOnScilabStack(pos, pvApiCtx);

        return;
    }
    else if (lower == "dataspace")
    {
        const H5Dataspace & space = const_cast<H5Dataset *>(this)->getSpace();
        space.createOnScilabStack(pos, pvApiCtx);

        return;
    }
    else if (lower == "data")
    {
        const H5Data & data = const_cast<H5Dataset *>(this)->getData();
        data.toScilab(pvApiCtx, pos, 0, 0, H5Options::isReadFlip());

        if (data.mustDelete())
        {
            delete &data;
        }

        return;
    }
    /*else if (lower == "layout")
    {
        const H5Dataset::H5Layout & layout = const_cast<H5Dataset *>(this)->getLayout();
        layout.createOnScilabStack(pos, pvApiCtx);

        return;
    }*/
    else
    {
        try
        {
            H5Object & obj = H5Object::getObject(*const_cast<H5Dataset *>(this), _name);
            obj.createOnScilabStack(pos, pvApiCtx);
            return;
        }
        catch (const H5Exception & /*e*/) { }
    }

    H5Object::getAccessibleAttribute(_name, pos, pvApiCtx);
}
Ejemplo n.º 5
0
ColorMerger::ColorMerger(std::vector<std::pair<properties::tagType, properties::iterator> > tags,
                         std::map<std::string, streamRecord*>& outStreamRecords,
                         std::vector<std::map<std::string, streamRecord*> >& inStreamRecords,
                         properties* props) :
                    Merger(advance(tags), outStreamRecords, inStreamRecords, props)
{
  if(props==NULL) props = new properties();
  this->props = props;
  
  assert(tags.size()>0);
  vector<string> names = getNames(tags); assert(allSame<string>(names));
  assert(*names.begin() == "textColor" ||
         *names.begin() == "bgColor"   ||
         *names.begin() == "borderColor");

  map<string, string> pMap;
  properties::tagType type = streamRecord::getTagType(tags); 
  if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging Trace!"<<endl; exit(-1); }
  if(type==properties::enterTag) {    
    // Merge the selector IDs along all the streams (these should already have been merged when we processed
    // entry in this color annotation's associated colorSelector
    int mergedSelID = streamRecord::mergeIDs("colorSelector", "selID", pMap, tags, outStreamRecords, inStreamRecords);
    pMap["selID"]  = txt()<<mergedSelID;
    
    // Merge the trace IDs along all the streams
    int mergedInstID = streamRecord::mergeIDs("color", "instanceID", pMap, tags, outStreamRecords, inStreamRecords);
    pMap["instanceID"] = txt()<<mergedInstID;
    
    // We take an arbitrary value out of the set provided
    pMap["value"] = *getValues(tags, "value").begin();
  }
  
  props->add(*names.begin(), pMap);
}
Ejemplo n.º 6
0
ColorSelectorMerger::ColorSelectorMerger(std::vector<std::pair<properties::tagType, properties::iterator> > tags,
                         std::map<std::string, streamRecord*>& outStreamRecords,
                         std::vector<std::map<std::string, streamRecord*> >& inStreamRecords,
                         properties* props) :
                    Merger(advance(tags), outStreamRecords, inStreamRecords, props)
{
  if(props==NULL) props = new properties();
  this->props = props;
  
  map<string, string> pMap;
  properties::tagType type = streamRecord::getTagType(tags); 
  if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging Trace!"<<endl; exit(-1); }
  if(type==properties::enterTag) {
    assert(tags.size()>0);
    vector<string> names = getNames(tags); assert(allSame<string>(names));
    assert(*names.begin() == "colorSelector");
    
    // Merge the selector IDs along all the streams
    int mergedSelID = streamRecord::mergeIDs("colorSelector", "selID", pMap, tags, outStreamRecords, inStreamRecords);
    pMap["selID"]  = txt()<<mergedSelID;
    
    pMap["startR"] = txt()<<vAvg(str2float(getValues(tags, "startR")));
    pMap["endR"]   = txt()<<vAvg(str2float(getValues(tags, "endR")));
    pMap["startG"] = txt()<<vAvg(str2float(getValues(tags, "startG")));
    pMap["endG"]   = txt()<<vAvg(str2float(getValues(tags, "endG")));
    pMap["startB"] = txt()<<vAvg(str2float(getValues(tags, "startB")));
    pMap["endB"]   = txt()<<vAvg(str2float(getValues(tags, "endB")));
  }
  props->add("colorSelector", pMap);
}
Ejemplo n.º 7
0
int
QZDir::updateZ()
{
  if (m_type!=QZF_UNCHK) return m_type;

  int       my_type;
  QCString  m_zname, m_sub;
  ZEntry    *my_entry;

  my_type = getNames(m_path, m_zname, m_sub, &my_entry);

  if (my_type&QZF_DIR) {
    /* this is in zip file */
    if (my_type&QZF_ZIP) {
      my_entry->grab();
      m_dir.z = (ZDirEntry*)my_entry;
    } else {
      m_dir.q = new QDir(m_path);
    }
    m_type = my_type;
  } else {
    m_type = QZF_NONE;
  }
  return m_type;
}
Ejemplo n.º 8
0
int main() {
    getNames();
    setCombinationNames();

    while (gameFinished() == false) {

        printf("\n%s ist dran!\n\n", players[currentPlayer].name);
        pause();

        for (int i = 1; i <= 3; i++) { //Every time we may throw three times
            throwDices();

            if (i < 3) {
                if (ask("Nochmal wuerfeln?")) {
                    keepDices();
                }
                else {
                    break;
                }
            }
        }

        selectCombination();
        nextPlayer();
    }

    showPlayerEvalution();

    return 0;
}
Ejemplo n.º 9
0
int
bqc (int argc, char *argv[], int opCode)
{
    struct queueInfoEnt *queueInfo;
    char **queueList=NULL, **queues ;
    int numQueues, all = FALSE;
    int i;

    queues = NULL;
    if (argc == optind)
        numQueues =1;
    else {
        numQueues = getNames (argc, argv, optind, &queueList, &all, "queueC");
        if (!all)
            queues = queueList;
    }

    if ((queueInfo = lsb_queueinfo(queues, &numQueues, NULL, NULL, 0))
        == NULL) {
        if (lsberrno == LSBE_BAD_QUEUE
            && queues && queues[numQueues])
            lsb_perror(queues[numQueues]);
        else
            lsb_perror(NULL);
        return (-1);
    }

    for (i = 0; i < numQueues; i++) {
        ctrlQueue (queueInfo[i].queue, opCode);
    }
    return (exitrc);
}
Ejemplo n.º 10
0
bool Tobias::solve( size_t max, size_t slot, size_t student ) {
	//std::clog << slot << "," << student << "..." << std::endl;
	if( student == getNames().size() ) {
		slot++;
		student = 0;
	}
	if( avaiableSlots() == 0 || slot >= slots() ) {
		//std::cerr << (*this) << std::endl;
		return isSolved( max );
	}
	//std::clog << "!" << !slotFull( slot, max ) << std::endl;
	//std::clog << ">" << getChoices().at( student * slots() + slot ) << std::endl;
	//std::clog << "+" << !isStudentScheduled( student ) << std::endl;
	if( getReference().at( slot ) && !slotFull( slot, max ) && getChoices().at( student * slots() + slot ) && !isStudentScheduled( student ) ) {
		schedule[ student * slots() + slot ] = true;
		//std::clog << "Trying schedule[" << student << "," << slot << "] = true..." << std::endl;
		if( solve( max, slot, student + 1 ) ) {
			return true;
		}
		schedule[ student * slots() + slot ] = false;
	}
//	else {
		return solve( max, slot, student + 1 );
//	}
	return false;
}
Ejemplo n.º 11
0
SceneGraphModel::SceneGraphModel(GameObjectItem* root, QObject* parent)
	: QAbstractItemModel(parent),
	m_root(root)
{
	getNames();
	currentID = 0;
}
Ejemplo n.º 12
0
void StudentDB::newQuiz(QString quizName, QVector<StudentQuiz> quizVector)
{
    QSqlQuery q;
    QString insert = "INSERT INTO quizlist (quizname) VALUES ('" + quizName + "')";
    q.exec(insert);
    QString newQuizTable = "CREATE TABLE IF NOT EXISTS " + quizName + " (StudentName varchar(30), ExecuteTime real, Status varchar(30), Reason varchar(30), DeliveryTime varchar(30))";
    q.exec(newQuizTable);

    QStringList names = getNames();
    for(int x = 0; x < names.size(); x++)
    {
        QString insert = "INSERT INTO " + quizName + " (StudentName) VALUES ('" + names[x] + "')";
        q.exec(insert);
    }

    QString setDefaults = "UPDATE " + quizName + " SET ExecuteTime=0.00, Status='FAIL', Reason='Did Not Submit', DeliveryTime='0:00'";
    q.exec(setDefaults);
    for (int i =0; i < quizVector.size(); i++)
    {
        qDebug() << quizVector[i].getFailReason();
        qDebug() << quizVector[i].getName();
        qDebug() << quizVector[i].getRunTimeString();
        qDebug() << quizVector[i].getStatus();
        qDebug() << quizVector[i].getTimeString();

        QString updateStudent = "UPDATE " + quizName + " SET ExecuteTime='" + quizVector[i].getRunTimeString() + "', Status='" + quizVector[i].getStatus() + "', Reason='" + quizVector[i].getFailReason() + "', DeliveryTime='" + quizVector[i].getTimeString() +"' WHERE studentname='" + quizVector[i].getName() +"'";
        q.exec(updateStudent);
    }

}
Ejemplo n.º 13
0
/******************************
daCapo()
Start the game, and it has to be called
if you want to start a new game.
It contains 2 functions: inizio() and getNames()

Entering parameters:
   pedine: The structs containing all pawn data
    board: bidimensional array of struct puntators, with all the information
           about the chessboard and the position of every pawn
    name1: player 1 name's
    name2: player 2 name's

Returned value: none
********************************/
void daCapo(pedina *pedine, pedina *board[8][8], char *name1, char *name2, char *name, int *numero_celle)
{
	*numero_celle=0;
	inizio(pedine, board);
	getNames(name1, name2);
	name=name1;
	return;
}
Ejemplo n.º 14
0
void Tobias::solve( size_t maxStudentsStart ) {
	//for( size_t maxStudents = getNames().size() / 4; maxStudents <= getNames().size(); maxStudents++ ) {
	for( size_t maxStudents = maxStudentsStart; maxStudents <= getNames().size(); maxStudents++ ) {
		std::clog << "max = " << maxStudents << "..." << std::endl;
		if( solve( maxStudents, 0, 0 ) ) {
			std::clog << "Found solution for max = " << maxStudents << "!" << std::endl;
			break;
		}
	}
}
Ejemplo n.º 15
0
/**
 * If it is a group it is unrolled and each member added
 * @param workspace A pointer to the workspace to add
 */
void GroupWorkspaces::addToGroup(const API::Workspace_sptr &workspace) {
  auto localGroup = boost::dynamic_pointer_cast<WorkspaceGroup>(workspace);
  if (localGroup) {
    addToGroup(localGroup->getNames());
    // Remove the group from the ADS
    AnalysisDataService::Instance().remove(workspace->name());
  } else {
    m_group->addWorkspace(workspace);
  }
}
Ejemplo n.º 16
0
 /**
  * Get the maximum character length of a car type when printing on a
  * manifest or switch list. Car subtypes or characters after the "-" are
  * ignored.
  *
  * @return the maximum character length of a car type
  */
 /*public*/ int CarTypes::getMaxNameLength() {
     if (maxNameLengthSubType == 0) {
         QString maxName = "";
         maxNameLengthSubType = MIN_NAME_LENGTH;
         foreach (QString name, getNames()) {
             QStringList subString = name.split("-");
             if (subString[0].length() > maxNameLengthSubType) {
                 maxName = name;
                 maxNameLengthSubType = subString[0].length();
             }
         }
Ejemplo n.º 17
0
void ConvFitModel::addSampleLogs() {
  AddSampleLogRunner addSampleLog(getResultWorkspace(), getResultGroup());
  addSampleLog("resolution_filename",
               boost::algorithm::join(getNames(m_resolution), ","), "String");

  if (m_temperature && m_temperature.get() != 0.0) {
    addSampleLog("temperature_correction", "true", "String");
    addSampleLog("temperature_value", std::to_string(m_temperature.get()),
                 "Number");
  }
}
Ejemplo n.º 18
0
//----------------------------------------------------------------------------
MvLog::MvLog(const QualifiedName *tableName,
	     const ItemExpr *columnNames,
	     ItemExpr *rangeBegin,
	     ItemExpr *rangeEnd,
	     CollHeap *oHeap)
  : BinderOnlyNode(REL_MVLOG, oHeap),
    tableName_  (tableName),
    pColumnNamesItem_(columnNames),
    pBeginRange_ (rangeBegin),
    pEndRange_   (rangeEnd),
    isRangePartitioned_(TRUE),
    pBeginRangeExprList_(pBeginRange_, oHeap),
    pEndRangeExprList_(pEndRange_, oHeap),
    pBindWA_	 (NULL),
    ciBoundries_(oHeap),
    tupleListPhase1CorrName_(getNames().getTupleListRoot1(), oHeap),
    tupleListPhase2CorrName_(getNames().getTupleListRoot2(), oHeap),
    tupleListPhase3CorrName_(getNames().getTupleListName(), oHeap), 
    tupleListCorrName_(getNames().getTupleListName(), oHeap),
    first1NodeCorrName_(getNames().getGetFirstRoot(), oHeap),
    emptyCorrName_("", oHeap),
    pRelevantCiPositionsList_(oHeap),
    mvLogColNamesList_(oHeap),
    baseTableCiNamesList_(oHeap),
    nonCiColsNamesList_(oHeap),
    nonCiColsExprList_(oHeap),
    beginColNamesList_(oHeap),
    endColNamesList_(oHeap),
    first1ColNamesList_(oHeap),
    brColNamesList_(oHeap),
    erColNamesList_(oHeap),
    colsMinDefualtValList_(oHeap),
    colsMaxDefualtValList_(oHeap),
    pDirectionVector_(NULL),
    pNaTable_(NULL),
    heap_(oHeap)
{
}
Ejemplo n.º 19
0
std::string Pothos::Topology::queryJSONStats(void)
{
    Poco::JSON::Object::Ptr stats(new Poco::JSON::Object());

    //query each block's work stats and key it with the UID
    std::vector<std::shared_future<Poco::JSON::Object::Ptr>> results;
    for (const auto &block : getObjSetFromFlowList(_impl->flows))
    {
        results.push_back(std::async(std::launch::async, queryWorkStats, block));
    }

    //wait on the futures and record to the object
    for (const auto &result : results)
    {
        const auto workStats = result.get();
        std::vector<std::string> names; workStats->getNames(names);
        for (const auto &name : names) stats->set(name, workStats->getObject(name));
    }

    //use flat topology to get hierarchical block names
    const auto flatTopologyObj = parseJSONStr(this->dumpJSON());
    const auto flatTopologyBlocks = flatTopologyObj->getObject("blocks");
    std::vector<std::string> names; flatTopologyBlocks->getNames(names);
    for (const auto &name : names)
    {
        if (not stats->has(name)) continue;
        assert(stats->getObject(name));
        const auto topologObj = flatTopologyBlocks->getObject(name);
        assert(topologObj);
        const auto blockName = topologObj->getValue<std::string>("name");
        stats->getObject(name)->set("blockName", blockName);
    }

    //return the string-formatted result
    std::stringstream ss; stats->stringify(ss, 4);
    return ss.str();
}
Ejemplo n.º 20
0
QZFileInfo::QZFileInfo(QString str)
{
  QCString  zname, sname;
  ZEntry *entry=NULL;

  m_type = getNames(str, zname, sname, &entry);
  if (m_type==QZF_NONE) return;

  if (m_type&QZF_ZIP) {
    m_dir.z = entry;
    m_dir.z->grab();
  } else {
    m_dir.q = new QFileInfo(str);
  }
}
Ejemplo n.º 21
0
bool UniPAX::Provenance::merge(Provenance& object)
{
	{
		std::set<UniPAX::XrefPtr> tmp(getXrefs().begin(), getXrefs().end());
		for (std::vector<UniPAX::XrefPtr>::iterator it = object.getXrefs().begin(); it != object.getXrefs().end(); it++)
		{
			if (*it != 0)
			{
				tmp.insert(*it);
			}
		}
		getXrefs().assign(tmp.begin(), tmp.end());
	}
	{
		std::set<std::string> tmp(getNames().begin(), getNames().end());
		for (std::vector<std::string>::iterator it = object.getNames().begin(); it != object.getNames().end(); it++)
		{
			tmp.insert(*it);
		}
		if (!object.getStandardName().empty())
		{
			if (getStandardName().empty())
				setStandardName(object.getStandardName());
			tmp.insert(object.getStandardName());
		}
		if (!object.getDisplayName().empty())
		{
			if (getDisplayName().empty())
				setDisplayName(object.getStandardName());
			tmp.insert(object.getDisplayName());
		}
		getNames().assign(tmp.begin(), tmp.end());
	}

	return UniPAX::UtilityClass::merge(object);
}
void getFighterStats( void ){
 
        char fighterOne[ BUF_SIZE ] = { '\0' }; /* Input - first fighter name */
        char fighterTwo[ BUF_SIZE ] = { '\0' }; /* Input - second fighter name */
        int timesGetNamesCalled = 0; /* counter for how many fighters have ben entered */
        int wins; /* Input - how many wins the fighter has */
        int losses; /* Input - how many losses the fighter has */
        double totalFights; /* Input - the total amount of fights the fighter has */
        double winPercentageOne; /* Output - the win percentage of the first fighter */
        double winPercentageTwo; /* Output - the win percentage of the second fighter */
        double fighterOneKOChance; /* Input - the ko chance of the first fighter */
        double fighterTwoKOChance; /* Input - the ko chance of the second fighter */
        double fighterOneSubChance; /* Input - the submission chance of the first fighter */
        double fighterTwoSubChance; /* Input - the submission chance of the second fighter */
        int favoredFighter; /* Input - the fighter who is favored */
        double oddsOfWinning; /* Output - the fighters chance to win */
        
        
        getNames( fighterOne, &timesGetNamesCalled ); /* get first fighter Ones name */
        getNames( fighterTwo, &timesGetNamesCalled ); /* get second fighter Twos name */
        
        getRecord( fighterOne, &wins, &losses ); /* gets fighter Ones record */
        winPercentageOne = getWinPercentage( &wins, &losses, &totalFights ); /* gets fighter Ones win percentage */
        fighterOneKOChance = getKOChance( fighterOne, &totalFights ); /* gets fighter Ones ko chance */
        fighterOneSubChance = getSubChance( fighterOne, &totalFights ); /* gets fighter Ones submission chance */
        
        getRecord( fighterTwo, &wins, &losses ); /* gets fighter Twos record */
        winPercentageTwo = getWinPercentage( &wins, &losses, &totalFights ); /* gets fighter Twos win percentage */
        fighterTwoKOChance = getKOChance( fighterTwo, &totalFights ); /* gets fighter Twos ko chance */
        fighterTwoSubChance = getSubChance( fighterTwo, &totalFights ); /* gets fighter Twos submission chance */
        
        oddsOfWinning = getoddsOfWinning( fighterOne, fighterTwo, &favoredFighter  ); /* gets the favored fighter and the odds */
        
        /* simulates the fight */
        simulateFight( fighterOne, fighterTwo, winPercentageOne, winPercentageTwo, fighterOneKOChance, fighterTwoKOChance, fighterOneSubChance, fighterTwoSubChance, &favoredFighter, oddsOfWinning );
}
Ejemplo n.º 23
0
int A_getnames(int tree, char **nameptr, int *numvar, int maxptr)
{
   int             i;
   symbol        **root;

   i = 0;
   *numvar = 0;
   if ( (root = getTreeRoot(getRoot(tree))) )
   {
      getNames(*root, nameptr, numvar, maxptr, &i);
   }
   else
      return (-1);		/* tree doesn't exist */
   return (OK);
}
Ejemplo n.º 24
0
size_t Tobias::avaiableSlots() const {
	size_t available = 4;
	for( size_t i = 0; i < slots(); i++ ) {
		for( size_t s = 0; s < getNames().size(); s++ ) {
			if( schedule.at( s * slots() + i ) ) {
				available--;
				break;
			}
		}
		if( available == 0 ) {
			break;
		}
	}
	//std::clog << "avail: " << available << std::endl;
	return available;
}
Ejemplo n.º 25
0
ForwMachine::ForwMachine(const NEW_CTL_MSG * mp,
                         char * forward,
                         char * _forwardMethod,
                         int c_id_num) : pid(0), caller_id_num(c_id_num)
{
    // Store callee as 'local_user'
    strncpy(local_user, mp->r_name, NEW_NAME_SIZE);
    // -1 is to be sure to have a '\0' at the end
    // Store caller's name
    strncpy(caller_username, mp->l_name, NEW_NAME_SIZE);
    // Store caller's protocol
    callerProtocol = (mp->vers==0) ? talkProtocol : ntalkProtocol;

    // Forward method : from string to enumerate
    if (!strcmp(_forwardMethod,"FWA"))
        forwardMethod = FWA;
    else if (!strcmp(_forwardMethod,"FWR"))
        forwardMethod = FWR;
    else if (!strcmp(_forwardMethod,"FWT"))
        forwardMethod = FWT;
    else syslog(LOG_ERR,"Unknown forward method : %s",_forwardMethod);

    // Get answerer machine address and username
    if (getNames(forward)) {
        message("-- Talking to %s",answ_user);
        message("-- On %s",answ_machine_name);
        // Create a new talk connection, to the answerer ...
        tcAnsw = new TalkConnection(answ_machine_addr,
                                    answ_user,
                                    // from caller's username
                                    (char *) mp->l_name,
                                    noProtocol); // to be checked
        tcAnsw->open_sockets();
        // and from here if FWT or ...
        if (forwardMethod != FWT) {
            //from the caller if FWA or FWR
            tcAnsw->set_addr(&mp->addr);
            // but WE DO NOT CHANGE THE ctl_addr, we want the response !!
        }
        // Store caller's ctl_addr (to respond to its announce)
        caller_ctl_addr = mp->ctl_addr;
        // And his machine addr (to send a LOOK_UP)
        caller_machine_addr = ((struct sockaddr_in * )(&mp->ctl_addr))->sin_addr;
    }
}
Ejemplo n.º 26
0
void getNames() {

    printf("Anzahl der Spieler eingeben (max. %i): ", maxPlayersAmount);
    AmountOfPlayers = scannerInt();
    createPlayers(AmountOfPlayers);

    if (AmountOfPlayers >= 1 && AmountOfPlayers <= maxPlayersAmount) {
        printf("\nBitte Namen eingeben...\n\n");

        for (int i = 0;
             i < AmountOfPlayers; i++) {        //checking for the correctness of input and saving the names of players
            printf("Spieler %i: ", i + 1);
            scanf("%29s", &players[i].name[0]);
        }
    } else {
        printf("\nDie einzugebende Zahl muss eine natuerliche Zahl im Bereich von 1 bis %i sein!\n\n",
               maxPlayersAmount);
        getNames();
    }
}
Ejemplo n.º 27
0
bool
QZDir::cd(QString str)
{
  if (updateZ()==QZF_NONE) return false;

  if (str.left(2)=="..") {
    if (!this->cdUp()) return false;
    if (str.length()>3 && str.at(2)=='/')
      return this->cd(str.mid(3));
    return true;
  }

  if (m_type&QZF_ZIP) {
    QCString spath;
    toMB(spath, str, "euc-kr");

    ZEntry *entry = m_dir.z->findByName(spath);
    if (entry==NULL || !entry->isDir()){
      return false;
    }

    m_dir.z = (ZDirEntry*)entry;
    return true;
  } else {
    QString c_path;
    c_path = m_dir.q->path();
    c_path += "/" + str;

    ZEntry *entry;
    QCString zname, sname;
    int my_type = getNames(c_path, zname, sname, &entry);
    if (!(my_type&QZF_DIR))
      return false;
    if (my_type==QZF_DIR)
      return m_dir.q->cd(str);
    m_type = my_type;
    entry->grab();
    m_dir.z = (ZDirEntry*)entry;
    return true;
  }
}
Ejemplo n.º 28
0
// Sets the properties of the merged object
properties* SourceMerger::setProperties(std::vector<std::pair<properties::tagType, properties::iterator> > tags,
                                       map<string, streamRecord*>& outStreamRecords,
                                       vector<map<string, streamRecord*> >& inStreamRecords,
                                       properties* props) {
  if(props==NULL) props = new properties();
  
  map<string, string> pMap;
  properties::tagType type = streamRecord::getTagType(tags); 
  if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging Scope!"<<endl; exit(-1); }
  if(type==properties::enterTag) {
    assert(tags.size()>0);

    vector<string> names = getNames(tags); assert(allSame<string>(names));
    assert(*names.begin() == "source");
    
    vector<long> numRegionsV = str2int(getValues(tags, "numRegions"));
    assert(allSame<long>(numRegionsV));
    int numRegions = *numRegionsV.begin();
    pMap["numRegions"] = txt()<<numRegions;
    
    for(int i=0; i<numRegions; i++) {
      vector<string> fName = getValues(tags, txt()<<"fName_"<<i);
      assert(allSame<string>(fName));
      pMap[txt()<<"fName_"<<i] = *fName.begin();

      vector<string> startLine = getValues(tags, txt()<<"startLine_"<<i);
      assert(allSame<string>(startLine));
      pMap[txt()<<"startLine_"<<i] = *startLine.begin();

      vector<string> endLine = getValues(tags, txt()<<"endLine_"<<i);
      assert(allSame<string>(endLine));
      pMap[txt()<<"endLine_"<<i] = *endLine.begin();
    }
    
    props->add("source", pMap);
  } else {
    props->add("source", pMap);
  }
  
  return props;
}
void
GUICompleteSchemeStorage::writeSettings(FXApp* app) {
    const std::vector<std::string>& names = getNames();
    app->reg().writeIntEntry("VisualizationSettings", "settingNo", (FXint) names.size() - myNumInitialSettings);
    size_t gidx = 0;
    for (std::vector<std::string>::const_iterator i = names.begin() + myNumInitialSettings; i != names.end(); ++i, ++gidx) {
        const GUIVisualizationSettings& item = mySettings.find(*i)->second;
        std::string sname = "visset#" + toString(gidx);

        app->reg().writeStringEntry("VisualizationSettings", sname.c_str(), item.name.c_str());
        OutputDevice_String dev;
        item.save(dev);
        std::string content = dev.getString();
        app->reg().writeIntEntry(sname.c_str(), "xmlSize", (FXint)(content.size()));
        const unsigned maxSize = 1500; // this is a fox limitation for registry entries
        for (unsigned int i = 0; i < content.size(); i += maxSize) {
            const std::string b = content.substr(i, maxSize);
            app->reg().writeStringEntry(sname.c_str(), ("xml" + toString(i / maxSize)).c_str(), b.c_str());
        }
    }
}
Ejemplo n.º 30
0
// Sets the properties of the merged object
properties* CommBarMerger::setProperties(std::vector<std::pair<properties::tagType, properties::iterator> > tags,
                                       map<string, streamRecord*>& outStreamRecords,
                                       vector<map<string, streamRecord*> >& inStreamRecords,
                                       properties* props) {
  if(props==NULL) props = new properties();
  
  map<string, string> pMap;
  properties::tagType type = streamRecord::getTagType(tags); 
  if(type==properties::unknownTag) { cerr << "ERROR: inconsistent tag types when merging CommRecv!"<<endl; exit(-1); }
  if(type==properties::enterTag) {
    assert(tags.size()>0);

    vector<string> names = getNames(tags); assert(allSame<string>(names));
    assert(*names.begin() == "commBar");

    props->add("commBar", pMap);
  } else {
    props->add("commBar", pMap);
  }
  
  return props;
}