Exemple #1
0
unsigned int
StringId::getId(const std::string &str)
{
#if 0
    unsigned int tmp = idmap[str];
    if (tmp > 0)
	return tmp;
    idmap[str] = nextid;
    revmap[nextid] = str;
    tmp = nextid;
    nextid += 1;
    return tmp;
#else
    HTE ent(str);
    const HTE *d = idmap.lookup(ent);
    if (d == NULL) {
	std::string *alloc = new std::string(str);
	ent.str = alloc;
	ent.id = nextid;
	idmap.add(ent);
	revmap.add(ent);
	nextid += 1;
    } else {
	ent.id = d->id;
    }
    return ent.id;
#endif
}
Exemple #2
0
Entity create_testlight()
{
    Model * model = Model::create(check_in_pwd("mdl/boring_sphere.dae"), true);
    Testlight_input * input = new Testlight_input;
    Testlight_physics * physics = new Testlight_physics;
    Point_light * light = new Point_light(true, glm::vec3(1.0f, 0.0f, 0.0f), true,
        glm::vec3(0.0f, 0.0f, 0.0f), 1.0f, 0.5f, 0.0f);
    Audio * audio = new Audio(glm::vec3(0.0f));

    Entity ent(
        model,
        input,
        physics,
        light,
        audio);

    input->signal_light_toggled().connect(sigc::track_obj(sigc::track_obj([light, audio]()
    {
        light->enabled = !light->enabled;
        audio->play_sound(check_in_pwd("sound/clickclick.ogg"));
    }, *light), *audio));
    input->signal_move_toggled().connect(sigc::mem_fun(*physics, &Testlight_physics::toggle_movement));

    Message_locator::get().add_callback("key_down", sigc::mem_fun(*input, &Testlight_input::key_down));

    Jukebox_locator::get().preload_sound(check_in_pwd("sound/clickclick.ogg"));

    return ent;
}
Exemple #3
0
bool checkMeshDirectory(CaseInfo &info, const std::string &meshdir, bool time)
{

    //std::cerr << "checking meshdir " << meshdir << std::endl;
    bf::path p(meshdir);
    if (!::is_directory(p))
    {
        std::cerr << meshdir << " is not a directory" << std::endl;
        return false;
    }

    bool havePoints = false;
    std::map<std::string, std::string> meshfiles;
    for (bf::directory_iterator it(p);
         it != bf::directory_iterator();
         ++it)
    {
        bf::path ent(*it);
        std::string stem = ent.stem().string();
        std::string ext = ent.extension().string();
        if (stem == "points" || stem == "faces" || stem == "owner" || stem == "neighbour")
        {
            if (::is_directory(*it) || (!ext.empty() && ext != ".gz"))
            {
                std::cerr << "ignoring " << *it << std::endl;
            }
            else
            {
                meshfiles[stem] = bf::path(*it).string();
                if (stem == "points")
                    havePoints = true;
            }
        }
    }

    if (meshfiles.size() == 4)
    {
        if (time)
        {
            info.varyingGrid = true;
            info.varyingCoords = true;
        }
        return true;
    }
    if (meshfiles.size() == 1 && time && havePoints)
    {
        info.varyingGrid = false;
        info.varyingCoords = true;
        return true;
    }
    if (meshfiles.size() == 3 && time && !havePoints)
    {
        info.varyingGrid = true;
        info.varyingCoords = false;
        return true;
    }

    std::cerr << "did not find all of points, faces, owner and neighbour files" << std::endl;
    return false;
}
 Str decode_char_entities(const Str &s)
 {
     typedef typename Str::value_type Ch;
     Str r;
     typename Str::const_iterator end = s.end();
     for (typename Str::const_iterator it = s.begin(); it != end; ++it)
     {
         if (*it == Ch('&'))
         {
             typename Str::const_iterator semicolon = std::find(it + 1, end, Ch(';'));
             if (semicolon == end)
                 BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
             Str ent(it + 1, semicolon);
             if (ent == detail::widen<Str>("lt")) r += Ch('<');
             else if (ent == detail::widen<Str>("gt")) r += Ch('>');
             else if (ent == detail::widen<Str>("amp")) r += Ch('&');
             else if (ent == detail::widen<Str>("quot")) r += Ch('"');
             else if (ent == detail::widen<Str>("apos")) r += Ch('\'');
             else
                 BOOST_PROPERTY_TREE_THROW(xml_parser_error("invalid character entity", "", 0));
             it = semicolon;
         }
         else
             r += *it;
     }
     return r;
 }
