void CheckEvents(Cache<int, TestEntry>& cache, Listener<int, TestEntry>& lsnr)
{
    cache.Put(1, TestEntry(10));
    lsnr.CheckNextEvent(1, boost::none, TestEntry(10));

    cache.Put(1, TestEntry(20));
    lsnr.CheckNextEvent(1, TestEntry(10), TestEntry(20));

    cache.Put(2, TestEntry(20));
    lsnr.CheckNextEvent(2, boost::none, TestEntry(20));

    cache.Remove(1);
    lsnr.CheckNextEvent(1, TestEntry(20), TestEntry(20));
}
/**
 * Populate cache with test data.
 */
void Initialize()
{
    Cache<int64_t, Organization> orgCache =
        Ignition::Get().GetCache<int64_t, Organization>(ORG_CACHE);

    // Clear cache before running the example.
    orgCache.Clear();

    // Organizations.
    Organization org1("ApacheIgnite");
    Organization org2("Other");

    const int64_t org1Id = 1;
    const int64_t org2Id = 2;

    orgCache.Put(org1Id, org1);
    orgCache.Put(org2Id, org2);

    Cache<int64_t, Person> personCache =
        Ignition::Get().GetCache<int64_t, Person>(PERSON_CACHE);

    // Clear cache before running the example.
    personCache.Clear();

    // People.
    Person p1(org1Id, "John", "Doe", "John Doe has Master Degree.", 2000);
    Person p2(org1Id, "Jane", "Doe", "Jane Doe has Bachelor Degree.", 1000);
    Person p3(org2Id, "John", "Smith", "John Smith has Bachelor Degree.", 1000);
    Person p4(org2Id, "Jane", "Smith", "Jane Smith has Master Degree.", 2000);

    // Note that in this example we use custom affinity key for Person objects
    // to ensure that all persons are collocated with their organizations.
    personCache.Put(1, p1);
    personCache.Put(2, p2);
    personCache.Put(3, p3);
    personCache.Put(4, p4);
}
Example #3
0
/*
 * Execute individual Put and Get operations.
 * 
 * @param cache Cache instance.
 */
void PutGet(Cache<int, Organization>& cache) 
{
    // Create new Organization to store in cache.
    Organization org("Microsoft", Address("1096 Eddy Street, San Francisco, CA", 94109));

    // Put organization to cache.
    cache.Put(1, org);

    // Get recently created employee as a strongly-typed fully de-serialized instance.
    Organization orgFromCache = cache.Get(1);

    std::cout <<  ">>> Retrieved organization instance from cache: " << std::endl;
    std::cout << orgFromCache.ToString() << std::endl;
    std::cout << std::endl;
}
Example #4
0
PixelSize
TextCache::GetSize(const Font &font, const char *text)
{
#ifndef ENABLE_OPENGL
  const ScopeLock protect(text_cache_mutex);
#endif

  TextCacheKey key(font, text);
  const PixelSize *cached = size_cache.Get(key);
  if (cached != NULL)
    return *cached;

  PixelSize size = font.TextSize(text);

  key.Allocate();
  size_cache.Put(std::move(key), std::move(size));
  return size;
}
Example #5
0
PixelSize
TextCache::GetSize(const Font &font, const char *text)
{
#ifndef ENABLE_OPENGL
  const Poco::ScopedLock<Poco::Mutex> protect(text_cache_mutex);
#endif

  TextCacheKey key(font, text);
  const PixelSize *cached = size_cache.Get(key);
  if (cached != nullptr)
    return *cached;

#ifdef UNICODE
  PixelSize size = font.TextSize(UTF8ToWideConverter(text));
#else
  PixelSize size = font.TextSize(text);
#endif

  key.Allocate();
  size_cache.Put(std::move(key), std::move(size));
  return size;
}
Example #6
0
TextCache::Result
TextCache::Get(const Font &font, const char *text)
{
#ifdef ENABLE_OPENGL
  assert(pthread_equal(pthread_self(), OpenGL::thread));
#endif
  assert(font.IsDefined());
  assert(text != NULL);

  if (StringIsEmpty(text)) {
#ifdef ENABLE_OPENGL
    return nullptr;
#else
    return Result::Null();
#endif
  }

  TextCacheKey key(font, text);

  /* look it up */

#ifndef ENABLE_OPENGL
  const ScopeLock protect(text_cache_mutex);
#endif

  const RenderedText *cached = text_cache.Get(key);
  if (cached != NULL)
    return *cached;

  /* render the text into a OpenGL texture */

#ifdef USE_FREETYPE
  PixelSize size = font.TextSize(text);
  size_t buffer_size = font.BufferSize(size);
  if (buffer_size == 0) {
#ifdef ENABLE_OPENGL
    return nullptr;
#else
    return Result::Null();
#endif
  }

  uint8_t *buffer = new uint8_t[buffer_size];
  if (buffer == nullptr) {
#ifdef ENABLE_OPENGL
    return nullptr;
#else
    return Result::Null();
#endif
  }

  font.Render(text, size, buffer);
  RenderedText rt(size.cx, size.cy, buffer);
#ifdef ENABLE_OPENGL
  delete[] buffer;
#endif
#elif defined(ANDROID)
  PixelSize size, allocated_size;
  int texture_id = font.TextTextureGL(text, size, allocated_size);
  if (texture_id == 0)
    return NULL;

  RenderedText rt(texture_id, size.cx, size.cy,
                  allocated_size.cx, allocated_size.cy);
#else
#error No font renderer
#endif

  Result result = rt;

  key.Allocate();
  text_cache.Put(std::move(key), std::move(rt));

  /* done */

  return result;
}