Esempio n. 1
0
void EventSource::connect()
{

    LOG(TRACE) + "Connecting EventSource: " + m_url;

    ASSERT(m_state == CONNECTING);
    ASSERT(m_pNetRequest == 0);

    Hashtable<String,String> headers;

    headers.put("Accept","text/event-stream");
    headers.put("Cache-Control", "no-cache");
    if (!m_lastEventId.empty())
        headers.put("Last-Event-ID", m_lastEventId);

    {    
      common::CMutexLock lock(m_mxReqAccess);
    
      m_pNetRequest = new net::CAsyncNetRequest();
   
      m_pNetRequest->setMethod("GET");
      m_pNetRequest->setUrl(m_url);
      m_pNetRequest->setHeaders(headers);
      m_pNetRequest->setCallback(this);

      new common::CRhoCallInThread<net::CAsyncNetRequest>( m_pNetRequest );
  }

}
Esempio n. 2
0
void db_insert_into_table( db::CDBAdapter& db, const String& table, Hashtable<String, String>& hashObject, const char* excludes = null)
{
    String cols = "";
    String quests = "";
    Vector<String> vals;

    for ( Hashtable<String,String>::iterator it = hashObject.begin();  it != hashObject.end(); ++it )
    {
        String key = it->first;
        String val  = it->second;

        if ( excludes && key.compare(excludes) == 0 )
            continue;

        if (cols.length() > 0)
        {
            cols += ',';
            quests += ',';
        }
    
        cols += key;
        quests += '?';
        vals.addElement( val );
    }

    String query = "insert into " + table + "(" + cols + ") values (" + quests + ")";

    db.executeSQLEx(query.c_str(), vals);
}
Esempio n. 3
0
File: Peer.cpp Progetto: kaznog/t09
		OperationRequestParameters Peer::opCreateRoomImplementation(const JString& gameID, bool isVisible, bool isOpen, nByte maxPlayers, const Hashtable& customRoomProperties, const Hashtable& customLocalPlayerProperties, const JVector<JString>& propsListedInLobby)
		{
			OperationRequestParameters op;
			if(gameID.length())
				op.put(ParameterCode::ROOM_NAME, ValueObject<JString>(gameID));

			Hashtable roomProps(Utils::stripToCustomProperties(customRoomProperties));
			if(!isOpen)
				roomProps.put(Properties::Room::IS_OPEN, isOpen);
			if(!isVisible)
				roomProps.put(Properties::Room::IS_VISIBLE, isVisible);
			if(maxPlayers)
				roomProps.put(Properties::Room::MAX_PLAYERS, maxPlayers);
			JString* propsListedInLobbyArr = allocateArray<JString>(propsListedInLobby.getSize());
			for(unsigned int i=0; i<propsListedInLobby.getSize(); ++i)
				propsListedInLobbyArr[i] = propsListedInLobby[i];
			roomProps.put(Properties::Room::PROPS_LISTED_IN_LOBBY, propsListedInLobbyArr, propsListedInLobby.getSize());
			deallocateArray(propsListedInLobbyArr);
			op.put(ParameterCode::ROOM_PROPERTIES, ValueObject<Hashtable>(roomProps));

			Hashtable playerProperties = Utils::stripToCustomProperties(customLocalPlayerProperties);
			if(playerProperties.getSize())
				op.put(ParameterCode::PLAYER_PROPERTIES, ValueObject<Hashtable>(playerProperties));
			op.put(ParameterCode::BROADCAST, ValueObject<bool>(true));
			op.put(ParameterCode::CLEANUP_CACHE_ON_LEAVE, ValueObject<bool>(true));
			return op;
		}
