Esempio n. 1
0
void print_table(str s, const Ptable& T) {
	printf("%s", s.c_str()); printf("\n");
	int l = T.size();
	if (l==0) {
		printf("   ! Empty table\n");
		return;
	}
	int c = T[0].size();
	for (int i=0; i<l; i++) {
		if (T[i].size()!=c) {
			printf("   ! Table has different number of columns depending to the lines\n");
			return;
		}
	}
	str s0(" ",10);
	const char* space = s0.c_str();
	printf("%s", space);
	for (int j=0; j<c; j++) printf("%11d",j);
	printf("\n");
	for (int i=0; i<l; i++) {
		printf("%4d",i);
		for (int j=0; j<c; j++) printf("%11s",p2s(T[i][j]).c_str());
		printf("\n");
	}
	printf("\n");
}
Esempio n. 2
0
bool NetworkClient::Connect(const str& server_address, double timeout) {
	ScopeLock lock(&lock_);

	bool ok = !is_socket_connecting_;
	if (!ok) {
		log_.Warning("Already connecting (from some other thread?)...");
		deb_assert(false);
	}

	SocketAddress target_address;
	if (ok) {
		ok = target_address.Resolve(server_address);
		if (!ok) {
			log_.Warningf("Could not resolve server address '%s'.", server_address.c_str());
		}
	}
	if (ok) {
		const std::string connection_id = SystemManager::GetRandomId();
		is_socket_connecting_ = true;
		lock.Release();
		socket_ = mux_socket_->Connect(target_address, connection_id, timeout);
		lock.Acquire();
		is_socket_connecting_ = false;
		ok = (socket_ != 0);
	}
	return (ok);
}
Esempio n. 3
0
void print_hist(str s, int i0, List hist, bool latex) {
	str et = latex ? " & " : " | ";
	str slash = latex ? "\\\\ \n" : "\n";

	str rrr(10,'r');
	if (latex) printf("\\begin{table}[H]\\begin{center} \n \\caption{%s (interval %d)} \n \\begin{tabular}{%s}\n",s.c_str(),i0,rrr.c_str());
	else printf("%s (interval %d)\n",s.c_str(),i0);

	int size = hist.size();
	for (int i=0; i<size; i++) {
		str s = ((i+1)%10==0 || i==size-1) ? slash : et;
		printf("%4s %s",f(hist[i]).c_str(),s.c_str());
	}
	if (latex) printf("\\end{tabular}\\end{center}\\end{table} \n");
	fl();
}
Esempio n. 4
0
void Personality::SetBehaviorTendency( const str &packageName , float tendency )
{
	PackageTendency_t      pEntry;
	BehaviorPackageType_t  *package;
	PackageTendency_t      *checkEntry;
	
	for ( int i = 1 ; i <= PackageList.NumObjects() ; i++ )
	{
		package = PackageList.ObjectAt( i );
		
		if ( !Q_stricmp( packageName.c_str() , package->packageName.c_str() ) )
		{
			// We have a match, let's check to make sure we're not doubling up
			for ( int j = 1 ; j <= _PackageTendencies.NumObjects() ; j++ )
			{
				checkEntry = &_PackageTendencies.ObjectAt( j );
				
				if ( checkEntry->packageIndex == i )
				{
					checkEntry->tendency = tendency;
					return;
				}
				
			}
			
			// We don't have a match, so lets add the package
			pEntry.lastTendencyCheck = 0.0f;
			pEntry.tendency = tendency;
			pEntry.packageIndex = i;
			
			_PackageTendencies.AddObject( pEntry );
			return;
		}
	}   
}
Esempio n. 5
0
Reader xml_reader::create_node(const str& name)
  {
    TiXmlElement* node = node_->FirstChildElement(name.c_str());
    if (node)
      return Reader( new xml_reader(node, types_, options_) );
      
    return Reader();
  }
