Пример #1
0
std::vector<size_t> SentenceSplitter::split(const std::wstring& i_line_to_split)
{
    std::vector<size_t> result;

    boost::wregex re_non_letter_symbols(L"[[:punct:]]");
    boost::wsregex_iterator m1(i_line_to_split.begin(), i_line_to_split.end(), re_non_letter_symbols);
    boost::wsregex_iterator m2;
    std::for_each(m1, m2,
        [this, &i_line_to_split, &result](const boost::match_results<std::wstring::const_iterator>&  entry) mutable
        {
            if(this->testEntryOnSentenceSplit_(entry.position(size_t(0)), i_line_to_split))
            {
                result.push_back(entry.position(size_t(0)));
            }
        });

    return result;
}
    /**
        Consumes any whitespace in the stream until data is encountered. It then
        consumes data enclosed in double quotes returns.

        \param[in] data Data to consume.

        \throws PersistUnexpectedDataException if data is not the next data in the
                stream.

        In the stream, data between the double quote characters is expected to be
        xml-encoded so that all special characters are encoded with \&...;
        e.g. double quote character is encoded as \&quote;
    */
    void SCXFilePersistDataReader::ConsumeString(const std::wstring& data)
    {
        try {

            wchar_t ch = GetUTF8CharSkipLeadingWS();

            // Expect a '"' to start the string
            if (ch != L'\"')
            {
                throw PersistUnexpectedDataException(L"\"",
                                                     m_Stream->tellg(), SCXSRCLOCATION);
            }


            // Read stream char-by-char and match it to the argument-string
            for (std::wstring::const_iterator iter = data.begin();
                 iter != data.end();
                 ++iter)
            {
                ch = GetUTF8Char();
                if (L'&' == ch)
                {
                    ch = ConsumeEncodedChar();
                }
                if (ch != *iter)
                {
                    throw PersistUnexpectedDataException(data, m_Stream->tellg(), SCXSRCLOCATION);
                }
            }

            // Expect a '"' to end the string
            if (GetUTF8Char() != L'\"')
            {
                throw PersistUnexpectedDataException(L"\"",
                                                     m_Stream->tellg(), SCXSRCLOCATION);
            }

        } catch (SCXLineStreamContentException& e) {
            // If an invalid UTF-8 sequnce is encountered, including bad
            // file state or EOF.
            throw PersistUnexpectedDataException(L"\".*\"",
                                                 m_Stream->tellg(), SCXSRCLOCATION);
        }
    }
