void CTest::test_load_xml() { //file<> fdoc( const_xml_path.c_str() ); //不直接用库提供的读文件函数 std::string straData; ReadFromDiskA(const_xml_path, straData); rapidxml::xml_document<> xmlDoc; xmlDoc.parse<0>(const_cast<char*>(straData.c_str())); rapidxml::xml_node<>* xmlRoot = xmlDoc.first_node("root"); if (xmlRoot != NULL) { for ( rapidxml::xml_node<>* itemNode = xmlRoot->first_node("item"); itemNode != NULL; itemNode = itemNode->next_sibling() ) { std::wstring strwValueID = GetXMLAttributeValue(itemNode, L"id"); std::wstring strwValueTime = GetXMLAttributeValue(itemNode, L"time"); std::wstring strwValueLove = GetXMLAttributeValue(itemNode, L"love"); std::wstring strwValueData = GetXMLAttributeValue(itemNode, L"data"); std::wstring strwValuehei = GetXMLAttributeValue(itemNode, L"嘿"); std::cout << "id = " << wstr2str(strwValueID, CP_ACP) << std::endl; std::cout << "time = " << wstr2str(strwValueTime, CP_ACP) << std::endl; std::cout << "love = " << wstr2str(strwValueLove, CP_ACP) << std::endl; std::cout << "data = " << wstr2str(strwValueData, CP_ACP) << std::endl; std::cout << "hei = " << wstr2str(strwValuehei, CP_ACP) << std::endl; rapidxml::xml_node<>* xmlChild = itemNode->first_node("child_item"); if (xmlChild != NULL) { std::string strValueChildItem = xmlChild->value(); std::cout << "child_item = " << strValueChildItem << std::endl; } } } }
bool CTestjsoncpp::test_Parse() { std::wstring wstrJson = ReleaseJsonStr(); std::string strJson = wstr2str(wstrJson, CP_UTF8); Json::Reader jsonReader; Json::Value root; jsonReader.parse(strJson, root); std::string strresult = root["result"].asString(); std::cout << "result:" << strresult << std::endl; std::cout << "data:" << std::endl; Json::Value jvData = root["data"]; if(jvData.isArray()) { std::cout << "[" << std::endl; //item for (Json::Value::iterator it = jvData.begin(); it != jvData.end(); ++it) { std::cout << "{" << std::endl; Json::Value item = *it; Json::Value::Members memItem = item.getMemberNames(); //mem in item for (Json::Value::Members::iterator itItem = memItem.begin(); itItem != memItem.end(); ++itItem) { std::string strKey = *itItem; std::string strValue = item[strKey].asString(); std::cout << strKey << ":" << strValue << std::endl; } std::cout << "}" << std::endl; } std::cout << "]" << std::endl; } return false; }
std::string well_obj::py_str () const { std::stringstream s; s << wstr2str(sp_prop->py_str ()) << "\n"; return s.str (); }
void CViewerDlg::OnDropFiles(HDROP hDropInfo) { HDROP hdrop = hDropInfo; WCHAR filePath[ MAX_PATH]; const UINT size = DragQueryFile(hdrop, 0, filePath, MAX_PATH); if (size == 0) return;// handle error... // m_FileList.InsertItem(m_FileList.GetItemCount(), filePath); string fileName = wstr2str(filePath); // string::size_type if( fileName.rfind(".dat") != string::npos ) //작동원리 모름...구글링하였음... { m_pModelView->m_sfileIndex = m_FileList.GetItemCount(); //어떤 파일이었는지 보관하여 기억 m_FileList.InsertItem(m_FileList.GetItemCount(), filePath); // m_pModelView->m_sfileIndex = m_FileList.GetItemCount() - 1; m_pModelView->FileLoad( DAT, fileName ); } else if( fileName.rfind(".jpg") != string::npos ) { m_pModelView->FileLoad( JPG, fileName ); } CDialogEx::OnDropFiles(hDropInfo); }
string getUserName() { TCHAR username[UNLEN+1]; DWORD username_len = UNLEN+1; GetUserName(username, &username_len); return wstr2str(username, username_len-1); }
tstring wstr2tstr(const std::wstring& st ) { #ifdef _UNICODE return st; #else return wstr2str(st); #endif }
static bool FileSortCallback(const BrowserEntryStruct *f1, const BrowserEntryStruct *f2) { //! Special case for implicit directories if(((BrowserEntryStruct *)f1)->displayname[0] == '.' || ((BrowserEntryStruct *)f2)->displayname[0] == '.') { if(((BrowserEntryStruct *)f1)->displayname.compare(L".") == 0) { return true; } if(((BrowserEntryStruct *)f2)->displayname.compare(L".") == 0) { return false; } if(((BrowserEntryStruct *)f1)->displayname.compare(L"..") == 0) { return true; } if(((BrowserEntryStruct *)f2)->displayname.compare(L"..") == 0) { return false; } } //! If one is a file and one is a directory the directory is first if(((BrowserEntryStruct *)f1)->isdir && !(((BrowserEntryStruct *)f2)->isdir)) return true; if(!(((BrowserEntryStruct *)f1)->isdir) && ((BrowserEntryStruct *)f2)->isdir) return false; return (stricmp((wstr2str(((BrowserEntryStruct *)f1)->displayname)).c_str(), (wstr2str(((BrowserEntryStruct *)f2)->displayname)).c_str()) < 0); }
std::string tstr2str(const tstring& aa ) { #ifdef _UNICODE return wstr2str(aa); #else return aa; #endif }
// 애니메이션 파일을 연다. void CFilePanel::OnDblclkListAnimation() { const int selIdx = m_AnimationFileList.GetCurSel(); if (selIdx < 0) return; CString text; m_AnimationFileList.GetText(selIdx, text); const string fileName = wstr2str((wstring)text); cController::Get()->LoadFile(fileName); }
std::string GpuCapabilitiesWindows::WMIqueryStr(std::string wmiClass, std::string attribute) { VARIANT* variant = WMIquery(wmiClass, attribute); if (!variant) { return ""; } else { std::string result = wstr2str(std::wstring(variant->bstrVal)); VariantClear(variant); return result; } }
std::wstring CTest::GetXMLAttributeValue( rapidxml::xml_node<>* pNode, const std::wstring& strwKey ) { std::string straKey = wstr2str(strwKey, CP_UTF8); std::wstring strwValue; rapidxml::xml_attribute<>* xmlattribute = pNode->first_attribute(straKey.c_str()); if (xmlattribute != NULL) { std::string straValue = xmlattribute->value(); strwValue = str2wstr(straValue, CP_UTF8); } return strwValue; }
// 모델 파일을 연다. void CFilePanel::OnDblclkListModel() { const int selIdx = m_ModelFileList.GetCurSel(); if (selIdx < 0) return; CString text; m_ModelFileList.GetText(selIdx, text); const string fileName = wstr2str((wstring)text); ShowLoadingDialog(); cController::Get()->LoadFile(fileName); }
// 지형 텍스쳐 설정. void CHeightMapPanel::OnDblclkListHeightmapTex() { RET(m_TextureList.GetCurSel() < 0); CString fileName; m_TextureList.GetText(m_TextureList.GetCurSel(), fileName); SAFE_DELETE(m_texture); m_texture = Image::FromFile(fileName); InvalidateRect(NULL, FALSE); string asciiFileName = wstr2str((wstring)fileName); cMapController::Get()->LoadHeightMapTexture(asciiFileName); }
void GUISoundManager::addBackgroundSound(const wstring& soundFile) { // Create game entity for playing this sound wstringstream name; name << L"bgSound" << backgroundSounds.size(); XMLNode node = XMLNode::createXMLTopNode(L"GameEntity"); node.addAttribute(L"name", name.str().c_str()); XMLNode soundNode = node.addChild(L"Sound3D"); soundNode.addAttribute(L"file", soundFile.c_str()); soundNode.addAttribute(L"stream", L"1"); wstring xmlString = node.createXMLString(); unsigned int entityID = GameEngine::createGameEntity(wstr2str(xmlString).c_str()); // And add the sound entity to the list backgroundSounds.push_back(entityID); }
void GUISoundManager::addEventSound(GUIEvent event, wstring source, const wstring& soundFile) { // Create game entity for playing this sound wstringstream name; name << L"eventSound" << eventSounds.size(); XMLNode node = XMLNode::createXMLTopNode(L"GameEntity"); node.addAttribute(L"name", name.str().c_str()); XMLNode soundNode = node.addChild(L"Sound3D"); soundNode.addAttribute(L"stream", L"false"); soundNode.addAttribute(L"file", soundFile.c_str()); soundNode.addAttribute(L"autoStart", L"0"); wstring xmlString = node.createXMLString(); unsigned int entityID = GameEngine::createGameEntity(wstr2str(xmlString).c_str()); // And add it to the list eventSounds.push_back(new EventSound(event,source,entityID)); }
void CustomFileBrowser::SetButton(int i, std::wstring name, bool dir, bool enable) { if(i < 0) return; else if(i >= (int) fileBtn.size()) { AddButton(); } if(!enable) { fileBtn[i]->SetVisible(false); fileBtn[i]->SetState(STATE_DISABLED); return; } if(fileBtnIcon[i]) delete fileBtnIcon[i]; std::string fileext = wstr2str(name); int index = fileext.find_last_of('.'); if(index > 0) { fileext = fileext.substr(index); if(!fileext.compare(".")) fileext = ""; } else fileext = ""; fileBtnIcon[i] = GetIconFromExt(fileext, dir); fileBtnIcon[i]->SetScale(0.667); fileBtnIcon[i]->SetPosition(-7, -7); fileBtnText[i]->SetText(name); fileBtnTextOver[i]->SetText(name); fileBtn[i]->SetIcon(fileBtnIcon[i]); fileBtn[i]->SetVisible(true); if(fileBtn[i]->GetState() == STATE_DISABLED) fileBtn[i]->SetState(STATE_DEFAULT); }
void CTest::AddXMLAttributeValue( rapidxml::xml_document<>& pDoc, rapidxml::xml_node<>* pNode, const std::wstring& strwKey, const std::wstring& strwValue ) { std::string straValue = wstr2str(strwValue, CP_UTF8); std::string strakey = wstr2str(strwKey, CP_UTF8); pNode->append_attribute(pDoc.allocate_attribute(pDoc.allocate_string(strakey.c_str()), pDoc.allocate_string(straValue.c_str()) ) ); }
Mesh* Mesh::CreateFromFBX(RenderSystem* pRenderSys, tstring const& filename) { try { tstring path = Core::GetInstance()->GetAssetsDir() + TEXT("/Models/") + filename; const aiScene* scene = aiImportFile(wstr2str(path).c_str(), aiProcessPreset_TargetRealtime_MaxQuality | aiProcess_ConvertToLeftHanded | aiProcess_TransformUVCoords); Float3 min, max; if (scene == nullptr || scene->mNumMeshes == 0) throw std::exception("No Mesh in this file"); Mesh* ret = new Mesh(); for (uint32 meshIndex = 0; meshIndex < scene->mNumMeshes; ++meshIndex) { MeshPart* part = ret->CreatePart(); aiMesh* pAiPart = scene->mMeshes[meshIndex]; int32 numVertices = pAiPart->mNumVertices; int32 numFaces = pAiPart->mNumFaces; int32 numUVChannels = scene->mMeshes[meshIndex]->GetNumUVChannels(); if (!pAiPart->HasFaces() || !pAiPart->HasNormals() || !pAiPart->HasPositions() || !pAiPart->HasTextureCoords(0) || !pAiPart->HasTangentsAndBitangents()) { ret->RemovePart(part); continue; }; min = Float3((float*)&(pAiPart->mVertices[0])); max = Float3((float*)&(pAiPart->mVertices[0])); part->m_pInputLayout.reset(new InputLayout{ { VertexElemType::Float3, ElemSemantic::Position, 0, 0, ElementClass::PerVertex, 0 }, { VertexElemType::Float3, ElemSemantic::Normal, 0, 0, ElementClass::PerVertex, 0 }, { VertexElemType::Float3, ElemSemantic::Tangent, 0, 0, ElementClass::PerVertex, 0 }, }); auto layout = part->m_pInputLayout; for (int32 i = 0; i < numUVChannels; ++i) layout->Insert(layout->End(), { VertexElemType::Float2, ElemSemantic::TexCoord, (uint32)i, 0, ElementClass::PerVertex, 0 }); uint32 stride = layout->GetVertexStride(0); byte* vertices = new byte[stride * numVertices]; uint16* indices = new uint16[3 * numFaces]; auto elemPosition = layout->Begin(); auto elemNormal = elemPosition + 1; auto elemTangent = elemNormal + 1; #define Get(V,i,stride,offset) (V + stride * i + offset) for (int32 i = 0; i < numVertices; ++i) { *(Float3*)Get(vertices, i, stride, elemPosition->AlignedByteOffset) = Float3((float*)&(pAiPart->mVertices[i])); *(Float3*)Get(vertices, i, stride, elemTangent->AlignedByteOffset) = Float3((float*)&(pAiPart->mTangents[i])); *(Float3*)Get(vertices, i, stride, elemNormal->AlignedByteOffset) = Float3((float*)&(pAiPart->mNormals[i])); auto elemTexCoord = elemTangent + 1; for (int32 j = 0; j < numUVChannels; ++j) { aiVector3D texcoord = pAiPart->mTextureCoords[j][i]; *(Float2*)Get(vertices, i, stride, elemTexCoord->AlignedByteOffset) = Float2((float*)&(pAiPart->mTextureCoords[j][i])); ++elemTexCoord; } #if UV_MIRROR float t = dot(cross(scene->mMeshes[meshIndex]->mNormals[i], scene->mMeshes[meshIndex]->mTangents[i]), scene->mMeshes[meshIndex]->mBitangents[i]); if (t < 0) vertices[i].Tangent = float3(-vertices[i].Tangent.r, vertices[i].Tangent.g, vertices[i].Tangent.b); #endif min.x = std::min(min.x, pAiPart->mVertices[i].x); min.y = std::min(min.y, pAiPart->mVertices[i].y); min.z = std::min(min.z, pAiPart->mVertices[i].z); max.x = std::max(max.x, pAiPart->mVertices[i].x); max.y = std::max(max.y, pAiPart->mVertices[i].y); max.z = std::max(max.z, pAiPart->mVertices[i].z); } part->m_Size = std::max(max.x - min.x, std::max(max.y - min.y, max.z - min.z)); part->m_Center = Float3((min.x + max.x) / 2.0f, (min.y + max.y) / 2.0f, (min.z + max.z) / 2.0f); for (long long i = 0; i < numFaces; ++i) { aiFace* face = &(scene->mMeshes[meshIndex]->mFaces[i]); indices[3 * i] = face->mIndices[0]; indices[3 * i + 1] = face->mIndices[1]; indices[3 * i + 2] = face->mIndices[2]; assert( indices[3 * i] <= numVertices && indices[3 * i + 1] <= numVertices && indices[3 * i + 2] <= numVertices ); } part->m_NumPrimitives = numFaces; part->m_pVertexBuffer.reset( VertexBuffer::Create(pRenderSys, vertices, layout->GetVertexStride(0) * numVertices, layout->GetVertexStride(0))); part->m_pIndexBuffer.reset( IndexBuffer::Create(pRenderSys, (byte*)indices, sizeof(uint16) * 3 * numFaces, DataFormat::R16_UINT)); delete vertices; delete indices; } aiReleaseImport(scene); return ret; } catch (std::exception& e) { Log(e.what()); return nullptr; } }
bool MSVCMemoryDump::miniDumpCallBack(const wchar_t* dump_path, const wchar_t* minidump_id, void* context, EXCEPTION_POINTERS* exinfo, MDRawAssertionInfo* assertion, bool succeeded) { if(succeeded) { //Launches crashreport.exe std::string commandLine = "owcrashreport"; if (!_styleName.empty()) { commandLine += " -style="; commandLine += _styleName; } //Name of the memory dump //Use current path std::string memoryDumpName; if ( !_fileNamePrefix.empty() ) { memoryDumpName += _fileNamePrefix; memoryDumpName += "-"; } memoryDumpName += wstr2str(std::wstring(minidump_id)); memoryDumpName += ".dmp"; //GetModuleFileName retrieves the path of the executable file of the current process. std::string memoryDumpFile = wstr2str(std::wstring(dump_path)); memoryDumpFile += memoryDumpName; commandLine += " -d "; commandLine += "\""; commandLine += memoryDumpFile; commandLine += "\""; commandLine += " -n "; commandLine += "\""; commandLine += _applicationName; commandLine += "\""; if (!_languageFilename.empty()) { commandLine += " -l "; commandLine += "\""; commandLine += _languageFilename; commandLine += "\""; } if (getAdditionalInfo) { commandLine += " -i "; commandLine += "\""; commandLine += getAdditionalInfo(); commandLine += "\""; } //Flushes the logger file //Logger::logger.flush(); executeProcess(commandLine); } // force to terminate TerminateProcess(GetCurrentProcess(), 0); return succeeded; }
std::string wstr2str(wstring wstr) { return wstr2str(wstr.c_str(), wstr.length()); }