void
TermApp::RefsReceived(BMessage* message)
{
	// Works Only Launced by Double-Click file, or Drags file to App.
	if (!IsLaunching())
		return;

	entry_ref ref;
	if (message->FindRef("refs", 0, &ref) != B_OK)
		return;

	BFile file;
	if (file.SetTo(&ref, B_READ_WRITE) != B_OK)
		return;

	BNodeInfo info(&file);
	char mimetype[B_MIME_TYPE_LENGTH];
	info.GetType(mimetype);

	// if App opened by Pref file
	if (strcmp(mimetype, PREFFILE_MIMETYPE) == 0) {

		BEntry ent(&ref);
		BPath path(&ent);
		PrefHandler::Default()->OpenText(path.Path());
		return;
	}

	// if App opened by Shell Script
	if (strcmp(mimetype, "text/x-haiku-shscript") == 0) {
		// Not implemented.
		//    beep();
		return;
	}
}
Exemple #6
0
void DragonView::_SimpleDataFile( BMessage *msg )
{
	// Loading a bitmap from a file using the Translation Kit is very
	// easy, courtesy of BTranslationUtils.
	//
	// We loop through the refs in the message in case several files were
	// dropped on us.  If that happens, we'll end up displaying the last
	// one.  A real program would probably want to open new windows (or
	// some other container) for the dropped files.

	entry_ref ref;
	int32 idx = 0;
	while( msg->FindRef( "refs", idx++, &ref ) == B_OK ) {
		// Convert the entry_ref into a filename.
		BEntry ent( &ref, true );
		BPath path( &ent );

		// Load the bitmap via the Translation Kit
		BBitmap *new_bits = BTranslationUtils::GetBitmapFile( path.Path() );

		// Update the window contents
		if( Window()->LockLooper() ) {
			DragonApp *app = dynamic_cast<DragonApp *>( be_app );

			_SetNewImage( new_bits, app->rsrc_strings->FindString( RSRC_Dropped ) );

			dynamic_cast<DragonWindow *>( Window() )->NewImage();
			Window()->UnlockLooper();
		}
	}
}
Exemple #7
0
bool
NLang::LoadFileID(const char* langID)
{
	list.RemoveAllAttributes();
	
	BEntry ent(mPath.String(), true);
	BDirectory dir(&ent);
	
	BEntry entry;
	while (dir.GetNextEntry(&entry, true) == B_OK) {
		BPath path(&entry);
		BString name(path.Leaf());
		name.Remove(0, name.Length()-4);
		
		if (name.Compare(langID) == 0) {
			// filename matches *.langID
			
			if (load_lang_file(path.Path())) {
				return true;
			}
		}
	}
	
	// no match:
	//puts("(NLANG) fail (2)");
	return false;
}
Exemple #8
0
Entity create_testmonkey()
{
    Model * model = Model::create(check_in_pwd("mdl/monkey.dae"), true);
    Testmonkey_input * input = new Testmonkey_input;
    Spot_light * light = new Spot_light(true, glm::vec3(0.0f, 1.0f, 1.0f), true,
        glm::vec3(0.0f, 0.0f, 0.0f),
        glm::vec3(0.0f, 0.0f, 1.0f), std::cos(10.0f * M_PI / 180.0f), 90.0f,
        0.0f, 0.1f, 0.0f);
    Audio * audio = new Audio(glm::vec3(0.0f));

    Entity ent(
        model,
        input,
        nullptr, // physics
        light,
        audio);

    ent.set_pos(glm::vec3(-10.0f, 10.0f, -10.0f));
    ent.rotate_world(0.25f * M_PI, ent.up());
    ent.rotate_world(0.25f * M_PI, ent.right());

    audio->set_pos(ent.pos());

    input->signal_light_toggled().connect(sigc::track_obj(sigc::track_obj([light, audio]()
    {
        light->enabled = !light->enabled;
        audio->play_sound(check_in_pwd("sound/tack.ogg"));
    }, *light), *audio));
    Message_locator::get().add_callback("key_down", sigc::mem_fun(*input, &Testmonkey_input::key_down));

    Jukebox_locator::get().preload_sound(check_in_pwd("sound/tack.ogg"));
    audio->play_music(check_in_pwd("sound/Monkeys_Spinning_Monkeys.ogg"), 100.0f, true);

    return ent;
}
Exemple #9
0
  bool dijkstra() {
    priority_queue<pair<double, pair<int, int> > > q;
    vi ent(sz(adj), -2);
    vd dist(sz(adj), INF);
    fu(u, sz(adj)) if (imb[u] >= delta)
      q.push(make_pair(0.0, make_pair(u, -1)));

    while (!q.empty()) {
      int u = q.top().second.first, f = q.top().second.second;
      double d = -q.top().first; q.pop();
      if (ent[u] != -2) continue; dist[u] = d; ent[u] = f;
			for (int a : adj[u]) if (capres(a) >= delta)
        q.push(make_pair(-(dist[u] + rescost(a)), make_pair(dest[a], a)));
    }

    fu(u, sz(adj)) if (ent[u] != -2 && imb[u] <= -delta) {
      fu(v, sz(adj)) pot[v] += dist[v];
      for (int a = ent[u]; a != -1; a = ent[orig(a)]) {
        flow[a] += delta;
        flow[inv(a)] -= delta;
        imb[dest[a]] += delta;
        imb[orig(a)] -= delta;
      }
      return true;
    }
    return false;
  }
 std::basic_string<Ch> decode_char_entities(const std::basic_string<Ch> &s)
 {
     typedef typename std::basic_string<Ch> Str;
     Str r;
     typename Str::const_iterator end = s.end();
     for (typename Str::const_iterator it = s.begin(); it != end; ++it)
     {
         if (*it == Ch('&'))
         {
             typename Str::const_iterator semicolon = std::find(it + 1, end, Ch(';'));
             if (semicolon == end)
                 throw xml_parser_error("invalid character entity", "", 0);
             Str ent(it + 1, semicolon);
             if (ent == detail::widen<Ch>("lt")) r += Ch('<');
             else if (ent == detail::widen<Ch>("gt")) r += Ch('>');
             else if (ent == detail::widen<Ch>("amp")) r += Ch('&');
             else
                 throw xml_parser_error("invalid character entity", "", 0);
             it = semicolon;
         }
         else
             r += *it;
     }
     return r;
 }