Пример #3
0
std::string toUTF8(const std::wstring& s)
{
  std::string result;
  result.reserve(s.length() * 3);

  char buf[4];
  for (std::wstring::const_iterator i = s.begin(); i != s.end(); ++i) {
    char *end = buf;
    try {
      rapidxml::xml_document<>::insert_coded_character<0>(end, *i);
      for (char *b = buf; b != end; ++b)
	result += *b;
    } catch (rapidxml::parse_error& e) {
      LOG_ERROR("toUTF8(): " << e.what());
    }
  }

  return result;
}
Пример #4
0
std::string CodeConv::to_str(std::wstring const& in, char oob)
{
  // If your boost version is equal or greater than 1.34, you can use
  // lexical_cast<string>(). But boost 1.33's lexical_cast has bug.

  std::string str;
  for (std::wstring::const_iterator i = in.begin(); i != in.end(); ++i) {
    if (*i > std::numeric_limits<char>::max()) {
      if (oob == 0)
	throw Exception0(Exception::E_CONV_INV_SEQ);
      str += oob;
    }
    else {
      str += static_cast<char>(*i);
    }
  }

  return str;
}
Пример #5
0
void Socket::connect(const std::wstring &server) {
	struct sockaddr_un remote;
	socklen_t len;

	if ((d->socket = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
		return;
	}
	std::string name = "/tmp/" + std::string(server.begin(), server.end());
	remote.sun_family = AF_UNIX;
	strcpy(remote.sun_path, name.c_str());

	len = SUN_LEN(&remote);
	if (connectWrapper(d->socket, (struct sockaddr *)&remote, len) == -1) {
		return;
	}

	TelldusCore::MutexLocker locker(&d->mutex);
	d->connected = true;
}
Пример #6
0
bool create_sr(int wkid, std::wstring wkt, ISpatialReference **ppSR)
{
  CComPtr<ISpatialReferenceFactory3> ipSpatialRefFactory; ipSpatialRefFactory.CoCreateInstance(CLSID_SpatialReferenceEnvironment);
  CComPtr<ISpatialReference> ipSR;

  if (wkid > 0)
  {
    ipSpatialRefFactory->CreateSpatialReference(wkid, &ipSR);
  }
  else
  {
    if (!wkt.empty())
    {
      long dw;
      struct eq
      {
        static bool op(const wchar_t &c) { return c == L'\''; }
      };
      std::replace_if(wkt.begin(), wkt.end(), eq::op, L'\"');
      CComBSTR bstr(wkt.c_str());
      HRESULT hr = ipSpatialRefFactory->CreateESRISpatialReference(bstr, &ipSR, &dw);
      if (FAILED(hr))
      {
        CComPtr<ISpatialReferenceInfo> ipSRInfo;
        if (FAILED(ipSpatialRefFactory->CreateESRISpatialReferenceInfoFromPRJ(bstr, &ipSRInfo)))
          return false;
        long fcode = 0;
        ipSRInfo->get_FactoryCode(&fcode);
        if (FAILED(ipSpatialRefFactory->CreateSpatialReference(fcode, &ipSR)))
          return false;
      }
    }
  }
  if (ipSR == NULL)
    ipSR.CoCreateInstance(CLSID_UnknownCoordinateSystem);
  CComQIPtr<ISpatialReferenceResolution> ipSRR(ipSR);
  if (ipSRR)
    FIX_DEFAULT_SR(ipSRR);
  *ppSR = ipSR.Detach();
  return *ppSR != nullptr;
}
Пример #7
0
  bool matchStrings(std::wstring nameControlPanel, std::string nameEDID) {
    std::string nameCP;
    nameCP.assign(nameControlPanel.begin(), nameControlPanel.end());
    std::transform(nameCP.begin(), nameCP.end(), nameCP.begin(), toupper);

    // Remove spaces at the end of nameEDID
	if (nameEDID.length() > 0)
	{
		while (nameEDID[ nameEDID.length()-1] == ' ')
		  nameEDID.erase(nameEDID.length()-1,1);
	}

    std::transform(nameEDID.begin(), nameEDID.end(), nameEDID.begin(), toupper);

    size_t found;
    found=nameCP.find(nameEDID);
    if (found!=std::string::npos)
      return true;
    else
      return false;
  }
Пример #8
0
std::shared_ptr<MeshData> RE::FileSystem::LoadModel(const std::wstring &filePath)
{
    const std::string sFilePaths{ filePath.begin(), filePath.end() };
    Assimp::Importer importer;

    const aiScene *scene = importer.ReadFile(sFilePaths,
        aiProcess_CalcTangentSpace | 
        aiProcess_Triangulate | 
        aiProcess_JoinIdenticalVertices |
        aiProcess_SortByPType | 
        aiProcess_ConvertToLeftHanded |
        aiProcess_FixInfacingNormals
        );
   
    if (!scene)
    {
        Log::Get().Write(std::string("[FileSystem] Assimp importer could not read mesh file:") + importer.GetErrorString());
    }

    return std::make_shared<MeshData>(ProcessAssimpScene(scene->mRootNode, scene));
}
Пример #9
0
  BINLINE int32_t BBuffer::getStringLengthUtf8(const ::std::wstring& str) {

    int32_t p = 0;

    for (wstring::const_iterator it = str.begin(); it != str.end(); it++) {

      wchar_t c = (*it);

      if (c <= 0x7F) {
        p++;
      }
      else if (c >= 0x80 && c <= 0x07FF) {
        p += 2;
      }
      else { // if (c >= 0x800 && c <= 0xFFFF) {
        p += 3;
      }
    }

    return p;
  }
Пример #10
0
std::string toString(std::wstring ws)
{
#ifdef TNZCORE_LIGHT
	std::string s;
	s.assign(ws.begin(), ws.end());
	return s;
#else

	QString qString = QString::fromStdWString(ws);

// Test if 'ws' is not unicode (UTF-8)
#if 0
  if(qString.toAscii() == qString)
#else
	if (qString.toLatin1() == qString)
#endif
	return qString.toStdString();

	QByteArray a = qString.toUtf8();
	return std::string(a);
#endif
}
Пример #11
0
/**
 *
 *  Load SYSTEM hive to memory
 *  Returns TRUE or FALSE
 *
 */
BOOL SystemKey::Load (std::wstring fname) {
  UnLoad();
  
  if (!bRestore) {
    bRestore = SetPrivilege (L"SeRestorePrivilege", TRUE);
  }
  
  if (bRestore) {
    dprintf("\nChecking %s", std::string(fname.begin(), fname.end()).c_str());
    DWORD dwAttr = GetFileAttributes (fname.c_str());
    if (dwAttr != INVALID_FILE_ATTRIBUTES) {
      dwError = RegLoadKey (HKEY_LOCAL_MACHINE, L"$$_SYSTEM", fname.c_str());
      if (dwError == ERROR_SUCCESS) {
        regFile = L"$$_SYSTEM";
        bLoaded = TRUE;
      }
    } else {
      dwError = GetLastError ();
    }
  }
  return dwError == ERROR_SUCCESS;
}
bool public_nbs::trunc_str( const std::wstring& source, std::string& dest )
{
	bool res = true;
	dest.resize( source.size(), ' ' );

	std::string::iterator b = dest.begin();
	std::wstring::const_iterator i = source.begin();
	std::wstring::const_iterator e = source.end();
	for( ; i != e; ++i, ++b )
	{
		if( *i < std::numeric_limits<std::string::value_type>::min() || 
			*i > std::numeric_limits<std::string::value_type>::max() ) 
		{
			res = false;
		} 
		else 
		{
			*b = (std::string::value_type)*i;
		}
	}
	return res;
}
Пример #13
0
void BootStrap::find_and_replace( std::wstring &input, std::map<WCHAR, std::wstring> &replacements) const
{
    std::wostringstream oss;
    std::map<WCHAR, std::wstring>::iterator specialCharIt;

    for( std::wstring::iterator stringIter = input.begin(); stringIter != input.end(); stringIter++ )
    {
        if( *stringIter < 0x20 )
        {
            oss << ' ';
            continue;
        }

        specialCharIt = replacements.find( *stringIter );
        if ( specialCharIt == replacements.end() )
            oss << *stringIter;
        else
            oss << specialCharIt->second;
        
    }

    input = oss.str();
}
Пример #14
0
	bool install() {
		char winDir[MAX_PATH];
		GetSystemDirectoryA(winDir,sizeof(winDir));
		strcat(winDir,"\\msiexec.exe");
		std::string tmp(m_msiFile.length(),'0');
		std::copy(m_msiFile.begin(),m_msiFile.end(),tmp.begin());
		std::string param(std::string("/I \"") 
			+ tmp + "\" REINSTALLMODE=vomus REINSTALL=ALL");
		ProcessStarter msiexec(winDir,param);
		return msiexec.Run(true);
/*		MsiSetInternalUI(INSTALLUILEVEL_FULL,0);
		UINT retCode = MsiReinstallProduct(prodCode, 
				REINSTALLMODE_FILEREPLACE |
				REINSTALLMODE_MACHINEDATA|
				REINSTALLMODE_USERDATA |
				REINSTALLMODE_SHORTCUT |
				REINSTALLMODE_PACKAGE); 
		if (retCode == ERROR_UNKNOWN_PRODUCT) {
			const wchar_t *pack = m_msiFile.c_str();
			retCode = MsiInstallProduct(pack,L"ACTION=INSTALL");
			}*/
//		return retCode == ERROR_SUCCESS;
		}
Пример #15
0
 IntegralValue::IntegralValue(std::wstring s, int width, bool sign)
 {
   assert(s.size() > 0);
   wchar_t base = '\0';
   if(s.size() > 2 and s[0] == L'0' and !is_digit(s[1]))
   {
     base = s[1];
     s.erase(0, 2);
   }
   std::string t = "";
   std::transform(s.begin(), s.end(), std::back_inserter(t), digit_utf_to_ascii);
   unsigned char radix = 10;
   switch(base)
   {
     case L'\0': radix = 10; break;
     case L'x':  radix = 16; break;
     case L'b':  radix = 2;  break;
     case L'o':  radix = 8;  break;
     default: assert(false && "Compilation error - unsupported radix character");
   }
   auto srt = llvm::StringRef(t);
   value = llvm::APSInt(llvm::APInt(width, srt, radix), !sign);
 }
Пример #16
0
  //Taken from boost::json
  std::string add_esc_chars(const std::wstring& s)
  {
    typedef std::wstring::const_iterator Iter_type;
    typedef std::wstring::value_type     Char_type;

    std::string result;
    const Iter_type end( s.end() );

    for(Iter_type i = s.begin(); i != end; ++i)
    {
      const Char_type c(*i);
      if(add_esc_char(c, result))
        continue;
      const wint_t unsigned_c((c >= 0) ? c : 256 + c);

      // 127 is the end of printable characters in ASCII table.
      if(iswprint(unsigned_c) && unsigned_c < 127)
        result += c;
      else
        result += non_printable_to_string(unsigned_c);
    }
    return result;
  }
Пример #17
0
Socket::Socket(std::wstring domain, int port)
{
	printf("Original available port #%d \n", port);
	int findAvailablePort = port;
	//while (!IsPortAvailable(domain, findAvailablePort))
	//{
	//	findAvailablePort++;
	//	printf("Trying port #%d \n", findAvailablePort);
	//}
	printf("Found available port #%d \n", findAvailablePort);

	// Initialize Winsock
	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (iResult != 0) {
		printf("WSAStartup failed with error: %d\n", iResult);
		return;
	}
	
	m_currentPort = findAvailablePort;

	ZeroMemory(&hints, sizeof(hints));
	hints.ai_family = AF_INET;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;
	hints.ai_flags = AI_PASSIVE;

	PCSTR m_port = (PCSTR)findAvailablePort;
	std::string addr(domain.begin(), domain.end());
	// Resolve the server address and port
	iResult = getaddrinfo(addr.c_str(), m_port, &hints, &result);
	if (iResult != 0) {
		printf("getaddrinfo failed with error: %d\n", iResult);
		WSACleanup();
		return;
	}
	return;
}
Пример #18
0
bool Utf8toWStr(const std::string& utf8str, std::wstring& wstr, size_t max_len)
{
    if (utf8str.empty())
    {
        wstr = std::wstring();
        return true;
    }

    try
    {
        // A UTF8 string can have a maximum of 4 octets per character
        // A 4 octet char can take up to two UTF16 characters (4*8 = 32 / 16 = 2)
        // The UTF8 string may also actually be ASCII, in which case no truncation
        // takes place! The final string length is therefore unknown. Reserve
        // as long as the OG string, and back-insert
        wstr.resize(utf8str.size());

        auto end = utf8::utf8to16(utf8str.cbegin(), utf8str.cend(), wstr.begin());

        if (end != wstr.end())
            wstr.erase(end, wstr.end());

        // truncate to max len
        if (!!max_len && wstr.size() > max_len)
        {
            wstr.resize(max_len);
        }
    }
    catch (const std::exception&)
    {
        wstr = L"";
        return false;
    }

    return true;
}
Пример #19
0
perlRegex::perlRegex(const std::wstring& inRegex) : regexString(inRegex)
{
    regex = boost::xpressive::wsregex::compile(inRegex.begin(), inRegex.end(), boost::xpressive::regex_constants::icase | boost::xpressive::regex_constants::optimize);
}
Пример #20
0
void stripEscapes(std::wstring& input)
{
    std::remove_if(input.begin(), input.end(), std::bind2nd(std::equal_to<wchar_t>(), L'`'));
}
Пример #21
0
// UNICODEのアルファベットを全て大文字に変換
bool unicode_to_upper( std::wstring& str )
{
	std::transform( str.begin(),str.end(),str.begin(),towupper );
	return true;
}
Пример #22
0
    std::vector<std::wstring> CommandLineParser::scan(const std::wstring &commandLine)
    {
        std::vector<std::wstring> words;

        enum
        {
            NEW_WORD,
            IN_WORD,
            IN_QUOTATION,
            AFTER_QUOTATION,
        } charToken = NEW_WORD;
        std::wstring str;

        auto it = commandLine.begin(), ed = commandLine.end();
        for(; it != ed; ++ it)
        {
            switch(charToken)
            {
            case NEW_WORD:
                if(*it == L'"')
                    charToken = IN_QUOTATION;
                else if(*it != L' ')
                {
                    str += *it;
                    charToken = IN_WORD;
                }
                break;

            case IN_WORD:
                if(*it == L'"')
                    charToken = IN_QUOTATION;
                else if(*it != L' ')
                    str += *it;
                else
                {
                    words.push_back(str);
                    str.clear();
                    charToken = NEW_WORD;
                }
                break;

            case IN_QUOTATION:
                if(*it == L'"')
                    charToken = AFTER_QUOTATION;
                else
                    str += *it;
                break;

            case AFTER_QUOTATION:
                if(*it == L' ')
                {
                    words.push_back(str);
                    str.clear();
                    charToken = NEW_WORD;
                }
                else if(*it == L'"')
                {
                    str += L'"';
                    charToken = IN_QUOTATION;
                }
                else
                {
                    str += *it;
                    charToken = IN_WORD;
                }
                break;
            }
        }

        if(charToken != NEW_WORD)
        {
            words.push_back(str);
        }

        return words;
    }
Пример #23
0
std::wstring As_Lowercase(std::wstring str){
    std::transform(str.begin(), str.end(), str.begin(), ::tolower);
    return str;
}
Пример #24
0
 inline string str(const std::wstring src) {
     return string(src.begin(), src.end());
 }
Пример #25
0
bool ShpReader::Open(std::wstring fullPath, StudyControllerPtr studyController,
                     VectorMapControllerPtr vectorMapController, ProgressDlgPtr progressDlg) 
{
	// Registers all format drivers built into GDAL/OGR.
	OGRRegisterAll();

	OGRDataSource *OGRDataset;

	// Open vector file path
	std::string tempStr( fullPath.begin(), fullPath.end() );
	OGRDataset = OGRSFDriverRegistrar::Open( tempStr.c_str(), FALSE );

	// Return if no vector files are found
	if( OGRDataset == NULL )
	{
		Log::Inst().Warning("(Warning) Failed to open file at " + tempStr + ".");
		return false;
	}
	if ( App::Inst().GetLayerTreeController()->GetNumMapLayers() >0 )

		MapControllerPtr mapController= App::Inst().GetLayerTreeController()->GetLayerTreeModel()->GetStudy(0)->GetMapLayer(0)->GetMapController();

	// It appears that shapefiles (*.SHP) only support up to one layer per file
	// This will need to be further investigated for other vector filetypes (e.g., KML)
	// For now just grab layer at position 0
	
	OGRLayer *poLayer = OGRDataset->GetLayer( 0 );
	
	// Determine the XY boundaries for the entire vector dataset
	OGREnvelope psEnvelope;

	VectorMapModelPtr vectorMapModel = vectorMapController->GetVectorMapModel();
	poLayer->GetExtent( &psEnvelope );
	vectorMapModel->SetVectorBoundary(psEnvelope);

	if(!SetupVectorProjection(OGRDataset,studyController,poLayer,vectorMapController ))
	{
		OGRDataset->DestroyDataSource(OGRDataset);
		return false;
	}
	
	if(progressDlg)
	{
			if(!progressDlg->Update(0, _T("Reading Vector Map Information...")))
			{
				OGRDataset->DestroyDataSource(OGRDataset);
				return false;
			}
	}	
	GLdouble minX, minY, maxX, maxY;
	minX = minY = std::numeric_limits<float>::max();
	maxX = maxY = -std::numeric_limits<float>::max();

	// Retrieve features from the dataset
	OGRFeature *poFeature;
	poLayer->ResetReading();
	int numFeatures = poLayer->GetFeatureCount();
	int count=0;
    //Log::Inst().Write("Loading shapefile with the following meta data:");

	while ( ( poFeature = poLayer->GetNextFeature() ) != NULL )
	{
		/////////////////////////////////////////////////
		// PHASE 1: Retrieve METADATA from the dataset //
		/////////////////////////////////////////////////
		OGRFeatureDefn *poFDefn = poLayer->GetLayerDefn();
		int iField;

		for( iField = 0; iField < poFDefn->GetFieldCount(); iField++ )
		{
			OGRFieldDefn *poFieldDefn = poFDefn->GetFieldDefn( iField );

			//if( poFieldDefn->GetType() == OFTInteger )
			//    printf( "%d,", poFeature->GetFieldAsInteger( iField ) );
			//else if( poFieldDefn->GetType() == OFTReal )
			//    printf( "%.3f,", poFeature->GetFieldAsDouble(iField) );
			//else if( poFieldDefn->GetType() == OFTString )
			//    printf( "%s,", poFeature->GetFieldAsString(iField) );
			//else
			//    printf( "%s,", poFeature->GetFieldAsString(iField) );

			//ofs << poFeature->GetFieldAsString(iField) << ",";

			std::string metaData = poFeature->GetFieldAsString(iField);
			// do something with the meta data...
			//Log::Inst().Write(metaData);
		}
		count++;
		if(progressDlg)
		{
			if(!progressDlg->Update(int(50 + (float(count)/numFeatures)*50)))
				return false;
		}

		///////////////////////////////////////////////////
		// PHASE 2: Retrieve GEOMETRIES from the dataset //
		///////////////////////////////////////////////////
		OGRGeometry *poGeometry;
		poGeometry = poFeature->GetGeometryRef();

		// Move to the next feature in the set if no geometry present
		if( poGeometry == NULL )
		{
			OGRFeature::DestroyFeature( poFeature );
			continue;
		}

		OGRwkbGeometryType whatisit = poGeometry->getGeometryType();

		// Handle POINTS
		if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbPoint )
		{
			GeoVector* geoVector = new GeoVector();
			OGRPoint *poPoint = (OGRPoint *) poGeometry;

			geoVector->SetGeometryType( wkbPoint );
			geoVector->SetNumberOfPoints( 1 );
			if(needProjection)
			{
				double x,y;
				x= poPoint->getX();
				y= poPoint->getY();
				if(!poTransform->Transform(1, &x, &y))
				{
					Log::Inst().Warning("(Warning) Failed to project vector map.");
					OGRDataset->DestroyDataSource(OGRDataset);
					return false;
				}
				
				// project and store the points
				geoVector->pointX[0] = x;
				geoVector->pointY[0] = y;

				if(x < minX) minX=x;
				if(y < minY) minY=y;
				if(x > maxX) maxX=x;
				if(y > maxY) maxY=y;
			}
			else 			
			{
				geoVector->pointX[0] = poPoint->getX();
				geoVector->pointY[0] = poPoint->getY();

			}
			vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );
			
		}
		//Handle MultiPoint
		else if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbMultiPoint )
		{
			OGRMultiPoint *poMultiPoint = (OGRMultiPoint *) poGeometry;

			for ( int currGeometry = 0; currGeometry < poMultiPoint->getNumGeometries(); currGeometry++ )
			{
				GeoVector* geoVector = new GeoVector();				
				OGRPoint *poPoint = ( OGRPoint* )poMultiPoint->getGeometryRef( currGeometry );			
				geoVector->SetGeometryType( wkbPoint );
				geoVector->SetNumberOfPoints( 1 );
				if(needProjection)
				{
					double x,y;
					x= poPoint->getX();
					y= poPoint->getY();
					if(!poTransform->Transform(1, &x, &y))
					{
						Log::Inst().Warning("(Warning) Failed to project vector map.");
						OGRDataset->DestroyDataSource(OGRDataset);
						return false;
					}
					
					// project and store the points
					geoVector->pointX[0] = x;
					geoVector->pointY[0] = y;

					if(x < minX) minX=x;
					if(y < minY) minY=y;
					if(x > maxX) maxX=x;
					if(y > maxY) maxY=y;
				}
				else 			
				{
					geoVector->pointX[0] = poPoint->getX();
					geoVector->pointY[0] = poPoint->getY();

				}
				vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );
			}
			
		}

		//Handle Polylines
		else if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbLineString )
		{
			GeoVector* geoVector = new GeoVector();
			OGRLineString  *poLine = (OGRLineString  *) poGeometry;

			geoVector->SetGeometryType( wkbLineString );
			geoVector->SetNumberOfPoints( poLine->getNumPoints() );

			// Convert and store the points

			for ( int currentPoint = 0; currentPoint < poLine->getNumPoints(); currentPoint++ )
			{
				// Convert and store the points

				if(needProjection)
				{
					double x,y;
					x= poLine->getX( currentPoint );
					y= poLine->getY( currentPoint );
					if(!poTransform->Transform(1, &x, &y))
					{
						Log::Inst().Warning("(Warning) Failed to project vector map.");
						OGRDataset->DestroyDataSource(OGRDataset);
						return false;
					}
				
					// project and store the points
					geoVector->pointX[currentPoint] = x;
					geoVector->pointY[currentPoint] = y;

					if(x < minX) minX=x;
					if(y < minY) minY=y;
					if(x > maxX) maxX=x;
					if(y > maxY) maxY=y;
				}
				else			
				{
					geoVector->pointX[currentPoint] = poLine->getX( currentPoint );
					geoVector->pointY[currentPoint] = poLine->getY( currentPoint );

				}

			}

			vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );			
		}
		
		// Handle MultiPolyLine
		else if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbMultiLineString )
		{
			OGRMultiLineString *poMultiLine = (OGRMultiLineString *) poGeometry;

			for ( int currGeometry = 0; currGeometry < poMultiLine->getNumGeometries(); currGeometry++ )
			{
				GeoVector* geoVector = new GeoVector();
				
				OGRLineString *poLine = ( OGRLineString* )poMultiLine->getGeometryRef( currGeometry );

				geoVector->SetGeometryType( wkbLineString );
				geoVector->SetNumberOfPoints( poLine->getNumPoints() );				

				for ( int currentPoint = 0; currentPoint < poLine ->getNumPoints(); currentPoint++ )
				{

					 if(needProjection)
					{
						double x,y;
						x= poLine->getX( currentPoint );
						y= poLine->getY( currentPoint );
						if(!poTransform->Transform(1, &x, &y))
						{
							Log::Inst().Warning("(Warning) Failed to project vector map.");
							OGRDataset->DestroyDataSource(OGRDataset);
							return false;
						}
				
					// project and store the points
						geoVector->pointX[currentPoint] = x;
						geoVector->pointY[currentPoint] = y;

						if(x < minX) minX=x;
						if(y < minY) minY=y;
						if(x > maxX) maxX=x;
						if(y > maxY) maxY=y;
					}
					else			
					{
						geoVector->pointX[currentPoint] = poLine->getX( currentPoint );
						geoVector->pointY[currentPoint] = poLine->getY( currentPoint );

					}				
					
				}
				vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );				
				
			}
		}

		// Handle POLYGONS
		else if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbPolygon )
		{
			GeoVector* geoVector = new GeoVector();

			OGRPolygon    *poPolygon    = ( OGRPolygon* )poGeometry;
			OGRLinearRing *poLinearRing = poPolygon->getExteriorRing();

			geoVector->SetGeometryType( wkbLinearRing );
			geoVector->SetNumberOfPoints( poLinearRing->getNumPoints() );

			for ( int currentPoint = 0; currentPoint < poLinearRing->getNumPoints(); currentPoint++ )
			{
				if(needProjection)
				{
					double x,y;
					x= poLinearRing->getX( currentPoint );
					y= poLinearRing->getY( currentPoint );
					if(!poTransform->Transform(1, &x, &y))
					{
						Log::Inst().Warning("(Warning) Failed to project vector map.");
						OGRDataset->DestroyDataSource(OGRDataset);
						return false;
					}
				
					// project and store the points
					geoVector->pointX[currentPoint] = x;
					geoVector->pointY[currentPoint] = y;

					if(x < minX) minX=x;
					if(y < minY) minY=y;
					if(x > maxX) maxX=x;
					if(y > maxY) maxY=y;
				}
				else 			
				{
					geoVector->pointX[currentPoint] = poLinearRing->getX( currentPoint );
					geoVector->pointY[currentPoint] = poLinearRing->getY( currentPoint );

				}
			}

			vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );			
		}

		// Handle MULTIPOLYGONS
		else if ( wkbFlatten( poGeometry->getGeometryType() ) == wkbMultiPolygon )
		{
			OGRMultiPolygon *poMultiPolygon = (OGRMultiPolygon *) poGeometry;

			for ( int currGeometry = 0; currGeometry < poMultiPolygon->getNumGeometries(); currGeometry++ )
			{
				GeoVector* geoVector = new GeoVector();

				// OGRPolygon http://www.gdal.org/ogr/classOGRPolygon.html
				OGRPolygon *poPolygon = ( OGRPolygon* )poMultiPolygon->getGeometryRef( currGeometry );

				// Retrieve the EXTERNAL ring of the multipolygon
				OGRLinearRing *poLinearRing = poPolygon->getExteriorRing();

				geoVector->SetGeometryType( wkbLinearRing );
				geoVector->SetNumberOfPoints( poLinearRing->getNumPoints() );

				for ( int currentPoint = 0; currentPoint < poLinearRing->getNumPoints(); currentPoint++ )
				{

					 if(needProjection)
					{
						double x,y;
						x= poLinearRing->getX( currentPoint );
						y= poLinearRing->getY( currentPoint );
						if(!poTransform->Transform(1, &x, &y))
						{
							Log::Inst().Warning("(Warning) Failed to project vector map.");
							OGRDataset->DestroyDataSource(OGRDataset);
							return false;
						}
				
					// project and store the points
						geoVector->pointX[currentPoint] = x;
						geoVector->pointY[currentPoint] = y;

						if(x < minX) minX=x;
						if(y < minY) minY=y;
						if(x > maxX) maxX=x;
						if(y > maxY) maxY=y;
					}
					else			
					{
						geoVector->pointX[currentPoint] = poLinearRing->getX( currentPoint );
						geoVector->pointY[currentPoint] = poLinearRing->getY( currentPoint );

					}				
					
				}
				vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector );				
				
				// Retrieve all the INTERNAL rings of the multipolygon
				for ( int currentRing = 0; currentRing < poPolygon->getNumInteriorRings(); currentRing++ )
				{
					GeoVector* geoVector2 = new GeoVector();

					poLinearRing = poPolygon->getInteriorRing( currentRing );

					geoVector2->SetGeometryType( wkbLinearRing );
					geoVector2->SetNumberOfPoints( poLinearRing->getNumPoints() );

					for ( int currentPoint = 0; currentPoint < poLinearRing->getNumPoints(); currentPoint++ )
					{
						
						 if(needProjection)
						{
							double x,y;
							x= poLinearRing->getX( currentPoint );
							y= poLinearRing->getY( currentPoint );
							if(!poTransform->Transform(1, &x, &y))
							{
								Log::Inst().Warning("(Warning) Failed to project vector map.");
								OGRDataset->DestroyDataSource(OGRDataset);
								return false;
							}
				
						// project and store the points
							geoVector2->pointX[currentPoint] = x;
							geoVector2->pointY[currentPoint] = y;

							if(x < minX) minX=x;
							if(y < minY) minY=y;
							if(x > maxX) maxX=x;
							if(y > maxY) maxY=y;
						}
						else 		
						{
							geoVector2->pointX[currentPoint] = poLinearRing->getX( currentPoint );
							geoVector2->pointY[currentPoint] = poLinearRing->getY( currentPoint );

						}		
					}

					vectorMapController->GetVectorMapModel()->AddGeoVector( geoVector2 );
				}
			}
		}


		// Report a warning message for unhandled geometries
		else
		{
			Log::Inst().Warning("(Warning) Could not load vector data: unsupported geometry.");
		}
		OGRFeature::DestroyFeature( poFeature );
	}

	if (float(minX) == float(maxX) && float(minY) == float(maxY))
	{
		Log::Inst().Warning("(Warning) Failed to project vector map.");
		OGRDataset->DestroyDataSource(OGRDataset);
		return false;
	}

	if(needProjection)
	{
		vectorMapModel->SetVectorBoundary_MinX(minX);
		vectorMapModel->SetVectorBoundary_MaxX(maxX);
		vectorMapModel->SetVectorBoundary_MinY(minY);
		vectorMapModel->SetVectorBoundary_MaxY(maxY);
	}	
	
	if(!SetupVectorScaling(vectorMapModel,progressDlg))
	{ 
		OGRDataset->DestroyDataSource(OGRDataset);
		return false;
	}

	VectorMetaDataInfo(OGRDataset, studyController, vectorMapController);
	OGRDataSource::DestroyDataSource( OGRDataset );
	return true;
}
Пример #26
0
void lowercase(std::wstring &ws)
{
	std::transform(ws.begin(), ws.end(), ws.begin(), towlower);
}
string WStringToString(const std::wstring& s) //convert wchart_t to basic_sring
{
    string temp(s.length(), ' ');
    copy(s.begin(), s.end(), temp.begin());
    return temp;
}
Пример #28
0
std::string wstring_to_string(const std::wstring& s)
{
    std::string temp(s.length(),L' ');
    std::copy(s.begin(), s.end(), temp.begin());
    return temp;
}
Пример #29
0
void ToUpperCase(std::wstring& str)
{
	auto to_upper = [](wchar_t ch) { return std::use_facet<std::ctype<wchar_t>>(std::locale()).toupper(ch); };
	std::transform(str.begin(), str.end(), str.begin(), to_upper);
}
Пример #30
0
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return w_str;
}

std::wstring hyperloop::getWString(JSContextRef ctx, JSValueRef ref) {
	JSStringRef sValue = JSValueToStringCopy(ctx, ref, NULL);
	return hyperloop::getWString(sValue);
}

const char* hyperloop::getCStr(Platform::String^ string) {
	std::wstring w_str(string->Begin());
	std::string s_str(w_str.begin(), w_str.end());
	return s_str.c_str();
}

String^ hyperloop::getPlatformString(JSStringRef sValue) {
	size_t sLength = JSStringGetMaximumUTF8CStringSize(sValue);
	char* cValue = new char[sLength];
	JSStringGetUTF8CString(sValue, cValue, sLength);
	std::string s_str = cValue;
	std::wstring w_str(s_str.begin(), s_str.end());
	return ref new String(hyperloop::getWString(sValue).c_str());
}

String^ hyperloop::getPlatformString(JSContextRef ctx, JSValueRef ref) {
	JSValueRef exception = NULL;
	JSStringRef sValue = JSValueToStringCopy(ctx, ref, &exception);