std::string JsonUtils::MapLayerJson(const MapLayerJSConfig::Layer& layer,
                                    const DbHeader& db_header,
                                    const std::string& locale) {
  // Get the legend for the specified locale.
  const LegendLocale& legend_locale = layer.legend_.GetLegendLocale(locale);
  // Create the map of field name-value pairs for the output JSON.
  std::string icon_name =
      "icons/" + legend_locale.icon.GetValue().LegendHref();
  bool is_imagery = (layer.type_ == MapLayerJSConfig::Layer::Imagery);
  double opacity = 1.0;
  std::map<std::string, std::string> field_map;
  field_map["id"] = Itoa(layer.channel_id_);
  field_map["version"] = Itoa(layer.index_version_);
  field_map["label"] = Quoted(legend_locale.name.GetValue());
  field_map["icon"] = Quoted(icon_name);
  field_map["initialState"] =
    JsonUtils::JsonBool(legend_locale.isChecked.GetValue());
  field_map["isPng"] = JsonUtils::JsonBool(!is_imagery);
  field_map["opacity"] = DoubleToString(opacity);

  field_map["requestType"] = Quoted(
      MapLayerRequestType(db_header.is_mercator_, layer));

  // TODO: add new locale fields
  // opacity (needs locale entry and ui)
  // look_at (needs ui)
  std::string lookAt(legend_locale.lookAt.GetValue().utf8());
  field_map["lookAt"] = JsonUtils::LookAtJson(lookAt);
  return JsonObject(field_map);
}
Example #2
0
ErrInf::ErrInf(const char *str, StreamManip &manip) {
    char tmp[256];
    reason = string(str).append("\nIt occured in line ");
    reason.append(Itoa(manip.GetLine(), &tmp[0], 10));
    reason.append(" position ");
    reason.append(Itoa(manip.GetPos(), &tmp[0], 10));
    reason.append("\n");
};
Example #3
0
void CfgLoad()
{
	std::strcpy(cfgW, Itoa(get_config_int("gfxmode", "width", 640)).c_str());
	std::strcpy(cfgH, Itoa(get_config_int("gfxmode", "height", 480)).c_str());
	cfgFull = get_config_int("gfxmode", "fullscreen", 0);
	cfgZoom = get_config_int("gfxmode", "zoomin", 0);
	LoadControls();
}
Example #4
0
int main(void) {
    Itoa(123456789, BUFFER, BUFFER_SIZE);
    printf("%s\n", BUFFER);

    Itoa(0, BUFFER, 256);
    printf("%s\n", BUFFER);

    getchar();
    return 0;
}
Example #5
0
const char* PacketLogger::UserIDTOString(unsigned char Id)
{
	// Users should override this
	static char str[256];
	Itoa(Id, str, 10);
	return (const char*) str;
}
Example #6
0
void SystemAddress::ToString(bool writePort, char *dest) const
{
	if (*this==UNASSIGNED_SYSTEM_ADDRESS)
	{
		strcpy(dest, "UNASSIGNED_SYSTEM_ADDRESS");
		return;
	}

#if defined(_XBOX) || defined(X360)
                                                                                                                      
#else

	
	in_addr in;
	in.s_addr = binaryAddress;
//	cellSysmoduleLoadModule(CELL_SYSMODULE_NETCTL);
//	sys_net_initialize_network();
	const char *ntoaStr = inet_ntoa( in );
	strcpy(dest, ntoaStr);
	if (writePort)
	{
		strcat(dest, ":");
		Itoa(port, dest+strlen(dest), 10);
	}
#endif
}
 // Test the CachedReadAccessor Pread() method.
 // This is the main method exposed by CachedReadAccessor.
 bool TestCachedReadAccessorPreadPerformance() {
   uint32 segment_id = 0;
   // Read request that is contained in 1 block.
   FileBundleReaderSegment segment(file_pool_,
                                   path_base_,
                                   segment_names_[segment_id],
                                   segment_names_[segment_id],
                                   segment_id);
   uint32 request_count = 1500; // typical 1500B for some Fusion packets.
   uint32 best_mb_per_sec = 0;
   uint32 best_kilobytes = 0;
   for(uint32 bytes = 1 << 14; bytes < 1 << 22; bytes <<= 1) {
     uint32 kilobytes = bytes / 1024;
     std::string prefix = "Cached read 2x " + Itoa(kilobytes) + "KB";
     uint32 mb_per_sec = TestReadAll(segment, request_count, 2, bytes, prefix);
     if (mb_per_sec > best_mb_per_sec) {
       best_mb_per_sec = mb_per_sec;
       best_kilobytes = kilobytes;
     }
   }
   uint32 uncached_mb_per_sec = TestReadAll(segment, request_count, 0, 0,
               std::string("Uncached read"));
   if (best_mb_per_sec > uncached_mb_per_sec) {
     std::cerr << "Cached is optimal " << best_mb_per_sec <<
       " MB/sec cached with " << best_kilobytes << "KB buffers vs Uncached "
       << uncached_mb_per_sec << " MB/sec" << std::endl;
   } else {
     std::cerr << "Uncached is optimal " << uncached_mb_per_sec <<
       " MB/sec vs Cached " << best_mb_per_sec << " MB/sec with " <<
       best_kilobytes << "KB buffers" << std::endl;
   }
   return true;
 }