Exemple #11
0
void TraxApp:: RefReceived( entry_ref * ref )
{
	BEntry ent( ref ) ;
	if( ent.IsDirectory() )
	{
		NewWindow(ref) ;
	}
}	
Exemple #12
0
//static
void LLDelayedGestureError::gestureMissing(const LLUUID &id)
{
	LLErrorEntry ent("GestureMissing", id);
	if ( ! doDialog(ent) )
	{
		enqueue(ent);
	}
}
Exemple #13
0
void KLocaleConfigTime::save()
{
  // temperary use of our locale as the global locale
  KLocale *lsave = KGlobal::_locale;
  KGlobal::_locale = m_locale;

  KConfig *config = KGlobal::config();
  KConfigGroupSaver saver(config, "Locale");

  KSimpleConfig ent(locate("locale",
			   QString::fromLatin1("l10n/%1/entry.desktop")
			   .arg(m_locale->country())), true);
  ent.setGroup("KCM Locale");

  QString str;

  str = ent.readEntry("CalendarSystem", QString::fromLatin1("gregorian"));
  config->deleteEntry("CalendarSystem", false, true);
  if (str != m_locale->calendarType())
    config->writeEntry("CalendarSystem", m_locale->calendarType(), true, true);

  str = ent.readEntry("TimeFormat", QString::fromLatin1("%H:%M:%S"));
  config->deleteEntry("TimeFormat", false, true);
  if (str != m_locale->timeFormat())
    config->writeEntry("TimeFormat", m_locale->timeFormat(), true, true);

  str = ent.readEntry("DateFormat", QString::fromLatin1("%A %d %B %Y"));
  config->deleteEntry("DateFormat", false, true);
  if (str != m_locale->dateFormat())
    config->writeEntry("DateFormat", m_locale->dateFormat(), true, true);

  str = ent.readEntry("DateFormatShort", QString::fromLatin1("%Y-%m-%d"));
  config->deleteEntry("DateFormatShort", false, true);
  if (str != m_locale->dateFormatShort())
    config->writeEntry("DateFormatShort",
		       m_locale->dateFormatShort(), true, true);

  int firstDay;
  firstDay = ent.readNumEntry("WeekStartDay", 1);
  config->deleteEntry("WeekStartDay", false, true);
  if (firstDay != m_locale->weekStartDay())
      config->writeEntry("WeekStartDay", m_locale->weekStartDay(), true, true);

  if ( m_locale->nounDeclension() )
  {
    bool b;
    b = ent.readBoolEntry("DateMonthNamePossessive", false);
    config->deleteEntry("DateMonthNamePossessive", false, true);
    if (b != m_locale->dateMonthNamePossessive())
      config->writeEntry("DateMonthNamePossessive",
		         m_locale->dateMonthNamePossessive(), true, true);
  }

  config->sync();

  // restore the old global locale
  KGlobal::_locale = lsave;
}
Exemple #14
0
static void LM_AddToSceneOrder (bool parents)
{
	for (int i = 0; i < cl.numLMs; i++) {
		localModel_t& lm = cl.LMs[i];
		if (!lm.inuse)
			continue;

		/* check for visibility */
		if (!((1 << cl_worldlevel->integer) & lm.levelflags))
			continue;

		/* if we want to render the parents and this is a child (has a parent assigned)
		 * then skip it */
		if (parents && lm.parent)
			continue;

		/* if we want to render the children and this is a parent (no further parent
		 * assigned), then skip it. */
		if (!parents && lm.parent == nullptr)
			continue;

		/* set entity values */
		entity_t ent(RF_NONE);
		assert(lm.model);
		ent.model = lm.model;
		ent.skinnum = lm.skin;
		ent.lighting = &lm.lighting;
		ent.setScale(lm.scale);

		if (lm.parent) {
			/** @todo what if the tagent is not rendered due to different level flags? */
			ent.tagent = R_GetEntity(lm.parent->renderEntityNum);
			if (ent.tagent == nullptr)
				Com_Error(ERR_DROP, "Invalid parent entity num for local model (%s/%s): %i",
						lm.model->name, lm.id, lm.parent->renderEntityNum);
			ent.tagname = lm.tagname;
		} else {
			R_EntitySetOrigin(&ent, lm.origin);
			VectorCopy(lm.origin, ent.oldorigin);
			VectorCopy(lm.angles, ent.angles);

			if (lm.animname[0] != '\0') {
				ent.as = lm.as;
				/* do animation */
				R_AnimRun(&lm.as, ent.model, cls.frametime * 1000);
			} else {
				ent.as.frame = lm.frame;
			}
		}

		/* renderflags like RF_PULSE */
		ent.flags = lm.renderFlags;

		/* add it to the scene */
		lm.renderEntityNum = R_AddEntity(&ent);
	}
}
Exemple #15
0
int main(int argc, char *argv[]) {
  gunk Reality = ent();
  ent_extend(Reality, Reality);
  ent_print(Reality);
  ent_behave(Reality, ent_print);
  ent_extend(Reality, Reality);
  ent_run(Reality);
  return 0;
}
Exemple #16
0
//static
void LLDelayedGestureError::gestureFailedToLoad(const LLUUID &id)
{
	LLErrorEntry ent("UnableToLoadGesture", id);

	if ( ! doDialog(ent) )
	{
		enqueue(ent);
	}
}
Exemple #17
0
status_t
ThemeManager::SetThemeScreenShot(int32 id, BBitmap *bitmap)
{
	FENTRY;
	status_t err;
	BMessage msg;
	BString name;
	BString themepath;
	BMessage *theme;
	
	if (id < 0)
		return EINVAL;
	theme = (BMessage *)fThemeList.ItemAt(id);
	if (!theme)
		return EINVAL;
	
	// TODO
	err = theme->FindMessage(Z_THEME_INFO_MESSAGE, &msg);
	if (err) {
		msg.MakeEmpty();
		theme->AddMessage(Z_THEME_INFO_MESSAGE, &msg);
	}
	err = ThemeLocation(id, themepath);
	if (err)
		return err;
	err = msg.FindString(Z_THEME_SCREENSHOT_FILENAME, &name);
	if (!err) {
		BPath spath(themepath.String());
		spath.Append(name.String());
		BEntry ent(spath.Path());
		if (ent.InitCheck() == B_OK)
			ent.Remove();
	}
	
	name = "screenshot.png";
	err = msg.ReplaceString(Z_THEME_SCREENSHOT_FILENAME, name);
	if (err)
		err = msg.AddString(Z_THEME_SCREENSHOT_FILENAME, name);
	if (err)
		return err;
	
	// save the BBitmap to a png
	BPath spath(themepath.String());
	spath.Append(name.String());
	BFile shotfile(spath.Path(), B_WRITE_ONLY|B_CREATE_FILE);
	if (shotfile.InitCheck() != B_OK)
		return shotfile.InitCheck();
	BTranslatorRoster *troster = BTranslatorRoster::Default();
	BBitmapStream bmstream(bitmap);
	err = troster->Translate(&bmstream, NULL, NULL, &shotfile, 'PNG '/* XXX: hack, should find by mime type */);
	if (err)
		return err;
	
	err = theme->ReplaceMessage(Z_THEME_INFO_MESSAGE, &msg);
	msg.PrintToStream();
	return err;
}
Exemple #18
0
bool scanModules(const std::string &dir, int hub, AvailableMap &available) {

   namespace bf = vistle::filesystem;
#ifdef WIN32
#ifdef _DEBUG
   std::cerr << dir + "/../../../libexec/module/Debug" << std::endl;
   bf::path p(dir + "/../../../libexec/module/Debug");
#else
   bf::path p(dir + "/../../../libexec/module/Release");
#endif
#else
   bf::path p(dir);
#endif
   try {
      if (!bf::is_directory(p)) {
         std::cerr << "scanModules: " << dir << " is not a directory" << std::endl;
         return false;
      }
   } catch (const bf::filesystem_error &e) {
      std::cerr << "scanModules: error in" << dir << ": " << e.what() << std::endl;
      return false;
   }

   p = bf::canonical(p);

   for (bf::directory_iterator it(p);
         it != bf::directory_iterator();
         ++it) {

      bf::path ent(*it);
      std::string stem = ent.stem().string();
      if (stem.size() > ModuleNameLength) {
         std::cerr << "scanModules: skipping " << stem << " - name too long" << std::endl;
         continue;
      } 
      if (stem.empty()) {
         continue;
      }

      std::string ext = ent.extension().string();

      AvailableModule mod;
      mod.hub = hub;
      mod.name = stem;
      mod.path = bf::path(*it).string();

      AvailableModule::Key key(hub, stem);
      auto prev = available.find(key);
      if (prev != available.end()) {
         std::cerr << "scanModules: overriding " << stem << ", " << prev->second.path << " -> " << mod.path << std::endl;
      }
      available[key] = mod;
   }

   return true;
}
Exemple #19
0
/**
 * @brief Adds a box that highlights the current active door
 */
static void LE_AddEdictHighlight (const le_t* le)
{
	const cBspModel_t* model = LE_GetClipModel(le);

	entity_t ent(RF_BOX);
	VectorSet(ent.color, 1, 1, 1);
	ent.alpha = (sin(cl.time * 6.28) + 1.0) / 2.0;
	CalculateMinsMaxs(le->angles, model->cbmBox, le->origin, ent.eBox);
	R_AddEntity(&ent);
}
Exemple #20
0
void block(Token *tk)
{// block
	ent();
	next(tk);
	if (tk->id == '}') PANIC("expected statement", tk->line);
	while (tk->id != '}' && tk->id) {
		stmt(tk);
		next(tk);
	}
	lev();
}
Exemple #21
0
double entCI(double input[], int cMatrix[], double partition, int nrows,int begin, int end)
{
  double s1[nrows], s2[nrows], entropy;
  int cs1[nrows], cs2[nrows];
  int s1Count=0, s2Count=0, sCount=0;
    while(input[begin]<partition)
    {
        cs1[s1Count]=cMatrix[begin];
        s1[s1Count++]=input[begin++];
    }
    while(begin<end)
    {
        cs2[s2Count]=cMatrix[begin];
        s2[s2Count++]=input[begin++];
    }
    sCount=s1Count+s2Count;
    entropy=(s1Count/double(sCount))*ent(s1,cs1,s1Count)
               +(s2Count/double(sCount))*ent(s2,cs2,s2Count);
    return entropy;
}
Exemple #22
0
void
NLang::Init(const char* path)
{
	BEntry ent(path, true);
	BPath p;
	ent.GetPath(&p);
	
	printf("Language directory is %s\n", p.Path());
	
	mPath = p.Path();
}
Exemple #23
0
void DentryCache::Insert(tfs_meta_key_t &key, const tfs_inode_t &value) {
  leveldb::MutexLock lock_cache_mutex(&cache_mutex);

  Entry ent(key, value);
  cache.push_front(ent);
  lookup[key] = cache.begin();
  if (cache.size() > maxsize) {
    lookup.erase(cache.back().first);
    cache.pop_back();
  }
}
Exemple #24
0
void FastTraxApp:: RefReceived( entry_ref * ref )
{
	BEntry ent( ref ) ;
	if( ent.IsDirectory() )
	{
		BWindow * win = new FastTraxWindow( ref ) ;
		fWindows.AddWindow( win ) ;
		if( (fOptions & F_Hide) )
			win->Hide() ;
		win->Show() ;
	}
}	
Exemple #25
0
bool FolderPanel :: GetPath( BPath * path )
{
	entry_ref ref ;

	if( !GetRef( &ref ) )
		return false ;
	
	BEntry ent( &ref ) ;
	path->SetTo( &ent ) ;

	return ( path->InitCheck() == B_OK ) ;
} 
Exemple #26
0
// returns B_ERROR if problems reading ref
// B_OK if ref is not a directory
// B_OK + 1 if ref is a directory
status_t
ent_is_dir(const entry_ref *ref)
{
	BEntry ent(ref);
	if (ent.InitCheck() != B_OK)
		return B_ERROR;

	struct stat st;
	if (ent.GetStat(&st) != B_OK)
		return B_ERROR;

	return S_ISDIR(st.st_mode) ? (B_OK + 1) : B_OK;
}
Exemple #27
0
/* Function: alureStopSource
 *
 * Stops the specified source ID, and any associated stream. The previously
 * specified callback will be invoked if 'run_callback' is not AL_FALSE.
 * Sources that were not started with <alurePlaySourceStream> or
 * <alurePlaySource> will still be stopped, but will not have any callback
 * called for them.
 *
 * Returns:
 * AL_FALSE on error.
 *
 * *Version Added*: 1.1
 *
 * See Also:
 * <alurePlaySourceStream>, <alurePlaySource>
 */
