Esempio n. 1
0
bool Message::valid() const
{
    return isMember("type") 
        && isMember("id") 
        && isMember("from") 
        && (*this)["from"].isString();
}
Esempio n. 2
0
Event::Event(const json::Value& root) :
    Message(root)
{
    if (!isMember("type"))
        setType("event");
    if (!isMember("time"))
        setTime(::time(0));
}
Esempio n. 3
0
Message::Message(const json::Value& root) :
    json::Value(root)
{
    if (!isMember("id"))
        (*this)["id"] = util::randomString(16);
    if (!isMember("type"))
        (*this)["type"] = "message";
}
Esempio n. 4
0
Actor* ActorSet::getPtr(OBJECT_ID id)
{
	if(isMember(id))
		return(find(id)->second);
	else
		return 0;
}
Esempio n. 5
0
        void SymTable::insert(Symbol *s, bool save){

            if (s==NULL) return;
            std::string lowsymbol(s->getname()); 
            toLower(lowsymbol);
            if (!isMember(lowsymbol)) {
            
              (*table)[lowsymbol] = s;
              if(save){
                s->offset = totaloffset;
                totaloffset += s->ntype->size;
              }
              return;
            }  
            
            Symbol *sym = (*table)[lowsymbol];
            
            if((s->line<sym->line) ||
              ((s->line==sym->line)&&(s->column<sym->column)))
              errorlog->addError(5,sym->line,sym->column,&sym->name);
            else
              errorlog->addError(5,s->line,s->column, &s->name);              
            

        }
