⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 printname.cpp

📁 一个非常好的人工智能开发工具开源软件
💻 CPP
字号:
/*** *** See the file "L2_RTI_EO1/disclaimers-and-notices-L2.txt" for  *** information on usage and redistribution of this file,  *** and for a DISCLAIMER OF ALL WARRANTIES. ***//** * Program printName */// #include <limits>#include <string>#include <strstream> // Stroustrup p. 640 says <sstream>#include "NameMapper.h"#include "enumapi.h"#define TELEMETRY 0#define L2SCRIPT  1const unsigned int ABSENT_ARG = static_cast<unsigned int>(ULONG_MAX);int mode; // mode of operation - telemetry or L2 scripts// can't find std::numeric_limits<unsigned int>::max();/** Standalone decoder. Use same enumapi.h file used by GPU TIS decoder. */char * process_L2_script (const char *buffer) {	char *output_buffer = (char*)malloc(256);	int  index = 0;	char *token_ptr[10], *string_ptr;	string_ptr = strdup(buffer);	while ((token_ptr[index]=strtok(string_ptr, "= ")) != NULL) {		string_ptr = NULL;		index++;	}	if (strstr (token_ptr[0], "assign")) {		if (atoi(token_ptr[2])==-1) {			strcat (output_buffer, "unassign ");			strcat (output_buffer, L2_model[atoi (token_ptr[1])].variable_name_primary);	// mode		} else {			strcat (output_buffer, token_ptr[0]);													// command			strcat (output_buffer, " ");			strcat (output_buffer, L2_model[atoi (token_ptr[1])].variable_name_primary);			// component			strcat (output_buffer, "=");			strcat (output_buffer, L2_model[atoi (token_ptr[1])].variable_values_primary [atoi (token_ptr[2])]);	// mode		}	} else {		if (strstr (token_ptr[0], "progress")) {		strcat (output_buffer, token_ptr[0]); 												// command		strcat (output_buffer, " ");		strcat (output_buffer, L2_model[atoi (token_ptr[1])].variable_name_primary);			// component		strcat (output_buffer, "=");		strcat (output_buffer, L2_model[atoi (token_ptr[1])].variable_values_primary [atoi (token_ptr[2])]);	// mode		} else {			strcpy (output_buffer, buffer);		}	}  return (output_buffer);}char * process_telemetry (const char *buffer) {  /* our pointer array to point to the tokens extracted */  /*char output_buffer[256]="";*/  char *output_buffer = (char*)malloc(256);  char *token_ptr[10],*string_ptr;  string_ptr = strdup(buffer);  int index=0;  /* Filter out ROS strings and just copy them directly to the output file */  if (strstr (buffer, "ROS:")) {	  strcpy (output_buffer, buffer);  }  else {		  /*string_ptr point to the start of the string */		  while ((token_ptr[index]=strtok(string_ptr, "! ,")) != NULL)			{			  string_ptr=NULL;			  index++;			}		  switch (atoi(token_ptr[0]))			{			case 1:			  strcat(output_buffer,"timestep");			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[1]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[2]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[3]);			  break;			case 2: strcat(output_buffer,"observation");			  strcat(output_buffer,",");			  strcat(output_buffer,L2_model[atoi(token_ptr[1])].variable_name_primary);			  strcat(output_buffer,",");			  if (atoi(token_ptr[2])==-1) {strcat(output_buffer,"unknown");}			  else strcat(output_buffer,L2_model[atoi(token_ptr[1])].variable_values_primary[atoi(token_ptr[2])]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[4]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[5]);			  break;			case 3: strcat(output_buffer,"findCandidates");			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[1]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[2]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[3]);			  break;			case 4: strcat(output_buffer,"candidate");			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[1]);			  break;			case 5: strcat(output_buffer,"transition");			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[1]);			  strcat(output_buffer,",");			  if (atoi(token_ptr[2])==-1) {			strcat(output_buffer,"state");			strcat(output_buffer,",");			strcat(output_buffer,"s");			strcat(output_buffer,token_ptr[3]);			  }			  else {			if ((atoi(token_ptr[4])==3) |				(atoi(token_ptr[4])==6) |				(atoi(token_ptr[4])==2) |				(atoi(token_ptr[4])==7) |				(atoi(token_ptr[4])==0))			  {strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_name_primary);}			else			  {strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_name_secondary);};			strcat(output_buffer,",");			if ((atoi(token_ptr[4])==3) |				(atoi(token_ptr[4])==6) |				(atoi(token_ptr[4])==2) |				(atoi(token_ptr[4])==7) |				(atoi(token_ptr[4])==0))			  {strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_values_primary[atoi(token_ptr[3])]);}			else			  {strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_values_secondary[atoi(token_ptr[3])]);}}			  break;			case 6: strcat(output_buffer,"endCandidate");			  break;			case 7: strcat(output_buffer,"endFindCandidates");			  break;			case 8: strcat(output_buffer,"command");			  strcat(output_buffer,",");			  strcat(output_buffer,L2_model[atoi(token_ptr[1])].variable_name_primary);			  strcat(output_buffer,",");			  strcat(output_buffer,L2_model[atoi(token_ptr[1])].variable_values_primary[atoi(token_ptr[2])]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[3]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[4]);			  break;			case 99:			case 9: strcat(output_buffer,"assignment");			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[1]);			  strcat(output_buffer,",");			  strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_name_secondary);			  strcat(output_buffer,",");			  strcat(output_buffer,L2_model[atoi(token_ptr[2])].variable_values_secondary[atoi(token_ptr[3])]);			  strcat(output_buffer,",");			  strcat(output_buffer,token_ptr[4]);			  break;			default :			  printf("UNKNOWN op CODE: %s", token_ptr[0]);			  break;};		  /*printf("Output buffer: %s\n", output_buffer);*/	 } /* end else */  return (output_buffer);}void mainLoop(istream& telemetryInputStream) {  string line;  char * temp_result;  while (!getline(telemetryInputStream, line).eof()) {    if (line.length() == 0) {      cout << " " << endl;}    else {      /*cout << line.c_str() << endl;*/      switch (mode) {		  case TELEMETRY:      		temp_result = process_telemetry (line.c_str());      		break;      	  case L2SCRIPT:      	    temp_result = process_L2_script (line.c_str());      	    break;      	  default:      	  	cerr << "Unknown mode" << endl;			exit (1);			break;	  }      cout << temp_result << endl;    }  }}/** * What to do if there is other than 1 command-line argument */void usage() {  cerr << "usage: printName model_file -telemetry | -L2script" << endl;}/** * Read in the model from the file whose pathname is argv[1], create a name mapper, * and call the main loop to expand each line of standard input. */int main(int argc, char* argv[]) {  if (argc != 3) {    usage();    exit(1);  }  if (strcmp (argv[2], "-telemetry")==0) {		mode = TELEMETRY;	} else {		if (strcmp (argv[2], "-L2script")==0) {			mode = L2SCRIPT;		} else {			cerr << "Unknown mode" << endl;			exit (1);		}  }  istream& telemetryInputStream = cin;  mainLoop(telemetryInputStream);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -