コード例 #1
0
// Get users list with info.
void meth::GetOnlineUsers(LogicalConnections::iterator conn, String &response) {
	OnlineUsersList online_users = ::GetOnlineUsers();
	bool first_user = true;
	User user;

	response = "[";
	for (OnlineUsersList::iterator online_user = online_users.begin(); online_user != online_users.end(); online_user++) {
		// Add comma before each user except first.
		if (!first_user) {
			response += ",";
		} else {
			first_user = false;
		}
		response += "{";

		user = GetUser(online_user->user_ref);
		AddPair(response, "name", user.name, true, true);
		AddPair(response, "sex", (int) user.sex, false, true);
		AddPair(response, "ip", (user.hidden_ip) ? String("N/A") : user.ip, true, true);
		AddPair(response, "state", online_user->state, true, false);
		response += "}";
	}

	response += "]";
}
コード例 #2
0
ファイル: genericparser2.cpp プロジェクト: Joanxt/OpenJK
bool CGPGroup::Parse(char **dataPtr, CTextPool **textPool)
{
	char		*token;
	char		lastToken[MAX_TOKEN_SIZE];
	CGPGroup	*newSubGroup;
	CGPValue	*newPair;

	while(1)
	{
		token = GetToken(dataPtr, true);

		if (!token[0])
		{	// end of data - error!
			if (mParent)
			{
				return false;
			}
			else
			{
				break;
			}
		}
		else if (strcmpi(token, "}") == 0)
		{	// ending brace for this group
			break;
		}

		strcpy(lastToken, token);

		// read ahead to see what we are doing
		token = GetToken(dataPtr, true, true);
		if (strcmpi(token, "{") == 0)
		{	// new sub group
			newSubGroup = AddGroup(lastToken, textPool);
			newSubGroup->SetWriteable(mWriteable);
			if (!newSubGroup->Parse(dataPtr, textPool))
			{
				return false;
			}
		}
		else if (strcmpi(token, "[") == 0)
		{	// new pair list
			newPair = AddPair(lastToken, 0, textPool);
			if (!newPair->Parse(dataPtr, textPool))
			{
				return false;
			}
		}
		else
		{	// new pair
			AddPair(lastToken, token, textPool);
		}
	}

	return true;
}
コード例 #3
0
ファイル: AddRsnPairsRho.C プロジェクト: fbellini/AliRsn
void AddRsnPairsRho(AliAnalysisTaskSE *task,
                    Bool_t isMC,
                    Bool_t isMixing,
                    AliPID::EParticleType pType1,
                    Int_t listID1,
                    AliPID::EParticleType pType2,
                    Int_t listID2,
                    AliRsnCutSet *cutsEvent=0,
                    AliRsnCutSet *cutsPair=0,
                    TString suffix = "") {

   Printf("id1=%d id2=%d",listID1,listID2);

   // retrieve mass from PDG database
   Int_t         pdg  = 113;
   TDatabasePDG *db   = TDatabasePDG::Instance();
   TParticlePDG *part = db->GetParticle(pdg);
   Double_t mass = part->Mass();
   Bool_t valid;
   Int_t isRsnMini = AliAnalysisManager::GetGlobalInt("rsnUseMiniPackage",valid);

   if (isRsnMini) {
      AddPairOutputMiniRho(task,isMC,isMixing,pType1,listID1,pType2,listID2,pdg,mass,cutsPair,suffix);
   } else {
      // this function is common and it is located in RsnConfig.C
      // as ouptup AddPairOutputPhi from this macro will be taken
      AddPair(task,isMC,isMixing,pType1,listID1,pType2,listID2,pdg,mass,cutsEvent,cutsPair,suffix);
   }
}
コード例 #4
0
void CGPGroup::Parse(char **dataPtr, CTextPool **textPool)
{
	char		*token;
	char		lastToken[MAX_TOKEN_SIZE];
	CGPGroup	*newSubGroup;
	CGPValue	*newPair;
	char		*name, *value;

	while(1)
	{
		token = GetToken(dataPtr, true);

		if (!token[0])
		{	// end of data - error!
			break;
		}
		else if (Q_strcmpi(token, "}") == 0)
		{	// ending brace for this group
			break;
		}

		strcpy(lastToken, token);

		// read ahead to see what we are doing
		token = GetToken(dataPtr, true, true);
		if (Q_strcmpi(token, "{") == 0)
		{	// new sub group
			name = (*textPool)->AllocText(lastToken, true, textPool);
			newSubGroup = AddGroup(name);
			newSubGroup->SetWriteable(mWriteable);
			newSubGroup->Parse(dataPtr, textPool);
		}
		else if (Q_strcmpi(token, "[") == 0)
		{	// new pair list
			name = (*textPool)->AllocText(lastToken, true, textPool);
			newPair = AddPair(name, 0);
			newPair->Parse(dataPtr, textPool);
		}
		else
		{	// new pair
			name = (*textPool)->AllocText(lastToken, true, textPool);
			value = (*textPool)->AllocText(token, true, textPool);
			AddPair(name, value);
		}
	}
}
コード例 #5
0
// Set value from the map list.
String SetParametersObject(MapList params, bool last_param_array) {
    MapList::iterator it;
	MapList::iterator last_param = params.end();
	last_param--;

    String params_object = "";

	for (it = params.begin(); it != params.end(); it++) {
		AddPair(params_object, it->first, it->second, (last_param == it && last_param_array) ? false : true, (last_param != it) ? true : false);
	}

	return params_object;
}
コード例 #6
0
// Get channels list.
void meth::GetChannelsList(LogicalConnections::iterator conn, String user_chnls, String &response) {
	ChannelsList channels = GetChannels();
	bool first_channel = true;

	response = "[";
	for (ChannelsList::iterator channel = channels.begin(); channel != channels.end(); channel++) {
		if (channel->visibility == 1) {
			// Add comma before each channel except first.
			if (!first_channel) {
				response += ",";
			} else {
            	first_channel = false;
            }
			response += "{";
			AddPair(response, "name", channel->name, true, true);
			AddPair(response, "topic", channel->topic, true, true);
			AddPair(response, "users_online", channel->online_users, false, true);
			AddPair(response, "access", (int) channel->access, false, false);
			response += "}";
		}
	}

	response += "]";
}
コード例 #7
0
ファイル: genericparser2.cpp プロジェクト: Joanxt/OpenJK
CGPValue *CGPGroup::AddPair(const char *name, const char *value, CTextPool **textPool)
{
	CGPValue	*newPair;

	if (textPool)
	{
		name = (*textPool)->AllocText((char *)name, true, textPool);
		if (value)
		{
			value = (*textPool)->AllocText((char *)value, true, textPool);
		}
	}

	newPair = new CGPValue(name, value);

	AddPair(newPair);

	return newPair;
}
コード例 #8
0
ファイル: genericparser.cpp プロジェクト: 3ddy/Jedi-Academy
/************************************************************************************************
 * CParseGroup
 *    copy constructor. recursively copies all subgroups and pairs.
 *
 * Input
 *    an existing parse group
 *
 * Output
 *    none
 *
 ************************************************************************************************/