Esempio n. 4
0
UnicodeString& TransliteratorRegistry::getAvailableVariant(int32_t index,
                                                           const UnicodeString& source,
                                                           const UnicodeString& target,
                                                           UnicodeString& result) const {
    Hashtable *targets = (Hashtable*) specDAG.get(source);
    if (targets == 0) {
        result.truncate(0); // invalid source
        return result;
    }
    uint32_t varMask = targets->geti(target);
    int32_t varCount = 0;
    int32_t varListIndex = 0;
    while (varMask > 0) {
        if (varMask & 1) {
            if (varCount == index) {
                UnicodeString *v = (UnicodeString*) variantList.elementAt(varListIndex);
                if (v != NULL) {
                    result = *v;
                    return result;
                }
                break;
            }
            varCount++;
        }
        varMask >>= 1;
        varListIndex++;
    }
    result.truncate(0); // invalid target or index
    return result;
}
Esempio n. 5
0
bool LoadBalancingListener::setLocalPlayerPos(int x, int y)
{
	if(x >= 0 && x < mGridSize && y >= 0 && y < mGridSize) 
	{
		int prevGroup = getGroupByPos();
		mLocalPlayer.x = x;
		mLocalPlayer.y = y;
		if(prevGroup != getGroupByPos()) 
			updateGroups();
		Hashtable data;
		nByte coords[] = {static_cast<nByte>(mLocalPlayer.x), static_cast<nByte>(mLocalPlayer.y)};
		data.put((nByte)1, coords, 2);

		if(mSendGroup)
			mpLbc->opRaiseEvent(false, data, 2, 0, 0, 0, 0, 0, mSendGroup);
		else
		{
			if(mUseGroups)
				mpLbc->opRaiseEvent(false, data, 2, 0, 0, 0, 0, 0, getGroupByPos());
			else
				mpLbc->opRaiseEvent(false, data, 2);
		}
		mpView->changePlayerPos(mLcalPlayerNr, mLocalPlayer.x, mLocalPlayer.y);
		return true;
	}
	else 
		return false;
}
Esempio n. 6
0
/**
 * Remove a source-target/variant from the specDAG.
 */
