示例#1
0
void BTree::_post(Node* n) {
	if( n != NULL) {
		_post(n->left);
		printNode(n);
		_pre(n->right);
	}
}
示例#2
0
void BTree::postOrder() {
	_post(root);
}
示例#3
0
MemoryEntry* Cache::_LoadRemoteFile(const std::string& url, FileEntry* pFileEntry, bool async, boost::function<void(const std::string&, MemoryEntry*, void*)> callback, boost::function<void(const std::string&, MemoryEntry*, void*)> callback_onthread, void* userdata)
{
   // (1) download file from url (update FileEntry)
   // (2) load file to memory (create memory entry)

   MemoryEntry* result= 0;

   // check if entry already exists for memory entry
   const MemoryCache_t::left_iterator it =_memcache.left.find(pFileEntry->LocalFile()); 
   if (it!=_memcache.left.end()) 
   {
      result = it->info;
      return result;
   }

   std::string sTempFile = _GenerateFilename();
   pFileEntry->_SetLocalFile(sTempFile);

   if (async)
   {
      // async generation
      // this is a little tricky, because when creating an async representation
      // the cache entry and memory entry must be done at the same time.
      result = new MemoryEntry();
      insertMemoryEntry(sTempFile,result); // "empty" memory entry

      // make download job with url, tempfile, fileentry, mementry
      DownloadJob job;
      job.vMem = result;
      job.vFile = pFileEntry;
      job.local_file = sTempFile;
      job.url = url;
      job.onload = callback;
      job.onthread = callback_onthread;
      job.userdata = userdata;
      _downloadJobs.push(job);  // push job
      _post();
      return result;

   }
   else
   {
      //**************************************************
      // synchronous download and cache generation of file
      //**************************************************
      //std::cout << "**SYNCHRONOUS DOWNLOAD: " << url << "\n";
      result= new MemoryEntry();
      insertMemoryEntry(sTempFile,result);
      _doDownload(url, sTempFile, pFileEntry, result);
      
      if (callback_onthread)
      {
         callback_onthread(url, result, userdata);
      }
      
      if (callback)
      {
         callback(url, result, userdata);
      }      
      return result;

   }

   return 0;
}
示例#4
0
// Retrieve Data
MemoryEntry* Cache::_LoadLocalFile(const std::string& k, bool async, bool relative, boost::function<void(const std::string&, MemoryEntry*, void*)> callback, boost::function<void(const std::string&, MemoryEntry*, void*)> callback_onthread, const std::string& origURL, void* userdata)
{
   const MemoryCache_t::left_iterator it =_memcache.left.find(k); 

   if (it==_memcache.left.end()) 
   { 
      // We don't have it: 
      // Evaluate function and create new record 
      MemoryEntry* v= new MemoryEntry();
      insertMemoryEntry(k,v); 

      std::string sFilename;
      if (relative)
      {
         sFilename = _basedir + k;
      }
      else
      {
         sFilename = k;
      }

      // async download: create a "read from disk job"
      if (async)
      {
          // create new job
          DownloadJob job;
          job.vMem = v;
          job.vFile = 0;
          job.local_file = sFilename;
          job.url = origURL;
          job.onload = callback;
          job.onthread = callback_onthread;
          job.userdata = userdata;
          _downloadJobs.push(job);  // push job
          _post();
      }
      else
      {
         // synchronous read...
         _doRead(v, sFilename);
         if (callback_onthread)
         {
            callback_onthread(sFilename, v, userdata);
         }
         
         if (callback)
         {
            callback(sFilename, v, userdata);
         }

         
      }
      
      return v;
   }
   else
   {
      // We do have it: 
      // Update the access record view. 
      if (!it->info->IsFailed())
         _memcache.right.relocate(_memcache.right.end(), _memcache.project_right(it)); 
      return it->info; 
   }
}