ALURE_API ALboolean ALURE_APIENTRY alureStopSource(ALuint source, ALboolean run_callback)
{
	PROTECT_CONTEXT();
	ALCcontext *current_ctx = alcGetCurrentContext();

	if(alGetError() != AL_NO_ERROR)
	{
		SetError("Existing OpenAL error");
		return AL_FALSE;
	}

	EnterCriticalSection(&cs_StreamPlay);

	if((alSourceStop(source),alGetError()) != AL_NO_ERROR)
	{
		LeaveCriticalSection(&cs_StreamPlay);
		SetError("Error stopping source");
		return AL_FALSE;
	}

	std::list<AsyncPlayEntry>::iterator i = AsyncPlayList.begin(),
	                                    end = AsyncPlayList.end();
	while(i != end)
	{
		if(i->source == source && i->ctx == current_ctx)
		{
			AsyncPlayEntry ent(*i);
			AsyncPlayList.erase(i);

			if(ent.buffers.size() > 0)
			{
				alSourcei(ent.source, AL_BUFFER, 0);
				alDeleteBuffers(ent.buffers.size(), &ent.buffers[0]);
				alGetError();
			}

			if(run_callback && ent.eos_callback)
			{
				DO_UNPROTECT();
				ent.eos_callback(ent.user_data, ent.source);
				DO_PROTECT();
			}
			break;
		}
		i++;
	}

	LeaveCriticalSection(&cs_StreamPlay);

	return AL_TRUE;
}
Exemple #28
0
double delta(double input[], int cInput[], double partition, int nrows, int begin, int end)
{
    int nbegin=begin;
    double s1[nrows], s2[nrows], delta;
    int cs1[nrows], cs2[nrows];
    int s1Count=0, s2Count=0, sCount=0;
    while(input[begin]<partition)
    {
        cs1[s1Count]=cInput[begin];
        s1[s1Count++]=input[begin++];
    }
    while(begin<end)
    {
        cs2[s2Count]=cInput[begin];
        s2[s2Count++]=input[begin++];
    }
    sCount=s1Count+s2Count;
    int c=0, c1=0, c2=0, maxC[3], minC[3];
    doMaxMinC(cInput,maxC[0],minC[0],nbegin,end);
    doMaxMinC(cs1,s1Count,maxC[1],minC[1]);
    doMaxMinC(cs2,s2Count,maxC[2],minC[2]);

    for(int i=0;i<3;i++)
    {
        for(int j=minC[i];j<=maxC[i];j++)
        {
            if(i==0 && p(j,cInput,nbegin,end)!=0.0)
               c++;
            else if(i==1 && p(j,cs1,s1Count)!=0.0)
               c1++;
            else if(i==2 && p(j,cs2,s2Count)!=0.0)
               c2++;
        }
    }
    delta = log2(pow(3.0,double(c))-2)-(c*fullent(input,cInput,nbegin,end)-
                     c1*ent(s1,cs1,s1Count)-c2*ent(s2,cs2,s2Count));
    return delta;
}
Exemple #29
0
        Entity* EntityManager::createEntity()
        {
            std::shared_ptr<Entity> ent( new Entity() );
            ent->idx = m_entities.insert( ent );

            std::string name;
            Core::StringUtils::stringPrintf( name, "Entity_%u", ent->idx.getValue() );
            ent->rename( name );

            m_entitiesName.insert( std::pair<std::string, Core::Index> (
                                       ent->getName(), ent->idx ) );

            return ent.get();
        }
Exemple #30
0
const std::string &
StringId::getString(unsigned int id)
{
#if 0    
    SINVARIANT(id < nextid);
    return revmap[id];
#else
    HTE ent(id);
    const HTE *d = revmap.lookup(ent);
    INVARIANT(d != NULL,
	      boost::format("internal error id %u has no std::string?!") % id);
    return *(d->str);
#endif

}