void TransliteratorRegistry::removeSTV(const UnicodeString& source,
                                       const UnicodeString& target,
                                       const UnicodeString& variant) {
    // assert(source.length() > 0);
    // assert(target.length() > 0);
    UErrorCode status = U_ZERO_ERROR;
    Hashtable *targets = (Hashtable*) specDAG.get(source);
    if (targets == NULL) {
        return; // should never happen for valid s-t/v
    }
    uint32_t varMask = targets->geti(target);
    if (varMask == 0) {
        return; // should never happen for valid s-t/v
    }
    int32_t variantListIndex = variantList.indexOf((void*) &variant, 0);
    if (variantListIndex < 0) {
        return; // should never happen for valid s-t/v
    }
    int32_t remMask = 1 << variantListIndex;
    varMask &= (~remMask);
    if (varMask != 0) {
        targets->puti(target, varMask, status);
    } else {
        targets->remove(target); // should delete variants
        if (targets->count() == 0) {
            specDAG.remove(source); // should delete targets
        }
    }
}
Esempio n. 7
0
void TEST_Construction() {
  Hashtable h;
  h.resize(26);
  Item a = {"a", 'a'};
  Item b = {"b", 'b'};
  Item c = {"c", 'c'};
  Item abcd1234 = {"abcd1234", 99};
  Item abcdefghijklmnopqrstuv = {"abcdefghijklmnopqrstuv", 101};

  insert(&h, &a);
  ASSERT_EQ(h[simple_hash::hash("a") % h.size()]->value,'a');
  insert(&h, &b);
  ASSERT_EQ(h[simple_hash::hash("b") % h.size()]->value,'b');
  insert(&h, &c);
  ASSERT_EQ(h[simple_hash::hash("c") % h.size()]->value,'c');
  insert(&h, &abcd1234);
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size()]->value, 'a');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 1]->value, 'b');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 2]->value, 'c');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 3]->value, 99);
  insert(&h, &abcdefghijklmnopqrstuv);
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size()]->value, 'a');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 1]->value, 'b');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 2]->value, 'c');
  ASSERT_EQ(h[simple_hash::hash("abcd1234") % h.size() + 3]->value, 99);
  ASSERT_EQ(h[simple_hash::hash("abcdefghijklmnopqrstuv") % h.size() + 4]->value, 101);
}
Esempio n. 8
0
void
LocaleKeyFactory::updateVisibleIDs(Hashtable & result, UErrorCode & status) const
{
	const Hashtable * supported = getSupportedIDs(status);
	if (supported)
	{
		UBool visible = (_coverage & 0x1) == 0;

		const UHashElement * elem = NULL;
		int32_t pos = 0;
		while ((elem = supported->nextElement(pos)) != NULL)
		{
			const UnicodeString & id = *((const UnicodeString *)elem->key.pointer);
			if (!visible)
			{
				result.remove(id);
			}
			else
			{
				result.put(id, (void *)this, status); // this is dummy non-void marker used for set semantics
				if (U_FAILURE(status))
				{
					break;
				}
			}
		}
	}
}
Esempio n. 9
0
static size_t curlHeaderCallback(void *ptr, size_t size, size_t nmemb, void *opaque)
{
    Hashtable<String,String>* pHeaders = (Hashtable<String,String>*)opaque;
    size_t nBytes = size*nmemb;
    String strHeader((const char *)ptr, nBytes);
    RAWTRACE1("Received header: %s", strHeader.c_str());
    
    int nSep = strHeader.find(':');
    if (nSep > 0 )
    {		
        String strName = String_trim(strHeader.substr(0, nSep));
        String lName;
        std::transform(strName.begin(), strName.end(), std::back_inserter(lName), &::tolower);
        
        String strValue = String_trim(strHeader.substr(nSep+1, strHeader.length() - (nSep+3) ));
        
        if ( pHeaders->containsKey(lName) )
        {
            strValue += ";" + pHeaders->get( lName );
            pHeaders->put( lName, strValue );
        }
        else
            pHeaders->put(lName, strValue);
    }
    
    return nBytes;
}
StarSystem * GetLoadedStarSystem( const char *system )
{
    StarSystem *ss = star_system_table.Get( string( system ) );
    std::string ssys( string( system )+string( ".system" ) );
    if (!ss)
        ss = star_system_table.Get( ssys );
    return ss;
}
void Texture::setbad( const string & s)
{
    // Put both current path+texfile and shared texfile since they both have been looked for
    bool * b = new bool( true);
    if( VSFileSystem::current_path.back()!="")
        badtexHashTable.Put( VSFileSystem::GetHashName(s), b);
    badtexHashTable.Put( VSFileSystem::GetSharedTextureHashName(s), b);
}
Esempio n. 12
0
void
TimeUnitFormat::checkConsistency(UTimeUnitFormatStyle style, const char* key, UErrorCode& err) {
    if (U_FAILURE(err)) {
        return;
    }
    // there should be patterns for each plural rule in each time unit.
    // For each time unit,
    //     for each plural rule, following is unit pattern fall-back rule:
    //         ( for example: "one" hour )
    //         look for its unit pattern in its locale tree.
    //         if pattern is not found in its own locale, such as de_DE,
    //         look for the pattern in its parent, such as de,
    //         keep looking till found or till root.
    //         if the pattern is not found in root either,
    //         fallback to plural count "other",
    //         look for the pattern of "other" in the locale tree:
    //         "de_DE" to "de" to "root".
    //         If not found, fall back to value of
    //         static variable DEFAULT_PATTERN_FOR_xxx, such as "{0} h".
    //
    // Following is consistency check to create pattern for each
    // plural rule in each time unit using above fall-back rule.
    //
    StringEnumeration* keywords = getPluralRules().getKeywords(err);
    if (U_SUCCESS(err)) {
        const UnicodeString* pluralCount;
        while ((pluralCount = keywords->snext(err)) != NULL) {
            if ( U_SUCCESS(err) ) {
                for (int32_t i = 0; i < TimeUnit::UTIMEUNIT_FIELD_COUNT; ++i) {
                    // for each time unit,
                    // get all the patterns for each plural rule in this locale.
                    Hashtable* countToPatterns = fTimeUnitToCountToPatterns[i];
                    if ( countToPatterns == NULL ) {
                        countToPatterns = initHash(err);
                        if (U_FAILURE(err)) {
                            delete countToPatterns;
                            return;
                        }
                        fTimeUnitToCountToPatterns[i] = countToPatterns;
                    }
                    MessageFormat** formatters = (MessageFormat**)countToPatterns->get(*pluralCount);
                    if( formatters == NULL || formatters[style] == NULL ) {
                        // look through parents
                        const char* localeName = getLocaleID(err);
                        CharString pluralCountChars;
                        pluralCountChars.appendInvariantChars(*pluralCount, err);
                        searchInLocaleChain(style, key, localeName,
                                            (TimeUnit::UTimeUnitFields)i,
                                            *pluralCount, pluralCountChars.data(),
                                            countToPatterns, err);
                    }
                }
            }
        }
    }
    delete keywords;
}
Esempio n. 13
0
void 
SimpleFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const 
{
    if (_visible) {
        result.put(_id, (void*)this, status); // cast away const
    } else {
        result.remove(_id);
    }
}
Esempio n. 14
0
		void MutablePlayer::setName(const JString& name)
		{
			if(mName != name)
			{
				Hashtable properties;
				properties.put(static_cast<nByte>(Properties::Player::PLAYERNAME), mName=name);
				mLoadBalancingClient->opSetPropertiesOfPlayer(mNumber, properties);
			}
		}