void HydrogenLinAlgSolver::logV(str path) {
    ofstream of(path.c_str());
    of << 0 << '\t' << 0. << '\t' << '?' << '\t' << '?' << endl;
    for (uint j = 0; j < this->N_step; ++j)
        of << (j+1) << '\t' << this->r[j] << '\t' << real(this->V[j]) << '\t' << imag(this->V[j]) << endl;
    of << (this->N_step + 2) << '\t' << (this->R_max) << '\t' << '?' << '\t' << '?' << endl;
    of.close();
}
Esempio n. 7
0
int generateVariableAssign(str varName, str varVal){
	if(DEBUG)printf("\tPrzypisuje zmiennej <%s> wartosc <%s>\n", varName.c_str(), varVal.c_str());
	int varIndex=variableManager.getItemIndex(varName);
	if(varIndex==-1){
		int cVarIndex=constantManager.getItemIndex(varName);
		if(cVarIndex==-1){ // jezeli nie istnieje ani stala ani zmienna
			return 1;
		}else{ // jezeli istnieje stala
			return 2; 
		}
	}
	// istnieje indeks zmiennej
	if(DEBUG)printf("Indeks zmiennej to %d\n", varIndex);
	char temp[50];
	sprintf(temp, "STORE %d", varIndex);
	addCodeLine(temp);
	return 0;
}
Esempio n. 8
0
WriteIterator xml_writer::create_iterator(const str& name, schema* type)
  {
    if (name.empty())
      return WriteIterator( new xml_write_iterator(node_, type, types_) );
    
    TiXmlElement* node = new TiXmlElement(name.c_str());
    node_->LinkEndChild( node );
    return WriteIterator( new xml_write_iterator(node, type, types_) );
  }
Esempio n. 9
0
void print_list(str s, Slist L) {
	printf("%s \n",s.c_str());
	int n = L.size();
	//if (n==0) { // doesn't want to be compiled... mystery
		//printf("   ! Empty list\n"); 
		//return;
	//}
	for (int i=0; i<n; i++) printf("%5d : %s \n",i,L[i].c_str());
	printf("\n");
}
Esempio n. 10
0
/** POMOCNICZE */
int isNumber(str name){
   const char* buf = name.c_str();
   while(*buf){
      if (!isdigit(*buf))
         return 0;
      else
         ++buf;
   }
   return 1;
}
Esempio n. 11
0
ReadIterator xml_reader::create_iterator(const str& name, schema* type)
  {
    if (name.empty())
      return ReadIterator( new xml_read_iterator(node_, type, types_, options_) );
      
    TiXmlElement* node = node_->FirstChildElement(name.c_str());
    if (!node)
      return ReadIterator();
    
    return ReadIterator( new xml_read_iterator(node, type, types_, options_) );
  }
//
// Name:        UsingWeaponNamed()
// Parameters:  None
// Description: Checks if our _activeWeapon has the same name
//
bool CombatSubsystem::UsingWeaponNamed(const str& weaponName)
{
  if (!_activeWeapon.weapon)
    return false;


  if (!Q_stricmp(_activeWeapon.weapon->getName().c_str(), weaponName.c_str()))
    return true;

  return false;
}
void PostureController::setPostureState( const str &postureState )
{

	if ( !_postureStateMap )
		return;

	if ( act->deadflag )
		return;

   _currentPostureState = _postureStateMap->FindState( postureState.c_str() );
	

}
Esempio n. 14
0
   void save(vector<str> bytecode,str filename)
   {
       //сохранение байткода в файл
       ofstream f;
       f.open(filename.c_str());

       for(unsigned long long int i=0;i<bytecode.size();i++)
       {
           f<<bytecode[i].c_str()<<" ";
       }
       f.close();

   }
Esempio n. 15
0
tuple<long, long, long> count_file(const str& fn, bool cb, bool cw, bool cl)
{
    long total_bytes=0, total_words=0, total_lines=0;

    fstream f(fn.c_str());
    str line;
    while(len(line=readline(f))){
        total_lines++;
        auto words=line.split();
        total_words+=len(words);
        total_bytes=f.tellg();
    }
    return _t(total_bytes,total_words,total_lines);
}
Esempio n. 16
0
void print_mult_Dtable_latex(str s, str ss, Dtable T, double multX) {
	printf("# %s \n  Output data in %s \n\n",s.c_str(),ss.c_str());
	FILE* pFile;
	pFile = fopen(ss.c_str(),"w");
	if (!pFile) {
		printf("File opening failed \n"); fl();
		myexit(1);
	}

	fprintf(pFile,"x ");
	for (int i=0; i<T.size(); i++) fprintf(pFile,"%d ",i);
	fprintf(pFile,"\n");
	int maxrow = max_row(T);
	for (int j=0; j<maxrow; j++) {
		fprintf(pFile,"%f ",j*multX);
		for (int i=0; i<T.size(); i++) {
			if (j<T[i].size()) fprintf(pFile,"%f ",T[i][j]);
			else fprintf(pFile,"0 ");
		}
		fprintf(pFile,"\n");
	}
	fclose(pFile);
}
Esempio n. 17
0
   vector<str> load(str filename)
   {
       //загрузка байткода из файла
       ifstream f;
       vector<str> res;
       f.open(filename.c_str());
       char  tmp[50];
        char forStr,last='0';
       while(!f.eof())
       {

          f>> tmp;
           str t(tmp);
            if (t==LSTR)
            {

                res.push_back(t);
                t="";
                f.get();
               while(!f.eof())
               {
                       f.get(forStr);
                       if(forStr=='\"' && last!='\\')
                        {

                            break;
                        }
                       t=t+forStr;

                       last=forStr ;
               }

               t=escape(t);
                res.push_back(t);
                res.push_back("\"");
           }
           else
                res.push_back(t);
          if(f.fail())
                break;
       }




       f.close();

       return res;
   }