Example #8
0
const char *SystemAddress::ToString(bool writePort) const
{
	if (*this==UNASSIGNED_SYSTEM_ADDRESS)
		return "UNASSIGNED_SYSTEM_ADDRESS";

#ifdef _XBOX360
	return "";
#else
	static unsigned char strIndex=0;
	static char str[8][22];
	in_addr in;
	in.s_addr = binaryAddress;
	strcpy(str[strIndex], inet_ntoa( in ));
	if (writePort)
	{
		strcat(str[strIndex], ":");
		Itoa(port, str[strIndex]+strlen(str[strIndex]), 10);
	}

	unsigned char lastStrIndex=strIndex;
	strIndex++;
	if (strIndex==8)
		strIndex=0;
	
	return (char*) str[lastStrIndex];
#endif
}
Example #9
0
string Lex_Result::ToString() {
    char tmp[256];
    string res;
    res.append(" res_type ")
        .append(max<double>(13 - strlen(type_names[res_type]), 0), ' ')
        .append(type_names[res_type]);
    res.append(" res_int ").append(Itoa(res_int, tmp, 10));
    res.append(" res_val ").append(Gcvt(res_val, 12, tmp));
    res.append(" res_str ").append(res_str).append("\n");
    return res;
}
Example #10
0
void Painting::SetParameter(std::string p, std::string v)
{
	if(p == "file")
	{
        file = std::atoi(v.c_str());
        std::string canvasFileName = "saves/game";
        canvasFileName += Itoa(file + 1);
        canvasFileName += ".bmp";
        canvas = load_bitmap(canvasFileName.c_str(), 0);
		return;
	}
	Entity::SetParameter(p, v);
}
std::string JsonUtils::LookAtJson(const std::string& lookAtSpec) {
  if (lookAtSpec.empty())
    return Quoted(std::string("none"));
  // LookAtSpec format is :
  // longitude|latitude|altitude|...
  // we only care for these 3.
  std::vector<std::string> tokens;
  TokenizeString(lookAtSpec, tokens, "|");

  double altitude = strtod(tokens[2].c_str(), NULL);
  int zoomLevel = AltitudeToZoomLevel(altitude);

  // Create the map of field name-value pairs for the output JSON.
  std::map<std::string, std::string> field_map;
  field_map["lat"] = tokens[1];
  field_map["lng"] = tokens[0];
  field_map["zoom"] = Itoa(zoomLevel);
  field_map["altitude"] = DoubleToString(altitude);
  return JsonObject(field_map);
}
int IsPalindrome(int num)
{
    char *str = (char *) malloc(2*DIGITS);
    //printf("IsPalindrome num = %d\n",num);
    Itoa(num, str);
    int len = strlen(str);
    
    //printf("IsPalindrome str = %s\n",str);
    int start = 0;
    int end = len-1; 
    
    while(start < end)
    {
        if(str[start] != str[end])
        {
            return 0;
        }
        start++;
        end--;
    }
    return 1;
}
RNS2BindResult RNS2_Berkley::BindSharedIPV4And6( RNS2_BerkleyBindParameters *bindParameters, const char *file, unsigned int line ) {
	
	(void) file;
	(void) line;
	(void) bindParameters;

#if RAKNET_SUPPORT_IPV6==1

	int ret=0;
	struct addrinfo hints;
	struct addrinfo *servinfo=0, *aip;  // will point to the results
	PrepareAddrInfoHints2(&hints);
	hints.ai_family=bindParameters->addressFamily;
	char portStr[32];
	Itoa(bindParameters->port,portStr,10);

	// On Ubuntu, "" returns "No address associated with hostname" while 0 works.
	if (bindParameters->hostAddress && 
		(_stricmp(bindParameters->hostAddress,"UNASSIGNED_SYSTEM_ADDRESS")==0 || bindParameters->hostAddress[0]==0))
	{
		getaddrinfo(0, portStr, &hints, &servinfo);
	}
	else
	{
		getaddrinfo(bindParameters->hostAddress, portStr, &hints, &servinfo);
	}

	// Try all returned addresses until one works
	for (aip = servinfo; aip != NULL; aip = aip->ai_next)
	{
		// Open socket. The address type depends on what
		// getaddrinfo() gave us.
		rns2Socket = socket__(aip->ai_family, aip->ai_socktype, aip->ai_protocol);

		if (rns2Socket == -1)
			return BR_FAILED_TO_BIND_SOCKET;

		ret = bind__(rns2Socket, aip->ai_addr, (int) aip->ai_addrlen );
		if (ret>=0)
		{
			// Is this valid?
			memcpy(&boundAddress.address.addr6, aip->ai_addr, sizeof(boundAddress.address.addr6));

			freeaddrinfo(servinfo); // free the linked-list

			SetSocketOptions();
			SetNonBlockingSocket(bindParameters->nonBlockingSocket);
			SetBroadcastSocket(bindParameters->setBroadcast);

			GetSystemAddressIPV4And6( rns2Socket, &boundAddress );
			
			return BR_SUCCESS;
		}
		else
		{
			closesocket__(rns2Socket);
		}
	}
	
	return BR_FAILED_TO_BIND_SOCKET;

#else
return BR_REQUIRES_RAKNET_SUPPORT_IPV6_DEFINE;
#endif
}
Example #14
0
enum Command getCommand()
{
	unsigned char getAngleX[] = {"getanglex"};
	unsigned char getAngleY[] = {"getangley"};
	unsigned char getAngleZ[] = {"getanglez"};
	unsigned char getOsTime[] = {"getostime\0"};
	unsigned char getDistanceToGround[] = {"getdtg"};
	unsigned char getAllCommands0[] = {"?"};
	unsigned char getAllCommands1[] = {"--help"};
	unsigned char getAllCommands2[] = {"--h"};
	unsigned char getStatusAllTasks[] = {"getstatustasks"};
	unsigned char stopTaskWithId[] = {"stoptask"};
	unsigned char* lrc = lastReceivedCommand();