// guildtoggleabbreviation() Toggles the settings for showing or not showing the guild title
// Informs player about his change
void cGuildStone::ToggleAbbreviation(UOXSOCKET s)
{
	P_CHAR pc = currchar[s];

	if (!isMember(pc)) 
	{
		sysmessage(s, "you are not a guild member");
		return;
	}

	if (this->guildType != cGuildStone::standard)		// Check for Order/Chaos
	{
		sysmessage(s, "You are in an Order/Chaos guild, you cannot toggle your title.");
	}
	else
	{
		if (!pc->guildtoggle())									// If set to Off then
		{
			pc->setGuildtoggle(true);									// Turn it On
			sysmessage(s, "You toggled your abbreviation on.");	// Tell player about the change
		}
		else													// Otherwise
		{
			pc->setGuildtoggle(false);					// Turn if Off
			sysmessage(s, "You toggled your abbreviation off.");	// And tell him also
		}
	}
	this->Menu(s, 1);										// Send him back to the menu
	return;
}
Esempio n. 7
0
void TypedefDeclaration::toDebug()
{
    //printf("TypedefDeclaration::toDebug('%s')\n", toChars());

    assert(config.fulltypes >= CV4);

    // If it is a member, it is handled by cvMember()
    if (!isMember())
    {
        if (basetype->ty == Ttuple)
            return;

        const char *id = toPrettyChars();
        idx_t typidx = cv4_typidx(basetype->toCtype());
        if (config.fulltypes == CV8)
            cv8_udt(id, typidx);
        else
        {
            unsigned len = strlen(id);
            unsigned char *debsym = (unsigned char *) alloca(39 + IDOHD + len);

            // Output a 'user-defined type' for the tag name
            TOWORD(debsym + 2,S_UDT);
            TOIDX(debsym + 4,typidx);
            unsigned length = 2 + 2 + cgcv.sz_idx;
            length += cv_namestring(debsym + length,id);
            TOWORD(debsym,length - 2);

            assert(length <= 40 + len);
            objmod->write_bytes(SegData[DEBSYM],length,debsym);
        }
    }
}
Esempio n. 8
0
void deleteFromSet(Set set, int value) {
	int index = (value / 32);
	int position = (value % 32);
	if(isMember(set, value) >= 1) {
		set[index] &= ~(1 << position);
	}
}
Esempio n. 9
0
void EnumDeclaration::toDebug()
{
    //printf("EnumDeclaration::toDebug('%s')\n", toChars());

    assert(config.fulltypes >= CV4);

    // If it is a member, it is handled by cvMember()
    if (!isMember())
    {
	unsigned length;
	const char *id = toPrettyChars();
	idx_t typidx = cv4_Denum(this);
	unsigned len = strlen(id);
	unsigned char *debsym = (unsigned char *) alloca(39 + IDOHD + len);

	// Output a 'user-defined type' for the tag name
	TOWORD(debsym + 2,S_UDT);
	TOIDX(debsym + 4,typidx);
	length = 2 + 2 + cgcv.sz_idx;
	length += cv_namestring(debsym + length,id);
	TOWORD(debsym,length - 2);

	assert(length <= 40 + len);
	obj_write_bytes(SegData[DEBSYM],length,debsym);
    }
}
Esempio n. 10
0
void add2Set(Set set, int value) {
	int index = (value / 32);
	int position = (value % 32);
	if(isMember(set, value) == 0) {
		set[index] |= (1 << position);
	}
}
Esempio n. 11
0
ActorPtr ActorSet::getPtr(OBJECT_ID id)
{
	if(isMember(id))
		return(actors.find(id)->second);
	else
		return ActorPtr();
}
// Descr: tests the isMember function
TEST(GeometryTest, IsMember)
{

    vector<unsigned long> section;

    section.push_back(1);
    section.push_back(2);
    section.push_back(3);
    section.push_back(4);

	EXPECT_TRUE(isMember(section, 1) );
	EXPECT_TRUE(isMember(section, 2) );
	EXPECT_TRUE(isMember(section, 3) );
	EXPECT_TRUE(isMember(section, 4) );
	EXPECT_TRUE(!isMember(section, 5));

}
Esempio n. 13
0
int nameIsMember(Set set, char *str) {
	int searchresult = binarySearch(names, str, 0, 320);
	int result = isMember(set, searchresult);
	if(result < 0)
		return 0;
	else
		return result;
}
Esempio n. 14
0
void testIsMember()
{
    cout<<"Testing IsMember"<<endl;
    vector<unsigned long> section;

    section.push_back(1);
    section.push_back(2);
    section.push_back(3);
    section.push_back(4);

    assert(isMember(section, 1));
    assert(isMember(section, 2));
    assert(isMember(section, 3));
    assert(isMember(section, 4));
    assert(!isMember(section, 5));

    cout<<"Testing IsMember Completed\n"<<endl;
}
Esempio n. 15
0
bool Configuration::getRaw(const std::string& key, std::string& value) const
{	
	Mutex::ScopedLock lock(_mutex); 
	
	if (!isMember(key))
		return false;

	value = (*this)[key].asString();
	return true;
}
Esempio n. 16
0
void ActorSet::moveObject(ActorSet &dest, OBJECT_ID id)
{
	ASSERT(isMember(id), "The object is not a member of this set");
	ASSERT(!dest.isMember(id), "The object is already a member of the other set");

	// Add it to the other set
	dest.insert(  make_pair(id, toActor(*find(id)))  );

	// Remove it from this set
	erase(find(id));
}
Esempio n. 17
0
  Boolean noteMembership(unsigned ssrc, unsigned curTimeCount) {
    Boolean isNew = !isMember(ssrc);

    if (isNew) {
      ++fNumMembers;
    }

    // Record the current time, so we can age stale members
    fTable->Add((char*)(long)ssrc, (void*)(long)curTimeCount);

    return isNew;
  }
Esempio n. 18
0
	void Group::updateCount(QueueManager* qman)
	{
		total = running = 0;
		for(QueueManager::iterator j = qman->begin(); j != qman->end(); j++)
		{
			if(isMember(*j))
			{
				total++;
				if((*j)->getStats().running)
					running++;
			}
		}
	}