Esempio n. 18
0
void PowerupBase::init( const str &modelName, Sentient *owner )
{
	_modelName = modelName;
	_owner = owner;

	setModel( modelName );

	CancelEventsOfType( EV_ProcessInitCommands );
	ProcessInitCommands( gi.modelindex( modelName.c_str() ) );

	CancelEventsOfType( EV_Item_DropToFloor );

	setSolidType( SOLID_NOT );
	hideModel();
}
//--------------------------------------------------------------
// Name:		requestPosture()
// Class:		PostureController
//
// Description:	Request Handler for a specific Posture
//
// Parameters:	PostureStates_t postureState
//
// Returns:		true  -- if the posture is viable
//				false -- if the posture in not viable
//--------------------------------------------------------------
bool PostureController::requestPosture( const str &postureState , Listener *requestor )
{
	if ( !_postureStateMap )
		return false;
	
	_requestedPostureState = _postureStateMap->FindState( postureState.c_str() );
	
	if ( _requestedPostureState )
	{
		_requestor = requestor;
		_requestedPostureState_Name = postureState;
		return true;
	}
	
	
	
	return false;
}
Esempio n. 20
0
//--------------------------------------------------------------
// Name:		GetPackageIndex()
// Class:		PackageManager
//
// Description:	Returns the package index for the packageName.
//				We iterate through our list of registered behavior
//				packages because:  First, if the packages are registered
//				we know that the actor can use them.  Secondly, by only
//				having to be concerned about the packages we have specifically
//				registered we can cut way down on string compares. 
//
// Parameters:	const str &packageName
//
// Returns:		int
//--------------------------------------------------------------
int PackageManager::GetPackageIndex( const str &packageName )
{
	BehaviorPackageEntry_t pEntry;		
	BehaviorPackageType_t  *package;	
	
	// We do this so that we only have to do str compares on behavior
	// packages we have registered -- Not the whole Package List
	for ( int i = 1 ; i <= _BehaviorPackages.NumObjects() ; i++ )
	{
		pEntry = _BehaviorPackages.ObjectAt( i );
		package = PackageList.ObjectAt( pEntry.packageIndex );
		
		if ( !stricmp( package->packageName.c_str() , packageName.c_str() ) )
			return pEntry.packageIndex;
	}
	
	return -1;
}
Esempio n. 21
0
float Personality::GetTendency( const str &tendencyName )
{
	Tendency_t tendency;
	
	// First Make sure we don't already have this tendency
	for ( int i = 1 ; i <= _Tendencies.NumObjects() ; i++ )
	{
		tendency = _Tendencies.ObjectAt( i );
		
		if ( !Q_stricmp( tendencyName.c_str() , tendency.tendencyName.c_str() ) )
		{
			return tendency.tendencyValue;
		}
		
	}   
	
	//   gi.WDPrintf( "Actor %s, Entnum %d , has no tendency named %s", act->TargetName(), act->entnum , tendencyName.c_str() );
	return 0.0f;
}
Esempio n. 22
0
File: xss.cpp Progetto: gcubar/XKP
void dump_file(const str fname)
  {
    std::ifstream ifs(fname.c_str());

    str text;
    char buffer[1024];
    while(ifs.good())
      {
        ifs.getline(buffer, 1024);
        text += buffer;
        text += '\n';
      }

    dump_visitor visitor;
    xss_parser parser;
    parser.register_tag("xss:code");
    parser.register_tag("xss:e");

    parser.parse(text, &visitor);
  }
//
// Name:        RespondTo()
// Parameters:  const str &stimuli_name -- string name for the stimuli
//              qboolean respond -- Respond or Not to the stimuli
// Description: sets if the actor will respond to a particular stimulus
//
void SensoryPerception::RespondTo(const str &stimuli_name , qboolean respond )
{
	if ( !Q_stricmp( stimuli_name.c_str() , "sight" ) )
		RespondTo(StimuliSight , respond );
	else if ( !Q_stricmp( stimuli_name.c_str() , "sound" ) )
		RespondTo(StimuliSound , respond );
	else if ( !Q_stricmp( stimuli_name.c_str() , "pain" ) )
		RespondTo(StimuliPain , respond );
	else if ( !Q_stricmp( stimuli_name.c_str() , "script" ) )
		RespondTo(StimuliScript , respond );
	else if ( !Q_stricmp( stimuli_name.c_str() , "all" ) )
		RespondTo(StimuliAll , respond );
	else if ( !Q_stricmp( stimuli_name.c_str() , "none" ) )
		RespondTo(StimuliNone , respond );
}
//
// Name:        PermanentlyRespondTo
// Parameters:  const str &stimuli_name -- string name for the stimuli
//              qboolean respond -- Respond or Not to the stimuli
// Description: Allows the actor to ALWAYS respond or not to a particular stimulus
//              this allows us to make actors that are deaf or blind... etc
//
void SensoryPerception::PermanentlyRespondTo(const str &stimuli_name , qboolean respond )
{
	if ( !Q_stricmp( stimuli_name.c_str() , "sight" ) )
	{
		if ( respond )
			_permanent_stimuli |= StimuliSight;
		else
			_permanent_stimuli &= ~StimuliSight;
	}
	else if ( !Q_stricmp( stimuli_name.c_str() , "sound" ) )
	{
		if ( respond )
			_permanent_stimuli |= StimuliSound;
		else
			_permanent_stimuli &= ~StimuliSound;		
	}
	else if ( !Q_stricmp( stimuli_name.c_str() , "pain" ) )
	{
		if ( respond )
			_permanent_stimuli |= StimuliPain;
		else
			_permanent_stimuli &= ~StimuliPain;		
		
	}
	else if ( !Q_stricmp( stimuli_name.c_str() , "script" ) )
	{
		if ( respond )
			_permanent_stimuli |= StimuliScript;
		else
			_permanent_stimuli &= ~StimuliScript;		
		
	}
	else if ( !Q_stricmp( stimuli_name.c_str() , "all" ) )
	{
		if ( respond )
			_permanent_stimuli = StimuliAll;
		else
			_permanent_stimuli = StimuliNone;		
		
	}
	else if ( !Q_stricmp( stimuli_name.c_str() , "none" ) )
	{
		if ( respond )
			_permanent_stimuli = StimuliNone;
		else
			_permanent_stimuli = StimuliAll;
	}
}
Esempio n. 25
0
//
// Name:        UnregisterPackage
// Parameters:  str &packageName
// Description: Removes the package from the _BehaviorPackages container
//
void PackageManager::UnregisterPackage( const str &packageName )
{
	BehaviorPackageEntry_t pEntry;
	BehaviorPackageType_t *package;
	int index = 0;
	int i;
	
	for ( i = 1 ; i <= PackageList.NumObjects() ; i++ )
	{
		package = PackageList.ObjectAt( i );
		if ( !Q_stricmp( packageName.c_str() , package->packageName.c_str() ) )
			index = i;
	}
	
	for ( i = _BehaviorPackages.NumObjects() ; i > 0 ; i-- )
	{
		pEntry = _BehaviorPackages.ObjectAt( i );
		if ( pEntry.packageIndex == index )
			_BehaviorPackages.RemoveObjectAt( i );
	}
}
Esempio n. 26
0
//
// Name:        RegisterPackage
// Parameters:  str &packageName
// Description: Adds the package to the _BehaviorPackages container
//
void PackageManager::RegisterPackage( const str &packageName )
{
	BehaviorPackageEntry_t pEntry;
	BehaviorPackageType_t  *package;
	BehaviorPackageEntry_t *checkEntry;
	
	for ( int i = 1 ; i <= PackageList.NumObjects() ; i++ )
	{
		package = PackageList.ObjectAt( i );
		
		if ( !Q_stricmp( packageName.c_str() , package->packageName.c_str() ) )
		{
			// We have a match, let's check to make sure we're not doubling up
			for ( int j = 1 ; j <= _BehaviorPackages.NumObjects() ; j++ )
			{
				checkEntry = &_BehaviorPackages.ObjectAt( j );
				
				if ( checkEntry->packageIndex == i )
					return;
			}
			
			// We don't have a match, so lets add the package
			pEntry.currentScore     = 0;
			pEntry.lastScore        = 0;	
			pEntry.lastTimeExecuted = 0.0f;
			pEntry.priority         = 0.001f;
			pEntry.packageIndex     = i;
			
			_BehaviorPackages.AddObject( pEntry );
			
			// Make sure state machine gets cached properly
			
			CacheResource( package->stateFile, act );
			G_CacheStateMachineAnims( act, package->stateFile );
			
			return;
		}
	}
}
Esempio n. 27
0
int generateBoolOp(str op, str a, str b){
	generateP_AB(a, b);
	
	//w tym miejscu w REJ_A jest 'b', pierwszy w p_666
	
	if(op==S_GET){
		addCodeLine("SUB " + op_temp_a); // REJ_A=b-a
		addCodeLine("JG"); // if b-a > 0 <=> b > a -> skacz,
	}else if(op==S_EQ){
		addCodeLine("STORE " + op_temp_b);
		addCodeLine("SUB " + op_temp_a); // REJ_A=b-a
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SUB " + op_temp_b); // REJ_A=a-b
		addCodeLine("ADD " + op_temp_c); // w Z by sie to skrocilo; dla N wynik > 0 swiadczy o niezerowosci ktoregos ze skladnikow
		addCodeLine("JG"); //skaczemy gry (b-a) + (a-b) > 0, wtedy sa nierowne
	}else if(op==S_NEQ){
		addCodeLine("STORE " + op_temp_b);
		addCodeLine("SUB " + op_temp_a); // REJ_A=b-a
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("LOAD " + op_temp_a);
		addCodeLine("SUB " + op_temp_b); // REJ_A=a-b
		addCodeLine("ADD " + op_temp_c); // w Z by sie to skrocilo; dla N wynik > 0 swiadczy o niezerowosci ktoregos ze 
		addCodeLine("JZ");
	}else if(op==S_GT){
		addCodeLine("STORE " + op_temp_b);
		addCodeLine("SUB " + op_temp_a); // REJ_A = b-a
		addCodeLine("STORE " + op_temp_c);
		addCodeLine("LOAD " + op_temp_a); 
		addCodeLine("SUB " + op_temp_b); // REJ_A = a-b
		addCodeLine("SUB " + op_temp_c);
		addCodeLine("JZ");
	}else{
		return -1;
		if(ERR)printf("Nieznany operator %s", op.c_str());
	}
	jumper();
	return 0;
}
Esempio n. 28
0
void Personality::SetTendency( const str &tendencyName , float tendencyValue )
{
	Tendency_t *currentTendency;
	Tendency_t tendency;
	
	// First Make sure we don't already have this tendency
	for ( int i = 1 ; i <= _Tendencies.NumObjects() ; i++ )
	{
		currentTendency = &_Tendencies.ObjectAt( i );
		
		if ( !Q_stricmp( tendencyName.c_str() , currentTendency->tendencyName.c_str() ) )
		{
			currentTendency->tendencyValue = tendencyValue;         
			return;
		}
		
	}
	
	
	tendency.tendencyName = tendencyName;
	tendency.tendencyValue = tendencyValue;
	
	_Tendencies.AddObject( tendency );
}
Esempio n. 29
0
void PushViewer::OnRequestJoinServer(const str& server_address) {
	v_set(GetVariableScope(), kRtvarNetworkServeraddress, server_address);
	v_internal(UiCure::GetSettings(), kRtvarLoginIsserverselected, true);
	log_.Infof("Will use server %s when logging in.", server_address.c_str());
	CloseJoinServerView();
}
Esempio n. 30
0
//xml_read_archive
xml_read_archive::xml_read_archive(const str& xml, type_registry* types, size_t options):
  base_read_archive(types),
  options_(options)
  {
    doc_.Parse(xml.c_str());
  }