	char c2[10];
	Itoa(Strlen(lrc),c2,10);
	WriteDebugInfo(c2);
	WriteDebugInfo("<-\n\r");
	Itoa(Strlen(stopTaskWithId),c2,10);
	WriteDebugInfo(c2);
	WriteDebugInfo(lrc);
	WriteDebugInfo("<-\n\r");

	//check if there are spaces in lrc
	int i;
	int spacePosition[COMMANDLENGTH];
	int amountOfSpaces = 0;
	int lengthLrc = Strlen(lrc);
	for (i=0;i<lengthLrc;i++)
	{
		if (lrc[i] == ' ')
		{
			spacePosition[amountOfSpaces] = i;
			amountOfSpaces++;
		}
	}
	//get first command
	unsigned char firstCommand[spacePosition[0]+1];
	if (amountOfSpaces > 0)
	{
		int j;
		for (j=0;j<spacePosition[0];j++)
		{
			firstCommand[j] = lrc[j];
		}
		firstCommand[j] = '\0';
	}

	if (sameString(getAngleX,lrc))
	{
		return CommandRotationX;
	}
	else if (sameString(getAngleY,lrc))
	{
		return CommandRotationY;
	}
	else if (sameString(getAngleZ,lrc))
	{
		return CommandRotationZ;
	}
	else if (sameString(getOsTime,lrc))
	{
		return commandOsTime;
	}
	else if (sameString(getDistanceToGround,lrc))
	{
		return commandDistanceToGround;
	}
	else if (sameString(getAllCommands0,lrc) || sameString(getAllCommands1,lrc) || sameString(getAllCommands2,lrc))
	{
		return CommandHelp;
	}
	else if (sameString(getStatusAllTasks,lrc))
	{
		return CommandAllTaskStatus;
	}
	else if (sameString(stopTaskWithId,firstCommand))
	{
		//get fisrt parameter
		unsigned char firstParam[spacePosition[1]-(spacePosition[0])];
		if (amountOfSpaces > 1)
		{
			int j;
			for (j=spacePosition[1]+1;j<spacePosition[1]-(spacePosition[0]);j++)
			{
				firstParam[j-spacePosition[0]+1] = lrc[j-spacePosition[0]];
			}
			firstParam[j-spacePosition[0]] = '\0';
		}
		char c[10];
		Itoa(spacePosition[1],c,10);
		getFirstParameter(firstParam);
		return CommandStopTaskWithId;
	}
	else if (lrc[0] != '\0'){
		WriteDebugInformation(lrc,DirectDebug);
		WriteDebugInformation("Not a valid command.\n\r/>", DirectDebug);
		clearLastCommand();
	}
	return CommandNoCommand;
}
Example #15
0
int Printf (char* messageVoulu, ...){

	int i = 0, j = 0, k;
	int variable, nbArg;
	char *value;
	char buffer[MAX_LENGTH];
	int alloue = 0;
	arg_list alist;


	alist = arg_start ();
	nbArg = 0;

	// tant que l'on est pas a la fin du message
	while (messageVoulu[i] != '\0') {
		// si on a un %, il faut recuperer la variable
		// la transformer en chaine et la rajouter au resultat
		if (messageVoulu[i] == '%') {
			nbArg++;

			if (nbArg < 4) {
				i++;
				variable = arg_arg (alist);

				switch (messageVoulu[i]) {
				case 'd': // un entier
					value = Itoa (variable);
					alloue = 1;
					break;

				case 'i':
					value = Itoa (variable);
					alloue = 1;
					break;

				case 'c':
					value = malloc(2*sizeof(char));
					if(value == 0)
						return -1;
					value[0] = (char) variable;
					value[1] = '\0';
					alloue = 1;
					break;

				case 's': // un string
					value = (char*) variable;
					break;

				default:
					PutString("argument %");
					PutChar(messageVoulu[i]);
					PutString(" invalide\n");
					return -1;
					break;
				}

				k = 0;
				while (value[k] != '\0') {
					buffer[j] = value[k];
					j++;
					k++;
				}
			}
			else // si on veut lire un 4eme argument
			{
				if(alloue)
					free(value);
				arg_end(alist);
				return -1;
			}
		}
		else {
			buffer[j] = messageVoulu[i];
			j++;
		}

		i++;
	}
	PutString(buffer);

	// on vide le buffer (sinon, il y a des affichages en trop
	for (i = 0; i < MAX_LENGTH; i++) {
		buffer[i] = '\0';
	}
	if(alloue)
		free(value);
	arg_end(alist);

	return 0;
}