Esempio n. 19
0
File: Set.cpp Progetto: a-oleksa/set
// complement of Set
Set Set::operator ~( )
{
	Set tmp;

	for( int  i = 0; i < MaxSize; i++ )
	{
		
		if( !isMember(i) )
			tmp = tmp +i;
	}

	return tmp;
}
Esempio n. 20
0
void Guild::addMember(GuildMember *member)
{
    if (member->mGuild > 0 && member->mGuild != this)
    {
        throw "Member in another guild!";
    }

    if (!isMember(member))
    {
        mMembers.push_back(member);
        member->mGuild = this;
    }
}
Esempio n. 21
0
void GeneralizedTransform::nest(Json::Value const &transform) {
    if (!transform.isObject()) {
        /// We only nest objects, sorry.
        return;
    }
    auto currentPtr = &transform;
    while (currentPtr->isObject() &&
            currentPtr->isMember(routing_keys::child())) {
        auto const &current = *currentPtr;
        pushLevelBack(current);
        currentPtr = &(current[routing_keys::child()]);
    }
}
Esempio n. 22
0
void FilesystemSection::onFileEdited( const FilePath& path )
{
   if ( !isMember( path ) )
   {
      return;
   }

   // pass the message on to the listeners
   uint count = m_listeners.size();
   for ( uint i = 0; i < count; ++i )
   {
      m_listeners[i]->onFileEdited( path );
   }
}
Esempio n. 23
0
void FilesystemSection::onDirRemoved( const FilePath& dir )
{
   if ( !isMember( dir ) )
   {
      return;
   }

   // pass the message on to the listeners
   uint count = m_listeners.size();
   for ( uint i = 0; i < count; ++i )
   {
      m_listeners[i]->onDirRemoved( dir );
   }
}
Esempio n. 24
0
IResponse *GroupsService::getIsMember(IRequest *req)
{

         QVariantMap res;

         QString user_id = req->parameterValue("user_id");
         QString group_id = req->parameterValue("group_id");

         if(isMember(user_id.toUInt(), group_id.toUInt()))
             res.insert("member","1");
         else
             res.insert("member","0");

         return req->response(QVariant(res),IResponse::OK);
}
Esempio n. 25
0
long MoverGroup::setPoint (MoverPtr mover) {

	if (isMember(mover)) {
#ifdef USE_IFACE
		if (pointHandle)
			theInterface->setPoint(pointHandle, false);
#endif
		pointWID = mover->getWatchID();
#ifdef USE_IFACE
		theInterface->setPoint(mover->getPartId(), true);
#endif
	}

	return(NO_ERR);
}
Esempio n. 26
0
void Fireteam::removeUnit(BWAPI::Unit* unit) {
	if (isMember(unit)) {
		units.erase(unit);
		unitCount--;
		formation.emptyPositions.push(formation.positionMap[unit]);
		formation.positionMap.erase(unit);
		if(unitCount == 0) {
			destroyed = true;
		} else {
			destroyed = false;
		}
	} else {
		BWAPI::Broodwar->printf("Unit to be removed is not a member of this team.");
		BWAPI::Broodwar->pauseGame();
	}
}// Removes unit from team 
Esempio n. 27
0
bool baseStructureParser<streamT>::readUntil(bool inTerm, const char* termChars, int numTermChars,
        char& termHit, string& result) {
    result = "";
    // Outer loop that keeps reading more chunks of size bufSize from the file
    while(1) {
        //cout << "        ru: bufIdx="<<bufIdx<<", bufSize="<<bufSize<<endl;
        // Iterate through the rest of the file looking for terminator chars
        while(bufIdx<dataInBuf) {
            for(int i=0; i<numTermChars; i++) {
                // If the current character in buf is a terminator, return the result
                if(isMember(buf[bufIdx], termChars, numTermChars)) {
                    if(inTerm) {
                        termHit=buf[bufIdx];
                        return true;
                    }
                } else {
                    if(!inTerm) {
                        termHit=buf[bufIdx];
                        return true;
                    }
                }
            }
            // If the current character in buf is a terminator, return the result
            if(!inTerm) {
                termHit=buf[bufIdx];
                //nextChar();
                return true;
            }
            // If the character is not a terminator, append it to ret
            result += buf[bufIdx];
            bufIdx++;
        }

        //cout << "        ru: feof(f)="<<feof(f)<<", ferror(f)="<<ferror(f)<<endl;

        // If we've reached the end of the file, return unsuccessfuly
        if(streamEnd()) return false;

        // If we've encountered an error, yell
        if(streamError()) {
            fprintf(stderr, "ERROR reading file!");
//      exit(-1);
        }

        nextChar();
    }
}
Esempio n. 28
0
Content ONCatEntity::getNestedContent(const Content &content,
                                      const std::string &path) const {
  const auto pathTokens =
      StringTokenizer(path, ".", Mantid::Kernel::StringTokenizer::TOK_TRIM);

  auto currentNode = content;

  // Use the path tokens to drill down through the JSON nodes.
  for (const auto &pathToken : pathTokens) {
    if (!currentNode.isMember(pathToken)) {
      throw ContentError("");
    }
    currentNode = currentNode[pathToken];
  }

  return currentNode;
}
Esempio n. 29
0
colors_t colors_t_of_json(const Json::Value &value) {
    colors_t colors;
    for (auto it = value.begin(); it != value.end(); ++it) {
        auto key = key_of_value(color_names, it.key().asCString(),
                                colors_t::Normal, strcmp);
        auto extract_color = [&](const char *type) -> QColor {
            QColor ret;
            auto value = *it;
            if (value.isMember(type) && value[type].isString()) {
                ret.setNamedColor(value[type].asCString());
            }
            return ret;
        };
        colors[key].background = extract_color("background");
        colors[key].foreground = extract_color("foreground");
    }
    return colors;
}
Esempio n. 30
0
//Recommendation for 'Bottom10'
void VendeMaisMais::recommendProductBottom10() const {
    /* ********************************************************
    ********BOTTOM10 CLIENTS DATA INITIALIZATION***************/

    //Calculating Bottom10 clients (first ten clients in sorted vector)
    vector<Client> sortedClients = clientsVector;
    sort(sortedClients.begin(), sortedClients.end(), compareClients);

    //Client to Products matrix for Bottom10 clients
    vector<vector<bool>> bottom10matrix(10, vector<bool>(productsVector.size(),false));

    //Int to int map to associate each Bottom10 client's ID to his position in the matrix
    map<int,int> bottom10IdtoIndex;
    for(int counter = 0; counter < 10; counter++)
        bottom10IdtoIndex.insert(pair<int,int>(sortedClients.at(counter).getId(), counter));

    //Changing every bought product by each Bottom10 client boolean to #t
    for(map<int,int>::const_iterator id_it = transactionIdx.begin(); id_it != transactionIdx.end(); id_it++){
            map<int,int>::const_iterator idFinder = bottom10IdtoIndex.find(id_it->first);
            if(idFinder != bottom10IdtoIndex.end()) { //Means that current transaction was made by a Bottom10 client, so good to go
                int clientIndex = (bottom10IdtoIndex.find(id_it->first))->second;
                vector<string> products = transactionsVector.at(id_it->second).getProductsBought(); //Products bought on current transaction
                for(int productindex = 0; productindex < products.size(); productindex++){
                    int productIndexInMatrix = (productIdx.find(products.at(productindex)))->second;
                    bottom10matrix.at(clientIndex).at(productIndexInMatrix) = true;
                }
            }
    }

    /*
    //PRINTING TEST
    for(int i = 0; i < bottom10matrix.size(); i++){
        cout << "Index " << i << " - ";
        for(int j = 0; j < productsVector.size(); j++)
            cout << bottom10matrix.at(i).at(j) << " ";
        cout << endl;
    }
    */


    //Calculating vector that holds indexes of common products from Bottom10 clients
    vector<int> indexesOfCommonBottom10Products;
    for(int productindex = 0; productindex < productsVector.size(); productindex++){
        bool commonProduct = true;
        for(int clientindex = 0; clientindex < bottom10matrix.size(); clientindex++){
            if(!bottom10matrix.at(clientindex).at(productindex)) { //One client has not bought the product, so it is not common
                commonProduct = false;
                break;
            }
        }

        if(commonProduct)
            indexesOfCommonBottom10Products.push_back(productindex);
    }

    /* ********************************************************
    ********OTHER CLIENTS DATA INITIALIZATION***************/

    map<int,int> otherClientsIdtoIndex; //int to int map that translates other clients' ID to their position in the matrix used
    /*vector that contains every ID that made at least one transaction and respective initialization
    Note that simply getting the IDs from current clients is not good practice,
    since it is relatively likely that there are clients with no transactions (who are of no use here) or transactions from clients who have been removed*/

    vector<int> idsThatMadeTransactions;
    //vector<Transaction> otherClientsTransactions; //Vector that will store transactions that are not from Bottom10 clients
    for(int index = 0; index < transactionsVector.size(); index++){
        bool alreadyInTheMap = isMember(idsThatMadeTransactions, transactionsVector.at(index).getClientId());
        map<int,int>::const_iterator id_it = bottom10IdtoIndex.find(transactionsVector.at(index).getClientId());
        bool notBottom10;
        if(id_it == bottom10IdtoIndex.end()) //Current ID is not from a Bottom10 client
            notBottom10 = true;
        else
            notBottom10 = false;
        if(!alreadyInTheMap && notBottom10){
            idsThatMadeTransactions.push_back(transactionsVector.at(index).getClientId());
            //otherClientsTransactions.push_back(transactionsVector.at(index));
        }
    }

    //Sorting makes it easier
    sort(idsThatMadeTransactions.begin(), idsThatMadeTransactions.end());

    //Initializing int to int client ID to matrix position map
    for(int counter = 0; counter < idsThatMadeTransactions.size(); counter++)
        otherClientsIdtoIndex.insert(pair<int,int>(idsThatMadeTransactions.at(counter), counter));

    /*
    //PRINTING TEST
    for(map<int,int>::const_iterator p = otherClientsIdtoIndex.begin(); p != otherClientsIdtoIndex.end(); p++)
        cout << p->first << " - " << p->second << endl;
    */

    //Client to product matrix for other clients
    vector<vector<bool>> otherClientsMatrix(otherClientsIdtoIndex.size(), vector<bool>(productsVector.size(),false));

    //Changing every bought product by each "other client" boolean to #t
    for(map<int,int>::const_iterator id_it = transactionIdx.begin(); id_it != transactionIdx.end(); id_it++){
            map<int,int>::const_iterator idFinder = otherClientsIdtoIndex.find(id_it->first);
            if(idFinder != otherClientsIdtoIndex.end()) { //Means that current transaction was made by a "other client", so good to go
                int clientIndex = (otherClientsIdtoIndex.find(id_it->first))->second;
                vector<string> products = transactionsVector.at(id_it->second).getProductsBought(); //Products bought on current transaction
                for(int productindex = 0; productindex < products.size(); productindex++){
                    int productIndexInMatrix = (productIdx.find(products.at(productindex)))->second;
                    otherClientsMatrix.at(clientIndex).at(productIndexInMatrix) = true;
                }
            }
    }

    /*
    //PRINTING TEST
    cout << endl;
    for(int i = 0; i < otherClientsMatrix.size(); i++){
        cout << "Index " << i << " - ";
        for(int j = 0; j < productsVector.size(); j++)
            cout << otherClientsMatrix.at(i).at(j) << " ";
        cout << endl;
    }
    */


    //New matrix that copies from "other clients" matrix every client (and respective information) that has at least bought every common-to-all-Bottom10 product
    vector<vector<bool>> interestingClients;
    for(int clientindex = 0; clientindex < otherClientsMatrix.size(); clientindex++){
        bool interestingClient = true;
        for(int productindex = 0; productindex < indexesOfCommonBottom10Products.size(); productindex++){
            int currentProductIndex = indexesOfCommonBottom10Products.at(productindex);
            if(!otherClientsMatrix.at(clientindex).at(currentProductIndex)){ //If current client failed to buy at least one of the common-to-all-Bottom10 products, then he is not interesting
                interestingClient = false;
                break;
            }
        }

        if(interestingClient)
            interestingClients.push_back(otherClientsMatrix.at(clientindex));
    }

    /*
    //PRINTING TEST
    cout << endl;
    for(int i = 0; i < interestingClients.size(); i++){
        cout << "Index " << i << " - ";
        for(int j = 0; j < productsVector.size(); j++)
            cout << interestingClients.at(i).at(j) << " ";
        cout << endl;
    }
    */


    //Pair vector that will hold a pair with each potential product to suggest and its number of occurrences in the interesting clients' matrix (serve as the "histogram" mentioned)
    vector<pair<string,int>> productAppearances;

    for(int productindex = 0; productindex < productsVector.size(); productindex++){
        bool commonProductToBottom10 = isMember(indexesOfCommonBottom10Products, productindex); //Current product is not one of the common to Bottom10 clients so it is a possibility for later suggestion
        if(!commonProductToBottom10){
            string currentProductName = productsVector.at(productindex).getName();
            int currentProductIndex = productIdx.find(currentProductName)->second;
            pair<string,int> currentP = make_pair(currentProductName, 0);
            for(int clientindex = 0; clientindex < interestingClients.size(); clientindex++){
                bool productBoughtByCurrentClient = interestingClients.at(clientindex).at(productindex);
                if(productBoughtByCurrentClient)
                    (currentP.second)++;

            }
            productAppearances.push_back(currentP);
        }
    }

    //Sorting so it is tested from the highest value to the lowest (note that comparePairs returns true if first is greater than second and not vice-versa like a normal sort)
    sort(productAppearances.begin(), productAppearances.end(), comparePairs);

    /*
    //PRINTING TEST
    for(int x = 0; x < productAppearances.size(); x++)
        cout << productAppearances.at(x).first << " - " << productAppearances.at(x).second << endl;
    */

    for(int mainindex = 0; mainindex < productAppearances.size(); mainindex++){
        int occurrencesOfProductOnBottom10 = 0;
        int productIndex = productIdx.find(productAppearances.at(mainindex).first)->second;
        for(int secondaryindex = 0; secondaryindex < bottom10matrix.size(); secondaryindex++){
            if(bottom10matrix.at(secondaryindex).at(productIndex))
                occurrencesOfProductOnBottom10++;
        }
        if(occurrencesOfProductOnBottom10 == 0){
            cout << endl << "Recommmending product for 'Bottom10' clients" << endl;
            cout << endl;
            cout << "The 'Bottom10' clients are likely to like " << productAppearances.at(mainindex).first << ", why not suggesting it to them?" << endl;
            cin.ignore(numeric_limits<int>::max(),'\n');
            cout << endl;
            pressToContinue();
            return; //Product suggested so the function is done
        }
    }

    //Loop that will only execute when in the potential products there is not at least one that was not bought by any of the Bottom10 clients
    int indexToPrint; //Holds the index of product to suggest to print when loop is done
    int minimumNumberOfOccurrencesOnBottom10 = numeric_limits<int>::max(); //Initial minimum number of occurrences is the highest integer value compiler can process
    for(int mainindex = 0; mainindex < productAppearances.size(); mainindex++){
        int occurrencesOfProductOnBottom10 = 0;
        int productIndex = productIdx.find(productAppearances.at(mainindex).first)->second;
        for(int secondaryindex = 0; secondaryindex < bottom10matrix.size(); secondaryindex++){
            if(bottom10matrix.at(secondaryindex).at(productIndex))
                occurrencesOfProductOnBottom10++;
        }
        if(occurrencesOfProductOnBottom10 < minimumNumberOfOccurrencesOnBottom10){
            minimumNumberOfOccurrencesOnBottom10 = occurrencesOfProductOnBottom10;
            indexToPrint = mainindex;
        }
    }

    cout << endl;
    cout << "The 'Bottom10' clients are likely to like " << productAppearances.at(indexToPrint).first << ", why not suggesting it to them?" << endl;
    cout << endl;
    pressToContinue();

}