Exemple #1
0
ImportInfo::ImportInfo( Dict & attrs ) : 
	attrs( attrs )
{
	Dict::iterator it = attrs.find( FROM );
	if ( it == attrs.end() ) {
		throw Mishap( "Missing attribute in import" ).culprit( "Attribute", FROM );
	}
	this->from = it->second;
	
	set< string > matches;
	set< string > intos;
	for (
		Dict::iterator it = attrs.begin();
		it != attrs.end();
		++it
	) {
		if ( it->first.compare( 0, MATCH_SIZE, MATCH ) == 0 ) {
			matches.insert( it->second );
		} else if ( it->first.compare( 0, INTO_SIZE, INTO ) == 0 ) {
			intos.insert( it->second );
		}
	}
	
	this->match_tags = fetchFacetSet( matches );
	this->into_tags = fetchFacetSet( intos );
}
TransactionType
transaction_type_from_verb(wxString const& p_phrase)
{
    typedef map<wxString, TransactionType> Dict;
    static Dict dict;
    static bool calculated_already = false;
    if (!calculated_already)
    {
        JEWEL_ASSERT (dict.empty());
        dict[expenditure_verb()] = TransactionType::expenditure;
        dict[revenue_verb()] = TransactionType::revenue;
        dict[balance_sheet_verb()] = TransactionType::balance_sheet;
        dict[envelope_verb()] = TransactionType::envelope;
        dict[generic_verb()] = TransactionType::generic;
        calculated_already = true;
    }
    JEWEL_ASSERT (!dict.empty());
    JEWEL_ASSERT
    (   dict.size() ==
        static_cast<Dict::size_type>(TransactionType::num_transaction_types)
    );
    Dict::const_iterator const it = dict.find(p_phrase);
    if (it == dict.end())
    {
        JEWEL_THROW
        (   InvalidTransactionTypeException,
            "wxString passed to transaction_type_from_verb does not "
            "correspond to any TransactionType."
        );
    }
    JEWEL_ASSERT (it != dict.end());
    return it->second;
}
Exemple #3
0
// ---- Split ----
int getWord(const char* begin, const char* findAfter, const Dict& dict) {
    while (*findAfter != '\0') {
        string s(begin, findAfter + 1);
        if (dict.find(s) != dict.end())
            return findAfter - begin + 1;
        ++findAfter;
    }

    return -1;
}
FusionOperator IFusionOperator::fromString(const std::string& type)
{
    typedef map<string, FusionOperator, pfs::utils::StringUnsensitiveComp> Dict;
    static Dict v =
            map_list_of
            ("debevec", DEBEVEC)
            ("robertson", ROBERTSON)
            ("robertson-auto", ROBERTSON_AUTO)
            ;

    Dict::const_iterator it = v.find(type);
    if (it != v.end())
    {
        return it->second;
    }
    return DEBEVEC;
}
Exemple #5
0
ResponseCurveType ResponseCurve::fromString(const std::string& type)
{
    typedef map<string, ResponseCurveType, pfs::utils::StringUnsensitiveComp> Dict;
    static Dict v =
            map_list_of
            ("log10", RESPONSE_LOG10)
            ("log", RESPONSE_LOG10)
            ("linear", RESPONSE_LINEAR)
            ("gamma", RESPONSE_GAMMA)
            ("srgb", RESPONSE_SRGB)
            ;

    Dict::const_iterator it = v.find(type);
    if ( it != v.end() )
    {
        return it->second;
    }
    return RESPONSE_LINEAR;
}
// *****************************************************************************
EntityPtrs Shotgun::entityFactoryFind(const std::string &entityType, 
                                      Dict &findMap,
                                      const int limit)
{
    EntityPtrs entities;

    // Find the registered functions for the given type of class.
    ClassRegistry::iterator foundRegistryIter = m_classRegistry.find(entityType);

    if (foundRegistryIter == m_classRegistry.end())
    {
        throw SgEntityNotRegisteredError(entityType);
    }

    // The set of registered functions 
    RegistryFuncs registryFuncs = (*foundRegistryIter).second;

    // ------------------------------------------------------------------------
    // If the given findMap already has a "return_fields", merge its contents 
    // with the poupulated default return Fields of the given entity type. 
    // Shotgun will ignore the duplicated fields when it returns the search result. 
    // To update the findMap's "return_fields", erase it first since the 
    // xmlrpc_c::value type can't be reassigned once it's been instantiated. 
    // ------------------------------------------------------------------------

    // Populate the default return fields and add the extra return fields
    // before passing them to the findMap
    List returnFields = (*(registryFuncs.defaultReturnFieldsFunc))();
    try
    {
        // Check to see if the findMap has "return_fields" already
        returnFields.extend(findMap.value<List>("return_fields"));
        findMap.erase("return_fields");
    }
    catch (SgDictKeyNotFoundError)
    {
        // Do nothing
    }

    findMap.add("return_fields", returnFields);

    // If the findMap already has a "type" field, override it with the
    // given entityType to ensure that the type will not conflict with 
    // the factory function.
    if (findMap.find("type"))
    {
        findMap.erase("type");
    }
    findMap.add("type", entityType);

    // Find the shotgun entities by the findMap
    List xmlrpcFindResult = Entity::findSGEntities(this, findMap, limit); 
    
    // Create entity class object.
    for (size_t i = 0; i < xmlrpcFindResult.size(); i++)
    {
        entities.push_back((*(registryFuncs.factoryFunc))(this, xmlrpcFindResult[i]));
    }

    return entities;
}
int main(int argc, char* argv[]) {

	if(argc != 2) {
		cout << "Uso: " << argv[0] << " palavras.txt" << endl;
		exit(-1);
	}
	//Inicializa o dicionario
	init_dict(argv[1]);	

	//Gera as palavras com até cinco letras
	Dict::iterator itset;
	tic();
	while(true) {
		int tamanho = gera_tamanho_palavra();
		char *new_word = gera_palavra(tamanho);

		itset = mydict.find(new_word);

		if(itset != mydict.end()) {
			mydict_found.insert(*itset);
			mydict.erase(*itset);
			qtd_encontradas++;
			
			imprime_prop();

			float prop = qtd_encontradas / (float) total_palavras;
			if(prop >= 1.0)
				break;
		}
		
		free(new_word);
	}

	cout << mydict_found.size() << ":" << mydict.size() << endl;

	total_palavras = mydict.size();

	controle=1;

	// Junta duas palavras para gerar palavras maiores
	Dict::iterator it[2];
	char* combined[2];
	for(it[0] = mydict_found.begin(); it[0]!=mydict_found.end(); ++it[0]) {
		for(it[1] = mydict_found.begin(); it[1]!=mydict_found.end(); ++it[1]) {
			combined[0] = mystrcat(*it[0], *it[1]);
			combined[1] = mystrcat(*it[1], *it[0]);
			
			for(int i=0; i<2; i++) {
				itset = mydict.find(combined[i]);
				if(itset != mydict.end()) {
					//cout << qtd_encontradas << " - combined: " << combined[i] << endl;
					mydict_found.insert(*itset);
					mydict.erase(*itset);
					qtd_encontradas++;

					imprime_prop();

					float prop = qtd_encontradas / (float) total_palavras;
					if(prop >= 1.0)
						break;
				}
				free(combined[i]);
			}
		}
	}
		
	fclose(arq_palavras);
	cout << "elapsed time: " << toc() << endl;

	return 0;
}
Exemple #8
0
int main(int argc, char** argv)
{
	Dict data;

	FILE* fNumbers = fopen("numbers.txt", "r");
	FILE* fresult = fopen("run_result.txt", "w");

	int32_t currentNumber = 1;
	int ch;


	while((ch = getc(fNumbers)) != EOF) {
		if(ch == '\n') {
			uint32_t key1 = currentNumber / keymax2;
			uint32_t key2 = currentNumber % keymax2;
			Dict::iterator kit = data.find(key1);
			
			uint32_t* &subarray = data[key1];
			if(kit == data.end()) {
				subarray = new uint32_t[keymax2];
				memset(subarray, 0, sizeof(uint32_t) * keymax2);
			}
			
			uint32_t &currentCounter = subarray[key2];
			currentCounter += 1;
			if(currentCounter == 2) {
				resultHeader = new Result(currentNumber, &currentCounter, resultHeader);
			}

			currentNumber = 1;
		}
		else if(ch != '\r') {
			currentNumber = (currentNumber * 10) + A2I(ch);
		}
	}

	wLineBuffer[99] = 0;
	while(resultHeader != NULL) {
		char* chptr = &wLineBuffer[99];
		I2A(chptr, resultHeader->data);

		fputc('"', fresult);
		fputs(chptr + 1, fresult);
		fputs("\", ", fresult);

		chptr = &wLineBuffer[99];
		I2A(chptr, *resultHeader->countPtr);
		fputs(chptr, fresult);
		fputc('\n', fresult);

		Result* next = resultHeader->nextPtr;
		delete resultHeader;
		resultHeader = next;
	}

	fclose(fresult);
	fclose(fNumbers);
	

	for(Dict::iterator it = data.begin(); it != data.end(); it++) {
		delete[] it->second;
	}

	return 0;
}
Exemple #9
0
void AutoUpdaterImpl::step() {
  if(!req) {
    ret();
    return;
  }

  if(!req->done())
    return;

  ret();

  if(req->getsize()) {
    Stringtable st(req->getbuf(), req->getsize());
    char last_mod[64] = "";
    enum {
      STATUS,
      HEADER,
      REPLY,
    } state = STATUS;
    Dict reply;

    for(int i = 0; i < st.size(); ++i) {
      const char* str = st.get(i);

      switch(state) {
      case STATUS:
	if(strncmp(str, "HTTP/", 5) != 0) {
	  msgbox("update: Invalid HTTP response\n");
	  return;
	}

	while(str && *str != '\0' && *str != ' ' && *str != '\t')
	  ++str;

	while(str && *str != '\0' && (*str == ' ' || *str == '\t'))
	  ++str;

	if(strncmp(str, "200", 3) == 0)
	  msgbox("HTTP status is OK\n");
	else if(strncmp(str, "304", 3) == 0) {
	  msgbox("update: version file not modified\n");
	  config.info3.last_update = time(NULL);
	  config.write();
	  return;
	} else {
	  msgbox("update: HTTP status isn't 200 or 304: %s\n", str);
	  return;
	}

	state = HEADER;
	break;

      case HEADER:
	if(*str == '\0') {
	  state = REPLY;
	  continue;
	}

	// Take note of the Last-Modified header.
	if(strncasecmp(str, "Last-Modified:", 14) == 0) {
	  while(str && *str != '\0' && *str != ' ' && *str != '\t')
	    ++str;

	  while(str && *str != '\0' && (*str == ' ' || *str == '\t'))
	    ++str;

	  snprintf(last_mod, sizeof(last_mod), "%s", str);
	  msgbox("update: Last-Modified: %s\n", last_mod);
	}

	break;

      case REPLY:
	msgbox("update: reply: %s\n", str);
	reply.add(str);
	break;
      };
    }

    const char* val = reply.find("qserv");
    if(val)
      snprintf(config.info3.default_game_server_address,
	       sizeof(config.info3.default_game_server_address),
	       "%s", val);

    if(reply.find_sub("version")) {
      const char* version_key = "unstable";

      if(VERSION_MINOR % 2 == 0)
	version_key = "stable";

      val = reply.find_sub("version")->find(version_key);
      if(val)
	  {
		int s = sizeof(config.info3.latest_version);
		strncpy(config.info3.latest_version, val, s);
		config.info3.latest_version[s-1] = 0;
	  }
    }

    if(*last_mod)
      snprintf(config.info3.last_modified, sizeof(config.info3.last_modified),
	       "%s", last_mod);

    config.info3.last_update = time(NULL);
    config.write();

    msgbox("update: done\n");
  } else
    msgbox("update: failed\n");
}