CParseGroup::CParseGroup(CParseGroup *orig)
{
	CParseGroup		*newGroup = 0;

	if (orig == 0)
	{
		return;
	}
	mWriteable = orig->mWriteable;
	mName = orig->mName;
	mParent = orig->mParent;
	for (TParsePairIter itp = orig->PairsBegin(); itp != orig->PairsEnd(); itp++)
	{
		AddPair((*itp).first, (*itp).second);
	}
	for (TParseGroupIter itg = orig->GroupsBegin(); itg != orig->GroupsEnd(); itg++)
	{
		newGroup = new CParseGroup((*itg).second);
		AddSubGroup(newGroup);
	}
}
コード例 #9
0
ファイル: Json.cpp プロジェクト: puckipedia/BlogPositive
void
JsonObject::Parse(JsonParser* parser)
{
	parser->TakeUntil('{');
	parser->TakeOne();
	char chr;
	JsonString* name;
	while (chr = parser->Peek()) {
		if (chr == '}') {
			parser->TakeOne();
			return;
		}
		parser->TakeWhitespace();
		name = ParseNew<JsonString>(parser);
		parser->TakeUntil(':');
		parser->TakeOne();
		AddPair(name, parser->TakeValue());
		parser->TakeWhitespace();
		if(parser->Peek() == ',')
			parser->TakeOne();
		parser->TakeWhitespace();
	}
}
コード例 #10
0
ファイル: KeyCodes.cpp プロジェクト: DeadnightWarrior/spring
void CKeyCodes::Reset()
{
	nameToCode.clear();
	codeToName.clear();
	
	AddPair("backspace", SDLK_BACKSPACE);
	AddPair("tab",       SDLK_TAB);
	AddPair("clear",     SDLK_CLEAR);
	AddPair("enter",     SDLK_RETURN);
	AddPair("return",    SDLK_RETURN);
	AddPair("pause",     SDLK_PAUSE);
	AddPair("esc",       SDLK_ESCAPE);
	AddPair("escape",    SDLK_ESCAPE);
	AddPair("space",     SDLK_SPACE);
	AddPair("delete",    SDLK_DELETE);

	// ASCII mapped keysyms
	for (unsigned char i = ' '; i <= '~'; ++i) {
		if (!isupper(i)) {
			AddPair(std::string(1, i), i);
		}
	}

	nameToCode["\xA7"] = 220;

	/* Numeric keypad */
	AddPair("numpad0", SDLK_KP0);
	AddPair("numpad1", SDLK_KP1);
	AddPair("numpad2", SDLK_KP2);
	AddPair("numpad3", SDLK_KP3);
	AddPair("numpad4", SDLK_KP4);
	AddPair("numpad5", SDLK_KP5);
	AddPair("numpad6", SDLK_KP6);
	AddPair("numpad7", SDLK_KP7);
	AddPair("numpad8", SDLK_KP8);
	AddPair("numpad9", SDLK_KP9);
	AddPair("numpad.", SDLK_KP_PERIOD);
	AddPair("numpad/", SDLK_KP_DIVIDE);
	AddPair("numpad*", SDLK_KP_MULTIPLY);
	AddPair("numpad-", SDLK_KP_MINUS);
	AddPair("numpad+", SDLK_KP_PLUS);
	AddPair("numpad=", SDLK_KP_EQUALS);
	AddPair("numpad_enter", SDLK_KP_ENTER);

	/* Arrows + Home/End pad */
	AddPair("up",       SDLK_UP);
	AddPair("down",     SDLK_DOWN);
	AddPair("right",    SDLK_RIGHT);
	AddPair("left",     SDLK_LEFT);
	AddPair("insert",   SDLK_INSERT);
	AddPair("home",     SDLK_HOME);
	AddPair("end",      SDLK_END);
	AddPair("pageup",   SDLK_PAGEUP);
	AddPair("pagedown", SDLK_PAGEDOWN);

	/* Function keys */
	AddPair("f1",  SDLK_F1);
	AddPair("f2",  SDLK_F2);
	AddPair("f3",  SDLK_F3);
	AddPair("f4",  SDLK_F4);
	AddPair("f5",  SDLK_F5);
	AddPair("f6",  SDLK_F6);
	AddPair("f7",  SDLK_F7);
	AddPair("f8",  SDLK_F8);
	AddPair("f9",  SDLK_F9);
	AddPair("f10", SDLK_F10);
	AddPair("f11", SDLK_F11);
	AddPair("f12", SDLK_F12);
	AddPair("f13", SDLK_F13);
	AddPair("f14", SDLK_F14);
	AddPair("f15", SDLK_F15);

	/* Key state modifier keys */
	//AddPair("numlock", SDLK_NUMLOCK);
	//AddPair("capslock", SDLK_CAPSLOCK);
	//AddPair("scrollock", SDLK_SCROLLOCK);
	AddPair("shift", SDLK_LSHIFT);
	AddPair("ctrl",  SDLK_LCTRL);
	AddPair("alt",   SDLK_LALT);
	AddPair("meta",  SDLK_LMETA);
	// I doubt these can be used correctly anyway (without special support in other parts of the spring code...)
	//AddPair("super", SDLK_LSUPER);    /* Left "Windows" key */
	//AddPair("mode", SDLK_MODE);       /* "Alt Gr" key */
	//AddPair("compose", SDLK_COMPOSE); /* Multi-key compose key */

	/* Miscellaneous function keys */
	//AddPair("help", SDLK_HELP);
	AddPair("printscreen", SDLK_PRINT);
	//AddPair("sysreq", SDLK_SYSREQ);
	//AddPair("break", SDLK_BREAK);
	//AddPair("menu", SDLK_MENU);
	// These conflict with "joy*" nameToCode.
	//AddPair("power", SDLK_POWER);     /* Power Macintosh power key */
	//AddPair("euro", SDLK_EURO);       /* Some european keyboards */
	//AddPair("undo", SDLK_UNDO);       /* Atari keyboard has Undo */

	// Are these required for someone??
	//AddPair("'<'", 226);
	//AddPair("','", 188);
	//AddPair("'.'", 190);

	AddPair("joyx", 400);
	AddPair("joyy", 401);
	AddPair("joyz", 402);
	AddPair("joyw", 403);
	AddPair("joy0", 300);
	AddPair("joy1", 301);
	AddPair("joy2", 302);
	AddPair("joy3", 303);
	AddPair("joy4", 304);
	AddPair("joy5", 305);
	AddPair("joy6", 306);
	AddPair("joy7", 307);
	AddPair("joyup",    320);
	AddPair("joydown",  321);
	AddPair("joyleft",  322);
	AddPair("joyright", 323);

	// remember our defaults	
  defaultNameToCode = nameToCode;
  defaultCodeToName = codeToName;
}
コード例 #11
0
cElHomographie  cElHomographie::RobustInit(double & aDMIn,double * aQuality,const ElPackHomologue & aPack,bool & Ok ,int aNbTestEstim, double aPerc,int aNbMaxPts)
{
   cElHomographie aRes = cElHomographie::Id();
   Ok = false;
   Pt2dr aCdg(0,0);
   for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
   {
       aCdg = aCdg + itH->P1();
   }

   aCdg = aCdg / double(aPack.size());
   
   std::vector<std::pair<Pt2dr,Pt2dr> > aV00;
   std::vector<std::pair<Pt2dr,Pt2dr> > aV01;
   std::vector<std::pair<Pt2dr,Pt2dr> > aV10;
   std::vector<std::pair<Pt2dr,Pt2dr> > aV11;
   std::vector<std::pair<Pt2dr,Pt2dr> > aVAll;

   int aNbPtsTot = aPack.size();


   int aCpt = 0;
   for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
   {
        Pt2dr aP1 = itH->P1();
        Pt2dr aP2 = itH->P2();
        std::pair<Pt2dr,Pt2dr> aPair(aP1,aP2);

        if (  (((aCpt-1)*aNbMaxPts)/aNbPtsTot)  !=  ((aCpt*aNbMaxPts)/aNbPtsTot))
        {
            aVAll.push_back(aPair);
        }

        if (aP1.x < aCdg.x)
        {
            if (aP1.y < aCdg.y) aV00.push_back(aPair);
            else                aV01.push_back(aPair);
        }
        else
        {
            if (aP1.y < aCdg.y) aV10.push_back(aPair);
            else                aV11.push_back(aPair);
        }
        aCpt++;
   }


   if (aV00.empty()  || aV01.empty()  || aV10.empty()  || aV11.empty()  )
      return aRes;


   aDMIn = 1e30;
   int aNbPts = aVAll.size();
   int aNbKth = ElMax(1,ElMin(aNbPts-1,round_ni((aPerc/100.0) * aNbPts)));
   std::vector<double> aVDist;

   if (aNbMaxPts<aNbPtsTot)
      aNbTestEstim = (aNbTestEstim*aNbPtsTot) / aNbMaxPts;

   // int aKMIN = -1;
   std::vector<double> aVD; // For tuning and show in if(0) ...
   while (aNbTestEstim)
   {
       int aK00 = NRrandom3(aV00.size());
       int aK01 = NRrandom3(aV01.size());
       int aK10 = NRrandom3(aV10.size());
       int aK11 = NRrandom3(aV11.size());

       ElPackHomologue aP4;
       AddPair(aP4,aV00[aK00]);
       AddPair(aP4,aV01[aK01]);
       AddPair(aP4,aV10[aK10]);
       AddPair(aP4,aV11[aK11]);

       cElHomographie aSol = cElHomographie(aP4,true);

       aVDist.clear();
       for (int aK=0 ; aK< aNbPts ; aK++)
       {
          Pt2dr aP1 = aVAll[aK].first;
          Pt2dr aP2 = aVAll[aK].second;

/*
          Pt2dr aDif = aP2 -aSol.Direct(aP1);
          double aDx = ElAbs(aDif.x);
          double aDy = ElAbs(aDif.y);
          double aDist =  (aDx+aDy + ElMax(aDx,aDy))/ 2.0;
*/
          double aDist = QuickDist(aP2 -aSol.Direct(aP1));
          aVDist.push_back(aDist);
       }
       
       double aSom = MoyKPPVal(aVDist,aNbKth);
       
       aVD.push_back(aSom);

       //std::cout << "Robust:Hom:SOM = " << aDMIn << " " << aSom << "\n";

       if (aSom <aDMIn)
       {
          aRes = aSol;
          aDMIn = aSom;
       }
       aNbTestEstim--;
   }


   // double aDMinInit = aDMIn;
   ElPackHomologue aPckPds;
   for (int anIterL2 = 0 ; anIterL2 < 4 ; anIterL2++)
   {
       aPckPds = ElPackHomologue();
       aVDist.clear();
       int aCpt = 0;
       for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
       {
           Pt2dr aP1 = itH->P1();
           Pt2dr aP2 = itH->P2();
           double aDist = QuickDist(aP2 -aRes.Direct(aP1));
           aVDist.push_back(aDist);

           double aPds = 1/ (1+ 4*ElSquare(aDist/aDMIn));
           aPckPds.Cple_Add(ElCplePtsHomologues(aP1,aP2,aPds));
           aCpt++;
       }
       ELISE_ASSERT(aNbPtsTot==aPack.size() ,"KKKKK ????");
       int aKTh = round_ni(aNbPtsTot * (aPerc/100.0));

       ELISE_ASSERT(int(aVDist.size())==aNbPtsTot,"Compat MoyKPPVal/SplitArrounKthValue");
       aDMIn = MoyKPPVal(aVDist,aKTh);

       aRes = cElHomographie(aPckPds,true);
   }

   if (aQuality)
   {
      std::vector<double> aVEstim;
      int aNbTestValid = 71;
      for (int aKTest = 0 ; aKTest <aNbTestValid ; aKTest++)
      {
          ElPackHomologue aPckPdsA;
          ElPackHomologue aPckPdsB;
          cRandNParmiQ  aSelec(aNbPtsTot/2,aNbPtsTot);

          for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
          {
              Pt2dr aP1 = itH->P1();
              Pt2dr aP2 = itH->P2();
              double aDist = QuickDist(aP2 -aRes.Direct(aP1));
              aVDist.push_back(aDist);

              double aPds = 1/ sqrt(1+ ElSquare(aDist/aDMIn));
              // if (NRrandom3() > 0.5) 
              if (aSelec.GetNext())
                  aPckPdsA.Cple_Add(ElCplePtsHomologues(aP1,aP2,aPds));
              else
                  aPckPdsB.Cple_Add(ElCplePtsHomologues(aP1,aP2,aPds));

           
          }
          cElHomographie aResA = cElHomographie(aPckPdsA,true);
          cElHomographie aResB = cElHomographie(aPckPdsB,true);

          double aSomDist = 0; 
          for (ElPackHomologue::tCstIter itH=aPack.begin() ; itH!=aPack.end() ; itH++)
          {
              Pt2dr aP1 = itH->P1();

              Pt2dr  aQ   = aRes.Direct(aP1);
              Pt2dr  aQA  = aResA.Direct(aP1);
              Pt2dr  aQB  = aResB.Direct(aP1);
              double aDist = (QuickDist(aQ-aQA) + QuickDist(aQ-aQB) + QuickDist(aQB-aQA)) / 3.0;
              aSomDist += aDist;
          }
          aSomDist /= aNbPtsTot;
          aVEstim.push_back(aSomDist);
      }
      *aQuality  = MedianeSup(aVEstim);
   }


   Ok= true;
   return aRes;
}