Texture * Texture::Exists (string s) {
    Texture * tmp = texHashTable.Get(VSFileSystem::GetHashName(s));
    if (tmp==NULL) {
        string tmpo;
        tmp = texHashTable.Get (VSFileSystem::GetSharedTextureHashName (s));
    }
    if (tmp)
        return tmp->Original();
    return tmp;
}
Esempio n. 16
0
void LoadBalancingListener::createRoom() 
{
	char name[16];
	sprintf(name, "native-%d",rand() % 100);
	Hashtable props;
	props.put("s", mGridSize);
	props.put("m", mMap);
	mpLbc->opCreateRoom(name, true, true, 0, props);
	mpView->info( "Creating room %s", name );
}
Esempio n. 17
0
int32_t TransliteratorRegistry::countAvailableVariants(const UnicodeString& source,
                                                       const UnicodeString& target) const {
    Hashtable *targets = (Hashtable*) specDAG.get(source);
    if (targets == 0) {
        return 0;
    }
    UVector *variants = (UVector*) targets->get(target);
    // variants may be 0 if the source/target are invalid
    return (variants == 0) ? 0 : variants->size();
}
Esempio n. 18
0
void printGlobalMetadata() {
  cout << endl;
  cout << "Reading global metadata" << endl;
  Hashtable meta = reader->getGlobalMetadata();
  StringArray keys = MetadataTools::keys(meta);
  for (int i=0; i<keys.length(); i++) {
    Object value = meta.get(keys[i]);
    cout << keys[i] << ": " << value << endl;
  }
}
		void MutableRoom::mergeCustomProperties(const Hashtable& customProperties)
		{
			Hashtable stripDict = Peer::stripToCustomProperties(customProperties);
			if(!stripDict.getSize())
				return;
			Hashtable oldDict = mCustomProperties;
			mCustomProperties.put(stripDict);
			mCustomProperties = Peer::stripKeysWithNullValues(mCustomProperties);
			if(mCustomProperties != oldDict)
				mLoadBalancingPeer->opSetPropertiesOfRoom(stripDict);
		}
Esempio n. 20
0
		void MutablePlayer::mergeCustomProperties(const Hashtable& customProperties)
		{
			Hashtable stripDict = Utils::stripToCustomProperties(customProperties);
			if(!stripDict.getSize())
				return;
			Hashtable oldDict = mCustomProperties;
			mCustomProperties.put(stripDict);
			mCustomProperties = Utils::stripKeysWithNullValues(mCustomProperties);
			if(mCustomProperties != oldDict)
				mLoadBalancingClient->opSetPropertiesOfPlayer(mNumber, stripDict);
		}
Esempio n. 21
0
Handle_ptr hashexistsCommand( CBuiltinAdapter *adapter, Context &ctx,
		   Environment *env, std::vector<Handle_ptr> args)
{
  if (2 != args.size()) {
     throw ArgumentCountException( 2, __FILE__, __LINE__);
  }

  Hashtable *hashtable = asHashtable( args[0]);
  std::string key = args[1]->stringValue();
  return (hashtable->exists( key))? ctx.TRUE : ctx.FALSE;
}
Esempio n. 22
0
File: Peer.cpp Progetto: kaznog/t09
		OperationRequestParameters Peer::opJoinRoomImplementation(const JString& gameID, const Hashtable& customLocalPlayerProperties)
		{
			OperationRequestParameters op;
			op.put(ParameterCode::ROOM_NAME, ValueObject<JString>(gameID));
			
			Hashtable playerProps = Utils::stripToCustomProperties(customLocalPlayerProperties);
			if(playerProps.getSize())
				op.put(ParameterCode::PLAYER_PROPERTIES, ValueObject<Hashtable>(playerProps));
			op.put(ParameterCode::BROADCAST, ValueObject<bool>(true));
			return op;
		}
