map syntax

written by juan on May 7th, 2005 @ 12:00 AM

i wanted to have a cache for some data that it was costly to generate between invocations of some java's JNI method. So, i decided to use C++ map to acomplish this. I thought that i would take me 10 seconds to write the cache code, but i found my self far far away from java's Collection, in a dark world of C++ arcaic syntax....
static std::map <jobject, ITrajectory *> cache;
std::map <jobject, ITrajectory *>::const_iterator ci =
              cache.find(self);
ITrajectory *realTrajectory;
if( ci == cache.end() ) {
    realTrajectory  = createTrajectory(env,self);
    cache[self] = realTrajectory;
} else {
    realTrajectory = ci->second;
}
:|

Comments are closed

Options:

Size

Colors