void ms_cl_cmdlinet::process_response_file(const std::string &file) { std::ifstream infile(file.c_str()); if(!infile) { std::cerr << "failed to open response file `" << file << "'" << std::endl; return; } // these may be Unicode -- which is indicated by 0xff 0xfe std::string line; getline(infile, line); if(line.size()>=2 && line[0]==char(0xff) && line[1]==char(0xfe)) { // Unicode, UTF-16 little endian #if 1 // Re-open -- should be using wifstream, // but this isn't available everywhere. std::ifstream infile2(file.c_str(), std::ios::binary); infile2.seekg(2); std::wstring wline; while(my_wgetline(infile2, wline)) process_response_file_line(narrow(wline)); // we UTF-8 it #else std::wifstream infile2(file.c_str(), std::ios::binary); std::wstring wline; while(std::getline(infile2, wline)) process_response_file_line(narrow(wline)); // we UTF-8 it #endif } else if(line.size()>=3 && line[0]==char(0xef) && line[1]==char(0xbb) && line[2]==char(0xbf)) { // This is the UTF-8 BOM. We can proceed as usual, since // we use UTF-8 internally. infile.seekg(3); while(getline(infile, line)) process_response_file_line(line); } else { // normal ASCII infile.seekg(0); while(getline(infile, line)) process_response_file_line(line); } }
static uint32 sahSplit(uint32 starts[], uint32 ends[], Box3f geomBoxes[], Box3f centroidBoxes[], PrimVector &prims, uint32 branchFactor) { uint32 childCount; for (childCount = 1; childCount < branchFactor; ++childCount) { // Find child with most primitives uint32 interval = 0; for (uint32 i = 1; i < childCount; ++i) if (ends[interval] - starts[interval] < ends[i] - starts[i]) interval = i; // Largest child fits into a leaf node? -> we're done uint32 numPrims = ends[interval] - starts[interval] + 1; if (numPrims <= branchFactor) break; // If not, split the largest child SplitInfo split; twoWaySahSplit(starts[interval], ends[interval], prims, geomBoxes[interval], centroidBoxes[interval], split); // Create two new children starts [childCount] = split.idx; ends [childCount] = ends[interval]; geomBoxes [childCount] = narrow(split.rBox); centroidBoxes[childCount] = narrow(split.rCentroidBox); ends [interval] = split.idx - 1; geomBoxes [interval] = narrow(split.lBox); centroidBoxes[interval] = narrow(split.lCentroidBox); } return childCount; }
ResourceId ReplayRenderer::BuildCustomShader(const wchar_t *entry, const wchar_t *source, const uint32_t compileFlags, ShaderStageType type, rdctype::wstr *errors) { ResourceId id; string errs; switch(type) { case eShaderStage_Vertex: case eShaderStage_Hull: case eShaderStage_Domain: case eShaderStage_Geometry: case eShaderStage_Pixel: case eShaderStage_Compute: break; default: RDCERR("Unexpected type in BuildShader!"); return ResourceId(); } m_pDevice->BuildCustomShader(narrow(source), narrow(entry), compileFlags, type, &id, &errs); if(id != ResourceId()) m_CustomShaders.insert(id); if(errors) *errors = widen(errs); return id; }
// For backward, we save svd. // http://www.ics.forth.gr/cvrl/publications/conferences/2000_eccv_SVD_jacobian.pdf // But instead of gesvd SVD A = U(A) Sig(A) V(A)^T, which doesn't specify signs // of determinants of U and V, we consider det(A) = \prod Sig_(A), where // 1. A = U_(A) Sig_(A) V(A)^T // 2. Sig_(A) and U_(A) can be different in signs in first row/col from // their counterparts so that U_(A) * V_(A) have +1 determinant std::tuple<Tensor, Tensor, Tensor, Tensor> _det_with_svd(const Tensor& self) { if (!at::isFloatingType(self.type().scalarType()) || self.dim() != 2 || self.size(0) != self.size(1)) { std::ostringstream ss; ss << "det(" << self.type() << "{" << self.sizes() << "}): expected a 2D " << "square tensor of floating types"; throw std::runtime_error(ss.str()); } // check symmetric bool symmetric = self.equal(self.transpose(0, 1)); auto svd = self.svd(true); auto sigma = std::get<1>(svd); auto u = std::get<0>(svd); auto v = std::get<2>(svd); auto det = sigma.prod(); if (!symmetric) { auto qr = self.geqrf(); auto a = std::get<0>(qr); auto tau = std::get<1>(qr); // non-zero values in tau represent Householder reflectors, which has -1 det int64_t num_reflectors = tau.nonzero().size(0); auto qr_det = a.diag().prod(); if (num_reflectors % 2 == 1) { qr_det = -qr_det; } det = qr_det; // QR is more stable than svd, so use it anyways if ((qr_det < 0).any().toCByte() ^ (det < 0).any().toCByte()) { // if different sign u.narrow(1, 0, 1).mul_(-1); sigma.narrow(0, 0, 1).mul_(-1); } } return std::make_tuple(det, u, sigma, v); }
Gosu::File::File(const std::wstring& filename, FileMode mode) : pimpl(new Impl) { int flags; switch (mode) { case fmRead: flags = O_RDONLY; break; case fmReplace: flags = O_RDWR | O_TRUNC | O_CREAT; break; case fmAlter: flags = O_RDWR | O_CREAT; break; } // TODO: Locking flags? pimpl->fd = open(narrow(filename).c_str(), flags, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if (pimpl->fd < 0) throw std::runtime_error("Cannot open file " + narrow(filename)); if (mode == fmRead && size() > 0) pimpl->mapping = mmap(0, size(), PROT_READ, 0, pimpl->fd, 0); }
NS_IMETHODIMP sbDatetimePropertyInfo::MakeSearchable(const nsAString & aValue, nsAString & _retval) { nsresult rv; PRInt64 value = 0; NS_ConvertUTF16toUTF8 narrow(aValue); _retval = aValue; _retval.StripWhitespace(); sbSimpleAutoLock lock(mMinMaxDateTimeLock); if(PR_sscanf(narrow.get(), gsFmtRadix10, &value) != 1) { _retval = EmptyString(); return NS_ERROR_INVALID_ARG; } char out[32] = {0}; if(PR_snprintf(out, 32, gsSortFmtRadix10, value) == (PRUint32)-1) { rv = NS_ERROR_FAILURE; _retval = EmptyString(); } else { NS_ConvertUTF8toUTF16 wide(out); rv = NS_OK; _retval = wide; } return rv; }
void print_response(HttpResponse& response, TcpClientSocket& socket) { std::cout << narrow(widen(response.getStatusLine(), CP_UTF8), CP_OEMCP) << std::endl; auto headers = response.getHeaders(); for (auto it = std::begin(headers), eit = std::end(headers); it != eit; ++it) { for (auto vit = std::begin(it->second), veit = std::end(it->second); vit != veit; ++vit) { std::cout << it->first << ": " << *vit << std::endl; } } std::cout << "======END OF HEADERS======" << std::endl; auto& buffer = response.getBuffer(); if (response.getIsChunked()) { std::cout << "[[CHUNKED ENCODING]]" << std::endl; for (auto chunk = buffer.getchunk(); !chunk.empty(); chunk = buffer.getchunk()) { std::cout << chunk; } std::cout << "[[TRAILING HEADERS]]" << std::endl; for (auto th = buffer.getline(); !th.empty(); th = buffer.getline()) { std::cout << th << std::endl; } } else if (HttpResponse::nlen != response.getContentLength()) { std::cout << "[[EXACTLY " << response.getContentLength() << " BYTES]]" << std::endl; std::cout << buffer.getcount(response.getContentLength()) << std::endl; } else { std::vector<BYTE> buff(8 * 1024, 0); for (auto last = socket.recv_upto(std::begin(buff), std::end(buff)); last != std::begin(buff); last = socket.recv_upto(std::begin(buff), std::end(buff))) { std::cout << std::string(std::begin(buff), last); } } std::cout << std::endl << "======END OF RESPONSE======" << std::endl; }
void MainWindow::updatePanelVisible() { if (!m_updatePanelVisible) return; if (m_settings->hideMode() == KeepShowing) return; const Dock::HideState state = m_settings->hideState(); // qDebug() << state; do { if (state != Hide) break; if (!m_settings->autoHide()) break; QRect r(pos(), size()); if (r.contains(QCursor::pos())) break; return narrow(m_settings->position()); } while (false); return expand(); }
void MainWindow::positionChanged(const Position prevPos) { // paly hide animation and disable other animation m_updatePanelVisible = false; clearStrutPartial(); narrow(prevPos); // reset position & layout and slide out QTimer::singleShot(200, this, [&] { resetPanelEnvironment(false); updateGeometry(); expand(); }); // set strut QTimer::singleShot(400, this, [&] { setStrutPartial(); }); // reset to right environment when animation finished QTimer::singleShot(600, this, [&] { m_updatePanelVisible = true; updatePanelVisible(); }); }
int main () { string s="你好"; wstring ws=L"你好"; cout<<s<<endl; cout<<wstringtostring(ws)<<endl; cout<<narrow(ws)<<endl; wcout.imbue(locale(locale(), "", LC_CTYPE)); // wcout.imbue(locale("")); // wcout.imbue(locale_platform); wcout<<ws<<endl; wcout<<stringtowstring(s)<<endl; wcout<<widen(s)<<endl; wofstream fout("fout.txt"); fout.imbue(locale_platform); fout<<ws<<endl; fout<<stringtowstring(s)<<endl; fout<<widen(s)<<endl; // string in; // copy(utf8in(s.begin()), utf8in(s.end()), back_inserter(in)); // cout<<in<<endl; // copy(utf8in(s.begin()), utf8in(s.end()), back_inserter(wvect)); // cout<<string(utf8in(s.begin()), utf8in(s.end()))<<endl; }
void be_enum::FinishProtoTypeCode() { // flesh out typecode // since enums names are all in a scope and not added directly // we go through the scope and add them all here UTL_Scope* s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); assert(s); UTL_ScopeActiveIterator* i = 0; i = new UTL_ScopeActiveIterator(s, UTL_Scope::IK_decls); if (s->nmembers() > 0) { for ( ; !(i->is_done()); i->next()) { AST_Decl* d = i->item(); assert(d); m_typecode->member_names.push_back(d->local_name()->get_string()); } delete i; } }
void be_CodeGenerator::Generate(be_ClientImplementation& source) { UTL_ScopeActiveIterator* i; AST_Decl * d; UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); if (s) { i = new UTL_ScopeActiveIterator(s, UTL_Scope::IK_decls); while (!(i->is_done())) { be_CodeGenerator * cg; d = i->item(); if (!d->imported() && (cg = (be_CodeGenerator*)d->narrow((long) & be_CodeGenerator::type_id))) { cg->Generate(source); } i->next(); } delete i; } else { assert(pbfalse); } }
int main(int argc, char** argv) { if (argc != 2) { std::cerr << "Usage: " << argv[0] << " <sample size: integer>" << std::endl; return 1; } // Build initialization memory std::istringstream argbuf(argv[1]); std::size_t data_size; argbuf >> data_size; utils::random_engine engine(43278322); std::cout << "Uniform distribution:" << std::endl; utils::uniform_double_distribution uniform(engine, -1.0, 1.0); compare_libraries<3, point3_type, utils::uniform_double_distribution>( data_size, uniform); compare_libraries<9, point9_type, utils::uniform_double_distribution>( data_size, uniform); std::cout << "Normal distribution:" << std::endl; utils::normal_double_distribution normal(engine, -1.0, 1.0); compare_libraries<3, point3_type, utils::normal_double_distribution>( data_size, normal); compare_libraries<9, point9_type, utils::normal_double_distribution>( data_size, normal); std::cout << "Narrow normal distribution:" << std::endl; utils::narrow_double_distribution narrow(engine, -1.0, 1.0); compare_libraries<3, point3_type, utils::narrow_double_distribution>( data_size, narrow); compare_libraries<9, point9_type, utils::narrow_double_distribution>( data_size, narrow); }
bool Exporter::exportUPB(NiNodeRef &root, INode *node) { bool ok = false; if (!mUserPropBuffer) return ok; // Write the actual UPB sans any np_ prefixed strings TSTR upb; node->GetUserPropBuffer(upb); if (!upb.isNull()) { std::wstring line; std::wistringstream istr(std::wstring(upb), ios_base::out); std::wostringstream ostr; while (!istr.eof()) { std::getline(istr, line); if (!line.empty() && 0 != line.compare(0, 3, _T("np_"))) ostr << line << endl; } if (!ostr.str().empty()) { NiStringExtraDataRef strings = CreateNiObject<NiStringExtraData>(); strings->SetName("UPB"); strings->SetData(narrow(ostr.str())); root->AddExtraData(DynamicCast<NiExtraData>(strings)); ok = true; } } return ok; }
void be_exception::GenerateAssignmentOperator (be_ClientImplementation& source) { ostream & os = source.Stream (); DDS_StdString that (""); be_Type * btype; if (nmembers ()) { that = " that"; } os << ScopedName () << " & " << ScopedName () << "::operator = (const " << LocalName () << " &" << that << ")" << nl; os << "{" << nl; UTL_Scope * s = (UTL_Scope*)narrow((long) & UTL_Scope::type_id); assert (s); UTL_ScopeActiveIterator *it; // Iterate through decls for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); ! it->is_done (); it->next () ) { AST_Decl * adecl = it->item (); assert (adecl); be_field *bfield = (be_field *) adecl->narrow ((long) & be_field::type_id); if (bfield) { btype = bfield->get_be_type (); if (btype && btype->IsArrayType ()) { // Need to copy array elements os << " " << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ()) << "_copy (" << bfield->get_local_name () << ", that." << bfield->get_local_name () << ");" << nl; } else { os << " " << bfield->get_local_name () << " = that." << bfield->get_local_name() << ";" << nl; } } } delete it; os << " return *this;" << nl; os << "}" << nl << nl; }
void be_root::GenerateGlobalDecls (be_ClientHeader & source) { UTL_ScopeActiveIterator * i; be_CodeGenerator * cg; AST_Decl * d; UTL_Scope * s = (UTL_Scope*) narrow ((long) & UTL_Scope::type_id); if (s) { // Iterate through decls i = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); while (!(i->is_done ())) { d = i->item (); if (!d->imported ()) { cg = (be_CodeGenerator*) d->narrow ((long) & be_CodeGenerator::type_id); if (cg) { cg->Generate (source); } } i->next (); } delete i; } }
int request_type14(int id,int major,int minor,int* cxt, int* aux0,char* buf,int bufsize) { canna_server* svr = &server[id]; canna_request_type14 req; int size; int sub; if (retr(svr,&req.size,2)) return -1; size = ntohs(req.size); size -= 6; if (size < 2 || bufsize < size) return -1; req.data = malloc(size); if (req.data == 0) return -1; if (retr(svr,&req.mode,4)) return -1; if (retr(svr,&req.cxt,2)) return -1; *cxt = (int16_t)ntohs(req.cxt); *aux0 = ntohl(req.mode); if (retr(svr,req.data,size)) return -1; sub = narrow(buf,bufsize,req.data,size/2); if (sub == -1) return -1; if (*(buf+sub-1) != 0) return -1; free(req.data); return 0; }
std::shared_ptr<FIBITMAP> load_image(const std::wstring& filename) { if(!boost::filesystem::exists(filename)) BOOST_THROW_EXCEPTION(file_not_found() << boost::errinfo_file_name(narrow(filename))); FREE_IMAGE_FORMAT fif = FIF_UNKNOWN; fif = FreeImage_GetFileTypeU(filename.c_str(), 0); if(fif == FIF_UNKNOWN) fif = FreeImage_GetFIFFromFilenameU(filename.c_str()); if(fif == FIF_UNKNOWN || !FreeImage_FIFSupportsReading(fif)) BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format.")); auto bitmap = std::shared_ptr<FIBITMAP>(FreeImage_LoadU(fif, filename.c_str(), 0), FreeImage_Unload); if(FreeImage_GetBPP(bitmap.get()) != 32) { bitmap = std::shared_ptr<FIBITMAP>(FreeImage_ConvertTo32Bits(bitmap.get()), FreeImage_Unload); if(!bitmap) BOOST_THROW_EXCEPTION(invalid_argument() << msg_info("Unsupported image format.")); } //PNG-images need to be premultiplied with their alpha if(fif == FIF_PNG) { image_view<bgra_pixel> original_view(FreeImage_GetBits(bitmap.get()), FreeImage_GetWidth(bitmap.get()), FreeImage_GetHeight(bitmap.get())); premultiply(original_view); } return bitmap; }
Exporter::Result Exporter::exportLight(NiNodeRef parent, INode *node, GenLight* light) { TimeValue t = 0; NiLightRef niLight; switch (light->Type()) { case OMNI_LIGHT: { if (light->GetAmbientOnly()) { niLight = new NiAmbientLight(); } else { NiPointLightRef pointLight = new NiPointLight(); float atten = light->GetAtten(t, ATTEN_START); switch (light->GetDecayType()) { case 0: pointLight->SetConstantAttenuation(1.0f); break; case 1: pointLight->SetLinearAttenuation( atten / 4.0f ); break; case 2: pointLight->SetQuadraticAttenuation( sqrt(atten / 4.0f) ); break; } niLight = StaticCast<NiLight>(pointLight); } } break; case TSPOT_LIGHT: case FSPOT_LIGHT: niLight = new NiSpotLight(); break; case DIR_LIGHT: case TDIR_LIGHT: niLight = new NiDirectionalLight(); break; } if (niLight == NULL) return Skip; niLight->SetName(narrow(node->GetName())); Matrix3 tm = getObjectTransform(node, t, !mFlattenHierarchy); niLight->SetLocalTransform( TOMATRIX4(tm, false) ); niLight->SetDimmer( light->GetIntensity(0) ); Color3 rgbcolor = TOCOLOR3( light->GetRGBColor(0) ); if (light->GetAmbientOnly()) { niLight->SetDiffuseColor(Color3(0,0,0)); niLight->SetSpecularColor(Color3(0,0,0)); niLight->SetAmbientColor(rgbcolor); } else { niLight->SetDiffuseColor(rgbcolor); niLight->SetSpecularColor(rgbcolor); niLight->SetAmbientColor(Color3(0,0,0)); } parent->AddChild( DynamicCast<NiAVObject>(niLight) ); return Ok; }
int64_t nsAString::ToInteger64(nsresult *aErrorCode, uint32_t aRadix) const { NS_ConvertUTF16toUTF8 narrow(*this); const char *fmt; switch (aRadix) { case 10: fmt = "%lli"; break; case 16: fmt = "%llx"; break; default: NS_ERROR("Unrecognized radix!"); *aErrorCode = NS_ERROR_INVALID_ARG; return 0; } int64_t result = 0; if (PR_sscanf(narrow.get(), fmt, &result) == 1) *aErrorCode = NS_OK; else *aErrorCode = NS_ERROR_FAILURE; return result; }
Midi Midi::ReadFromFile(const wstring &filename) { #if defined WIN32 fstream file(reinterpret_cast<const wchar_t*>((filename).c_str()), ios::in|ios::binary); #else // TODO: This isn't Unicode! // MACTODO: Test to see if opening a unicode filename works. I bet it doesn't. std::string narrow(filename.begin(), filename.end()); fstream file(narrow.c_str(), ios::in | ios::binary); #endif if (!file.good()) throw MidiError(MidiError_BadFilename); Midi m; try { m = ReadFromStream(file); } catch (const MidiError &e) { // Close our file resource before handing the error up file.close(); throw e; } return m; }
decklink_producer(const core::video_format_desc& format_desc, size_t device_index, const safe_ptr<core::frame_factory>& frame_factory, const std::wstring& filter) : decklink_(get_device(device_index)) , input_(decklink_) , attributes_(decklink_) , model_name_(get_model_name(decklink_)) , device_index_(device_index) , filter_(filter) , format_desc_(format_desc) , audio_cadence_(format_desc.audio_cadence) , muxer_(format_desc.fps, frame_factory, filter) , sync_buffer_(format_desc.audio_cadence.size()) , frame_factory_(frame_factory) { hints_ = 0; frame_buffer_.set_capacity(2); graph_->set_color("tick-time", diagnostics::color(0.0f, 0.6f, 0.9f)); graph_->set_color("late-frame", diagnostics::color(0.6f, 0.3f, 0.3f)); graph_->set_color("frame-time", diagnostics::color(1.0f, 0.0f, 0.0f)); graph_->set_color("dropped-frame", diagnostics::color(0.3f, 0.6f, 0.3f)); graph_->set_color("output-buffer", diagnostics::color(0.0f, 1.0f, 0.0f)); graph_->set_text(print()); diagnostics::register_graph(graph_); auto display_mode = get_display_mode(input_, format_desc_.format, bmdFormat8BitYUV, bmdVideoInputFlagDefault); // NOTE: bmdFormat8BitARGB is currently not supported by any decklink card. (2011-05-08) if(FAILED(input_->EnableVideoInput(display_mode, bmdFormat8BitYUV, bmdVideoInputFlagDefault))) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Could not enable video input.") << boost::errinfo_api_function("EnableVideoInput")); if(FAILED(input_->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType32bitInteger, format_desc_.audio_channels))) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Could not enable audio input.") << boost::errinfo_api_function("EnableAudioInput")); if (FAILED(input_->SetCallback(this)) != S_OK) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to set input callback.") << boost::errinfo_api_function("SetCallback")); if(FAILED(input_->StartStreams())) BOOST_THROW_EXCEPTION(caspar_exception() << msg_info(narrow(print()) + " Failed to start input stream.") << boost::errinfo_api_function("StartStreams")); }
static void recursiveBuild(BuildResult &result, NaiveBvhNode &dst, uint32 start, uint32 end, PrimVector &prims, const Box3f &geomBox, const Box3f ¢roidBox, uint32 branchFactor) { result = BuildResult{1, 1}; dst.bbox() = geomBox; uint32 numPrims = end - start + 1; if (numPrims == 1) { // Single primitive, just create a leaf node dst.setId(prims[start].id()); } else if (numPrims <= branchFactor) { // Few primitives, create internal node with numPrims children result.nodeCount += numPrims; for (uint32 i = start; i <= end; ++i) dst.setChild(i - start, new NaiveBvhNode(narrow(prims[i].box()), prims[i].id())); } else { // Many primitives: Setup SAH split uint32 starts[4], ends[4]; Box3f geomBoxes[4], centroidBoxes[4]; starts [0] = start; ends [0] = end; geomBoxes [0] = geomBox; centroidBoxes[0] = centroidBox; // Perform the split (potentially in parallel) uint32 childCount = sahSplit(starts, ends, geomBoxes, centroidBoxes, prims, branchFactor); // TODO: Use pool allocator? for (unsigned i = 0; i < childCount; ++i) dst.setChild(i, new NaiveBvhNode()); if (numPrims <= 32*1024) { // Perform single threaded recursive build for small workloads for (unsigned i = 0; i < childCount; ++i) { BuildResult recursiveResult; recursiveBuild(recursiveResult, *dst.child(i), starts[i], ends[i], prims, geomBoxes[i], centroidBoxes[i], branchFactor); result.nodeCount += recursiveResult.nodeCount; result.depth = max(result.depth, recursiveResult.depth + 1); } } else { // Enqueue parallel build for large workloads BuildResult results[4]; std::shared_ptr<TaskGroup> group = ThreadUtils::pool->enqueue([&](uint32 i, uint32, uint32) { recursiveBuild(results[i], *dst.child(i), starts[i], ends[i], prims, geomBoxes[i], centroidBoxes[i], branchFactor); }, childCount); // Do some work while we wait ThreadUtils::pool->yield(*group); // Serial reduce for (unsigned i = 0; i < childCount; ++i) { result.nodeCount += results[i].nodeCount; result.depth = max(result.depth, results[i].depth + 1); } } } }
inline std::string apifname(const boost::filesystem::wpath & path) { #if BOOST_WINDOWS return narrow(wfname(path)); #else return utf8fname(path); #endif }
void be_exception::GenerateConvenienceConstructor (be_ClientHeader& source) { ostream & os = source.Stream (); const char * argPrefix = "_"; pbbool first = pbtrue; be_Tab tab (source); os << tab << LocalName () << " ("; UTL_Scope * s = (UTL_Scope*)narrow ((long) & UTL_Scope::type_id); assert (s); // Iterate through decls UTL_ScopeActiveIterator *it; for ( it = new UTL_ScopeActiveIterator (s, UTL_Scope::IK_decls); !it->is_done (); it->next () ) { AST_Decl * adecl = it->item(); assert (adecl); be_field * bfield = be_field::_narrow (adecl); be_Type * btype; if (bfield) { btype = bfield->get_be_type (); if (!first) { os << ", "; } first = pbfalse; if (btype && btype->IsStringType ()) { // Strings are special case os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->InTypeName ()); } else { os << (char*) BE_Globals::RelativeScope (ScopedName (), bfield->StructMemberTypeName ()); } os << " " << argPrefix << (char*) bfield->get_local_name (); } } delete it; os << ");" << nl; }
void NodeSerializerA::append(const wchar_t* str) { //typedef std::codecvt_utf8<wchar_t> convert_typeX; //std::wstring_convert<convert_typeX, wchar_t> converterX; //out<<converterX.to_bytes(str); std::string s = narrow(str); out<<s; }
void ToStdString(BSTR bs, std::string& str) { BOOL bUsedDefaultChar; int len = (int) SysStringLen(bs); AutoArrayDeleter<char> narrow(new char[len+1]); WideCharToMultiByte(CP_ACP, 0, bs, len, narrow.p, len+1, "?", &bUsedDefaultChar); narrow.p[len] = 0; str = narrow.p; }
static const std::string do_narrow( const std::wstring &wide, const std::locale &loc) { if (wide.empty()) return std::string(); std::string narrow(4*wide.size(), '\0'); // max character length in UTF-8 size_t processed = do_fast_narrow(wide, narrow); if (processed == wide.size()) return narrow; typedef std::wstring::traits_type::state_type state_type; typedef std::codecvt<wchar_t, char, state_type> CVT; const CVT& cvt = std::use_facet<CVT>(loc); //std::string narrow(cvt.max_length()*wide.size(), '\0'); state_type state = state_type(); const wchar_t* from_beg = &wide[0]; const wchar_t* from_end = from_beg + wide.size(); const wchar_t* from_nxt; char* to_beg = &narrow[0]; char* to_end = to_beg + narrow.size(); char* to_nxt; std::string::size_type sz = 0; std::codecvt_base::result r; do { r = cvt.out(state, from_beg, from_end, from_nxt, to_beg, to_end, to_nxt); switch (r) { case std::codecvt_base::error: throw std::runtime_error("error converting wstring to string"); case std::codecvt_base::partial: sz += to_nxt - to_beg; narrow.resize(2*narrow.size()); to_beg = &narrow[sz]; to_end = &narrow[0] + narrow.size(); break; case std::codecvt_base::noconv: narrow.resize(sz + (from_end-from_beg)*sizeof(wchar_t)); std::memcpy(&narrow[sz], from_beg,(from_end-from_beg)*sizeof(wchar_t)); r = std::codecvt_base::ok; break; case std::codecvt_base::ok: sz += to_nxt - to_beg; narrow.resize(sz); break; } } while (r != std::codecvt_base::ok); return narrow; }
TextOrID(const wchar_t *title) { if (IS_INTRESOURCE(title)) { _is_title = false; _rsrc_id = (uint16_t) (uintptr_t) title; } else { _is_title = true; _title = narrow(title); } }
YBUTIL_DECL const std::string fast_narrow(const std::wstring &wide) { if (wide.empty()) return std::string(); std::string narrow(4 * wide.size(), '\0'); // max character length in UTF-8 size_t processed = do_fast_narrow(wide, narrow); if (processed == wide.size()) return narrow; throw std::runtime_error("non ascii detected, fast_narrow failed"); }