Esempio n. 23
0
void
SimpleLocaleKeyFactory::updateVisibleIDs(Hashtable& result, UErrorCode& status) const
{
    if (U_SUCCESS(status)) {
        if (_coverage & 0x1) {
            result.remove(_id);
        } else {
            result.put(_id, (void*)this, status);
        }
    }
}
Esempio n. 24
0
int main(void)
{
	Hashtable *x = new Hashtable();
	char *hola = "Hola";
	x->put(hola, 1);
	cout << (*x)[hola];



	return(0);
}
Esempio n. 25
0
// This program exercises the Ref class.
int main(void) 
{
   CompleteSetupSystem setupSystem;

   printf("sizeof(TestItemRef)=%i\n", (int)sizeof(TestItemRef));

   {
      printf("Checking queue...\n");
      Queue<TestItemRef> q;
      printf("Adding refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         TestItemRef tr(new TestItem(temp));
         ConstTestItemRef ctr(tr);
         ConstTestItemRef t2(ctr);
         q.AddTail(tr);
      }
      printf("Removing refs...\n");
      while(q.HasItems()) q.RemoveHead();
      printf("Done with queue test!\n");
   }

   {
      printf("Checking hashtable\n");
      Hashtable<String, TestItemRef> ht;
      printf("Adding refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         ht.Put(String(temp), TestItemRef(new TestItem(temp)));
      }
      printf("Removing refs...\n");
      for (int i=0; i<10; i++) 
      {
         char temp[50]; muscleSprintf(temp, "%i", i);
         ht.Remove(String(temp));
      }
      printf("Done with hash table test!\n");
   }
    
   printf("Beginning multithreaded object usage test...\n");
   {
      const uint32 NUM_THREADS = 50;
      TestThread threads[NUM_THREADS]; 
      for (uint32 i=0; i<NUM_THREADS; i++) threads[i].StartInternalThread();
      Snooze64(SecondsToMicros(10));
      for (uint32 i=0; i<NUM_THREADS; i++) threads[i].ShutdownInternalThread();
      printf("Multithreaded object usage test complete.\n");
   }

   printf("testrefcount complete, bye!\n");
   return 0;
}
void main()
{
	Hashtable *table;
	table = new Hashtable(TABLESIZE);

	readFromFile(table, DATAPATH);
	//table->print();
	cout << "Fill Factor: " << table->getFillFactor() << "( " << table->getElementCount() << " / " << TABLESIZE << " )" << endl;
	cout << "Find: " << table->find("Lani")->text << endl;
	delete table;
}
Esempio n. 27
0
void Tabid::pop() {
	if (symbols->size() == 0) return;
	Hashtable *bucket = (*symbols)[0];
	Hashtable::iterator iter = bucket->begin(),
			    end  = bucket->end();
	while (iter != end)
		delete iter->second;
	bucket->clear();
	symbols->pop_back();
	delete bucket;
}
Esempio n. 28
0
Handle_ptr hashsizeCommand( CBuiltinAdapter *adapter, Context &ctx,
		 Environment *env, std::vector<Handle_ptr> args)
{
  if (1 != args.size()) {
    throw ArgumentCountException( 1, __FILE__, __LINE__);
  }

  Hashtable *hashtable = asHashtable( args[0]);
  assert( 0 != hashtable);

  return ctx.factory->makeInteger( hashtable->size());
}
Esempio n. 29
0
UBool
SelectFormat::operator==(const Format& other) const {
    if( this == &other){
        return TRUE;
    }
    if( other.getDynamicClassID() != SelectFormat::getStaticClassID() ){
        return  FALSE;
    }
    SelectFormat* fmt = (SelectFormat*)&other;
    Hashtable* hashOther = fmt->parsedValuesHash;
    if ( parsedValuesHash == NULL && hashOther == NULL)
        return TRUE;
    if ( parsedValuesHash == NULL || hashOther == NULL)
        return FALSE;
    if ( hashOther->count() != parsedValuesHash->count() ){
        return FALSE;
    }

    const UHashElement* elem = NULL;
    int32_t pos = -1;
    while ((elem = hashOther->nextElement(pos)) != NULL) {
        const UHashTok otherKeyTok = elem->key;
        UnicodeString* otherKey = (UnicodeString*)otherKeyTok.pointer;
        const UHashTok otherKeyToVal = elem->value;
        UnicodeString* otherValue = (UnicodeString*)otherKeyToVal.pointer; 

        UnicodeString* thisElemValue = (UnicodeString*)parsedValuesHash->get(*otherKey);
        if ( thisElemValue == NULL ){
            return FALSE;
        }
        if ( *thisElemValue != *otherValue){
            return FALSE;
        }
        
    }
    pos = -1;
    while ((elem = parsedValuesHash->nextElement(pos)) != NULL) {
        const UHashTok thisKeyTok = elem->key;
        UnicodeString* thisKey = (UnicodeString*)thisKeyTok.pointer;
        const UHashTok thisKeyToVal = elem->value;
        UnicodeString* thisValue = (UnicodeString*)thisKeyToVal.pointer;

        UnicodeString* otherElemValue = (UnicodeString*)hashOther->get(*thisKey);
        if ( otherElemValue == NULL ){
            return FALSE;
        }
        if ( *otherElemValue != *thisValue){
            return FALSE;
        }

    }
    return TRUE;
}
/**
 * Returns the relationship between myfaction and theirfaction
 * 1 is happy. 0 is neutral (btw 1 and 0 will not attack)
 * -1 is mad. <0 will attack
 */
int FactionUtil::GetFactionIndex( const string& name )
{
    static Hashtable< string, int, 47 >factioncache;
    int *tmp = factioncache.Get( name );
    if (tmp)
        return *tmp;
    int  i   = GetFactionLookup( name.c_str() );
    tmp  = new int;
    *tmp = i;
    factioncache.Put( name, tmp );
    return i;
}