Exemple #1
0
inline void CompImageLoader::Load(size_t size, ui8 color)
{
	if (!size)
		return;
	if (color==0xff)
	{
		auto   tmpbuf = new ui8[size];
		memset((void*)tmpbuf, color, size);
		Load(size, tmpbuf);
		delete [] tmpbuf;
		return;
	}
	//Current entry is RLE with same color as new block
	if (entry && entry[0] == color)
	{
		size_t toCopy = std::min<size_t>(size, 255 - entry[1]);
		size -= toCopy;
		entry[1] += toCopy;
	}
	//Create new entries
	while (size > 255)
	{
		NewEntry(color, 255);
		size -= 255;
	}
	if (size)
		NewEntry(color, size);
}
Exemple #2
0
int hdbm_insert(hdbm db, datum key, datum value)
/*
  Insert a new entry into the table without looking
  for duplicates.  The datums (key and value) are duplicated.
  
  Return 1 on sucess, 0 on failure.
  
  */
{
    entry *top = NewEntry(key, value);
    
    call_stats.inserts++;
    
    if (!top)
	return 0;
    
    if (!hdbm_check(db)) {
	fprintf(stderr, "hdbm_insert: invalid database handle %d\n", db);
	return 0;
    }
    
    if (hash_tables[db].file) {
	/* If using a file write key/pair to file and free memory for value */
	
	int status = write_file_entry(db, top);
	datum_free(top->value); top->value.dptr = 0;
	if (!status) return 0;
    }
    
    put_in_bin(db, top);
    
    return 1;
}
Exemple #3
0
static int hdbm_load(hdbm db, FILE *file)
/*
  Check that the file is indeed a data base and load data in
  */
{
    char header[32];
    file_entry fe;
    long rec_ptr;
    rewind(file);
    if ((hdbm_fread(header, sizeof(cookie), (size_t) 1, file) != 1) ||
	(strncmp(header, cookie, strlen(cookie)) != 0)) {
	(void) fprintf(stderr, "hdbm_load: cookie missing ... not a database\n");
	return 0;
    }

    /* Now simply keep reading until we hit end of file */
    
    rec_ptr = ftell(file);
    while (!hdbm_fseek(file, rec_ptr, SEEK_SET) &&
	   (hdbm_fread((char *) &fe, sizeof(fe), (size_t) 1, file) == 1)) {

	datum key, value;
	entry *e;

	if (fe.active) {
	    if (!datum_fread(file, rec_ptr+sizeof(fe), fe.key_size, &key)) {
		(void) fprintf(stderr, 
			       "hdbm_load: header present but key missing?\n");
		return 0;
	    }
	    
	    value.dptr = 0; value.dsize = fe.val_size;
	    
	    if (!(e = NewEntry(key, value)))
		return 0;
	    
	    datum_free(key); datum_free(value);
	    
	    e->rec_ptr = rec_ptr;
	    e->val_ptr = rec_ptr + ((long) sizeof(fe)) + fe.key_size;
	    
	    put_in_bin(db, e);
	}
	
	rec_ptr = rec_ptr + ((long) sizeof(fe)) + fe.key_size + fe.val_size;
	
    }
    
    /* Now check that we really are at EOF */
    
    (void) hdbm_fseek(file, 0L, SEEK_END);
    
    if (rec_ptr != ftell(file)) {
	fprintf(stderr, "hdbm_load: inconsistent end to file %ld != %ld\n",
		rec_ptr, ftell(file));
    }
    
    return TRUE;
}
void RegistryObjectReferenceMap::Put(int key, const SmartPointer<RegistryObject>& value)
{
  if (value.IsNull())
    throw ctkInvalidArgumentException("null values not allowed");

  Purge();

  ReferenceMapType::Iterator i = references.find(key);
  if (i != references.end())
  {
    delete *i;
  }
  references.insert(key, NewEntry(value));
}
TSharedRef<FString, ESPMode::ThreadSafe> FTextLocalizationManager::GetString(const FString& Namespace, const FString& Key, const FString* const SourceString)
{
	FScopeLock ScopeLock( &SynchronizationObject );

	// Hack fix for old assets that don't have namespace/key info
	if(Namespace.IsEmpty() && Key.IsEmpty())
	{
		return MakeShareable( new FString( SourceString ? **SourceString : TEXT("") ) );
	}

#if ENABLE_LOC_TESTING
	const bool bShouldLEETIFYAll = bIsInitialized && FInternationalization::Get().GetCurrentCulture()->GetName() == TEXT("LEET");

	// Attempt to set bShouldLEETIFYUnlocalizedString appropriately, only once, after the commandline is initialized and parsed
	static bool bShouldLEETIFYUnlocalizedString = false;
	{
		static bool bHasParsedCommandLine = false;
		if(!bHasParsedCommandLine && FCommandLine::IsInitialized())
		{
			bShouldLEETIFYUnlocalizedString = FParse::Param(FCommandLine::Get(), TEXT("LEETIFYUnlocalized"));
			bHasParsedCommandLine = true;
		}
	}
#endif

	// Find namespace's key table.
	FTextLookupTable::FKeyTable* LiveKeyTable = LiveTable.NamespaceTable.Find( Namespace );

	// Find key table's entry.
	FStringEntry* LiveEntry = LiveKeyTable ? LiveKeyTable->Find( Key ) : NULL;

	// Entry is present.
	if( LiveEntry )
	{
		// If we're in some sort of development setting, source may have changed but localization resources have not, in which case the source should be used.
		const uint32 SourceStringHash = SourceString ? FCrc::StrCrc32(**SourceString) : 0;

		// If the source string (hash) is different, the local source has changed and should override - can't be localized.
		if( SourceStringHash != 0 && SourceStringHash != LiveEntry->SourceStringHash )
		{
			LiveEntry->SourceStringHash = SourceStringHash;
			LiveEntry->String.Get() = SourceString ? **SourceString : TEXT("");

#if ENABLE_LOC_TESTING
			if( (bShouldLEETIFYAll || bShouldLEETIFYUnlocalizedString) && SourceString )
			{
				FInternationalization::Leetify(*LiveEntry->String);
				if(*LiveEntry->String == *SourceString)
				{
					UE_LOG(LogTextLocalizationManager, Warning, TEXT("Leetify failed to alter a string (%s)."), **SourceString );
				}
			}
#endif

			UE_LOG(LogTextLocalizationManager, Verbose, TEXT("An attempt was made to get a localized string (Namespace:%s, Key:%s), but the source string hash does not match - the source string (%s) will be used."), *Namespace, *Key, **LiveEntry->String);

#if ENABLE_LOC_TESTING
			LiveEntry->bIsLocalized = bShouldLEETIFYAll;
#else
			LiveEntry->bIsLocalized = false;
#endif
		}

		return LiveEntry->String;
	}
	// Entry is absent.
	else
	{
		// Don't log warnings about unlocalized strings if the system hasn't been initialized - we simply don't have localization data yet.
		if( bIsInitialized )
		{
			UE_LOG(LogTextLocalizationManager, Verbose, TEXT("An attempt was made to get a localized string (Namespace:%s, Key:%s, Source:%s), but it did not exist."), *Namespace, *Key, SourceString ? **SourceString : TEXT(""));
		}

		const TSharedRef<FString, ESPMode::ThreadSafe> UnlocalizedString = MakeShareable( new FString( SourceString ? **SourceString : TEXT("") ) );

		// If live-culture-swap is enabled or the system is uninitialized - make entries so that they can be updated when system is initialized or a culture swap occurs.
		CA_SUPPRESS(6236)
		CA_SUPPRESS(6316)
		if( !(bIsInitialized) || ENABLE_LOC_TESTING )
		{
#if ENABLE_LOC_TESTING
			if( (bShouldLEETIFYAll || bShouldLEETIFYUnlocalizedString) && SourceString )
			{
				FInternationalization::Leetify(*UnlocalizedString);
				if(*UnlocalizedString == *SourceString)
				{
					UE_LOG(LogTextLocalizationManager, Warning, TEXT("Leetify failed to alter a string (%s)."), **SourceString );
				}
			}
#endif

			if ( UnlocalizedString->IsEmpty() )
			{
				if ( !bIsInitialized )
				{
					*(UnlocalizedString) = AccessedStringBeforeLocLoadedErrorMsg;
				}
			}

			FStringEntry NewEntry(
#if ENABLE_LOC_TESTING
				bShouldLEETIFYAll						/*bIsLocalized*/
#else
				false												/*bIsLocalized*/
#endif
				, TEXT("")
				, SourceString ? FCrc::StrCrc32(**SourceString) : 0	/*SourceStringHash*/
				, UnlocalizedString									/*String*/
				);

			if( !LiveKeyTable )
			{
				LiveKeyTable = &(LiveTable.NamespaceTable.Add( Namespace, FTextLookupTable::FKeyTable() ));
			}

			LiveKeyTable->Add( Key, NewEntry );

			ReverseLiveTable.Add(NewEntry.String, FNamespaceKeyEntry( MakeShareable( new FString( Namespace ) ), MakeShareable( new FString( Key ) )));

		}

		return UnlocalizedString;
	}
}
	for (TObjectIterator<UClass> It; It; ++It)
	{
		UClass* Class = *It;
		// If this is a subclass of Actor Component, not abstract, and tagged as spawnable from Kismet
		if (Class->IsChildOf(UActorComponent::StaticClass()))
		{
			InMemoryClasses.Push(Class->GetFName());
			if (!Class->HasAnyClassFlags(CLASS_Abstract) && Class->HasMetaData(FBlueprintMetadata::MD_BlueprintSpawnableComponent) && !FKismetEditorUtilities::IsClassABlueprintSkeleton(Class)) //@TODO: Fold this logic together with the one in UEdGraphSchema_K2::GetAddComponentClasses
			{
				TArray<FString> ClassGroupNames;
				Class->GetClassGroupNames(ClassGroupNames);

				if (ClassGroupNames.Contains(CommonClassGroup))
				{
					FString ClassGroup = CommonClassGroup;
					FComponentClassComboEntryPtr NewEntry(new FComponentClassComboEntry(ClassGroup, Class, ClassGroupNames.Num() <= 1, EComponentCreateAction::SpawnExistingClass));
					SortedClassList.Add(NewEntry);
				}
				if (ClassGroupNames.Num() && !ClassGroupNames[0].Equals(CommonClassGroup))
				{
					const bool bIncludeInFilter = true;

					FString ClassGroup = ClassGroupNames[0];
					FComponentClassComboEntryPtr NewEntry(new FComponentClassComboEntry(ClassGroup, Class, bIncludeInFilter, EComponentCreateAction::SpawnExistingClass));
					SortedClassList.Add(NewEntry);
				}
			}

			bool const bOutOfDateClass = Class->HasAnyClassFlags(CLASS_NewerVersionExists);
			if (!bOutOfDateClass && !FKismetEditorUtilities::IsClassABlueprintSkeleton(Class))
			{
Exemple #7
0
inline void CompImageLoader::Load(size_t size, const ui8 * data)
{
	while (size)
	{
		//Try to compress data
		while(true)
		{
			ui8 color = data[0];
			if (color != 0xff)
			{
				size_t runLength = 1;
				while (runLength < size && color == data[runLength])
					runLength++;

				if (runLength > 1 && runLength < 255)//Row of one color found - use RLE
				{
					Load(runLength, color);
					data += runLength;
					size -= runLength;
					if (!size)
						return;
				}
				else
					break;
			}
			else
				break;
		}
		//Select length for new raw entry
		size_t runLength = 1;
		ui8 color = data[0];
		ui8 type = typeOf(color);
		ui8 color2;
		ui8 type2;
		
		if (size > 1)
		{
			do
			{
				color2 = data[runLength];
				type2 = typeOf(color2);
				runLength++;
			}
			//While we have data of this type and different colors
			while ((runLength < size) && (type == type2) && ( (color2 != 0xff) || (color2 != color)));
		}
		size -= runLength;

		//add data to last entry
		if (entry && entry[0] == 0xff && type == typeOf(entry[2]))
		{
			size_t toCopy = std::min<size_t>(runLength, 255 - entry[1]);
			runLength -= toCopy;
			entry[1] += toCopy;
			memcpy(position, data, toCopy);
			data+=toCopy;
			position+=toCopy;
		}
		//Create new entries
		while (runLength > 255)
		{
			NewEntry(data, 255);
			runLength -= 255;
		}
		if (runLength)
			NewEntry(data, runLength);
	}
}
Exemple #8
0
indextype FindEntry(struct matrix *m, const byte *key, const int create) {
  indextype hashidx, *storeidx, idx;

  hashidx = CalculateHashIndex(m, key);
  storeidx = &(m->hash[hashidx]);

  if (*storeidx < 0) { /* There is no node here */
    if (create <= 0)
      return (-1); /* Delete or read, nothing to do */
    *storeidx = NewEntry(m);
    m->next[*storeidx] = -1;
    m->prev[*storeidx] = hashidx;
    idx = *storeidx;
  } else {
    const int cr =
        memcmp(&(m->keys[*storeidx * m->key_size]), key, m->key_size);
    if (cr > 0) {
      /* The node is to be created as the first of the list */
      if (create <= 0)
        return (-1);
      idx = *storeidx;
      *storeidx = NewEntry(m);
      m->next[*storeidx] = idx;
      m->prev[*storeidx] = hashidx;
      m->prev[idx] = -*storeidx - 1;
      idx = *storeidx;
    } else if (cr == 0) {
      /* The node is the first node */
      if (create >= 0)
        return (*storeidx);
      /* Ok, the node should be deleted then ... */
      RemoveEntryIdx(m, *storeidx);
      return (-1);
    } else {
      /* Node is somewhere in the list ? */
      idx = *storeidx;
      while (m->next[idx] >= 0 &&
             (memcmp(&(m->keys[m->next[idx] * m->key_size]), key,
                     m->key_size) <= 0)) {
        idx = m->next[idx];
      }
      if (!memcmp(&(m->keys[idx * m->key_size]), key, m->key_size)) {
        /* Ok, found and return */
        if (create >= 0)
          return (idx);
        RemoveEntryIdx(m, idx);
        return (-1);
      }
      /* Was not in the list */
      if (create <= 0)
        return (-1);
      {
        const indextype idx3 = idx;
        idx = NewEntry(m);
        m->next[idx] = m->next[idx3];
        m->next[idx3] = idx;
        m->prev[idx] = -idx3 - 1;
        if (m->next[idx] != -1)
          m->prev[m->next[idx]] = -idx - 1;
      }
    }
  }
  // assert(idx>=0);
  memcpy(&(m->keys[idx * m->key_size]), key, m->key_size);
  memcpy(&(m->data[idx * m->size_of_entry]), m->default_value,
         m->size_of_entry);
  return (idx);
}