本文整理汇总了C++中ustring::string方法的典型用法代码示例。如果您正苦于以下问题:C++ ustring::string方法的具体用法?C++ ustring::string怎么用?C++ ustring::string使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ustring
的用法示例。
在下文中一共展示了ustring::string方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: addString
uint64_t StringTable::addString (ustring str, ustring var_name)
{
ASSERT (m_ptr && "StringTable has not been initialized");
// The strings are laid out in the table as a struct:
//
// struct TableRep {
// size_t len;
// size_t hash;
// char str[len+1];
// };
// Compute the size of the entry before adding it to the table
size_t size = sizeof(size_t) + sizeof(size_t) + str.size() + 1;
if (((m_offset + size) >= m_size)) {
reallocTable();
}
// It should be hard to trigger this assert, unless the table size is
// very small and the string is very large.
ASSERT (m_offset + size <= m_size && "String table allocation error");
int offset = getOffset(str.string());
if (offset < 0) {
// Place the hash and length of the string before the characters
size_t hash = str.hash();
cudaMemcpy (m_ptr + m_offset, (void*)&hash, sizeof(size_t), cudaMemcpyHostToDevice);
m_offset += sizeof(size_t);
size_t len = str.length();
cudaMemcpy (m_ptr + m_offset, (void*)&len, sizeof(size_t), cudaMemcpyHostToDevice);
m_offset += sizeof(size_t);
offset = m_offset;
m_offset_map [str] = offset;
m_name_map [str] = var_name;
// Copy the raw characters to the table
cudaMemcpy (m_ptr + m_offset, str.c_str(), str.size() + 1, cudaMemcpyHostToDevice);
m_offset += str.size() + 1;
// Align the offset for the next entry to 8-byte boundaries
m_offset = (m_offset + 0x7u) & ~0x7u;
}
uint64_t addr = reinterpret_cast<uint64_t>(m_ptr + offset);
// Optionally create an OptiX variable for the string. It's not necessary to
// create a variable for strings that do not appear by name in compiled code
// (in either the OSL library functions or in the renderer).
if (! var_name.empty()) {
m_optix_ctx [var_name.string()]->setUserData (8, &addr);
}
return addr;
}
示例2: ib
static void
time_read_imagebuf ()
{
ImageBuf ib (input_filename.string(), imagecache);
ib.read (0, 0, true, TypeDesc::TypeFloat);
imagecache->invalidate_all (true);
}
示例3: DASSERT
int
Dictionary::get_document_index (ustring dictionaryname)
{
DocMap::iterator dm = m_document_map.find(dictionaryname);
int dindex;
if (dm == m_document_map.end()) {
dindex = m_documents.size();
m_document_map[dictionaryname] = dindex;
pugi::xml_document *doc = new pugi::xml_document;
m_documents.push_back (doc);
pugi::xml_parse_result parse_result;
if (boost::ends_with (dictionaryname.string(), ".xml")) {
// xml file -- read it
parse_result = doc->load_file (dictionaryname.c_str());
} else {
// load xml directly from the string
parse_result = doc->load_buffer (dictionaryname.c_str(),
dictionaryname.length());
}
if (! parse_result) {
m_context->error ("XML parsed with errors: %s, at offset %d",
parse_result.description(),
parse_result.offset);
m_document_map[dictionaryname] = -1;
return -1;
}
} else {
dindex = dm->second;
}
DASSERT (dindex < (int)m_documents.size());
return dindex;
}
示例4:
// Heavy lifting of OSL regex operations.
OSL_SHADEOP int
osl_regex_impl2 (OSL::ShadingContext *ctx, ustring subject_,
int *results, int nresults, ustring pattern,
int fullmatch)
{
const std::string &subject (subject_.string());
boost::match_results<std::string::const_iterator> mresults;
const boost::regex ®ex (ctx->find_regex (pattern));
if (nresults > 0) {
std::string::const_iterator start = subject.begin();
int res = fullmatch ? boost::regex_match (subject, mresults, regex)
: boost::regex_search (subject, mresults, regex);
int *m = (int *)results;
for (int r = 0; r < nresults; ++r) {
if (r/2 < (int)mresults.size()) {
if ((r & 1) == 0)
m[r] = mresults[r/2].first - start;
else
m[r] = mresults[r/2].second - start;
} else {
m[r] = pattern.length();
}
}
return res;
} else {
return fullmatch ? boost::regex_match (subject, regex)
: boost::regex_search (subject, regex);
}
}
示例5: detect_known_colorspace
ustring ColorSpaceManager::detect_known_colorspace(ustring colorspace,
const char *file_format,
bool is_float)
{
if (colorspace == u_colorspace_auto) {
/* Auto detect sRGB or raw if none specified. */
if (is_float) {
bool srgb = (colorspace == "sRGB" || colorspace == "GammaCorrected" ||
(colorspace.empty() &&
(strcmp(file_format, "png") == 0 || strcmp(file_format, "tiff") == 0 ||
strcmp(file_format, "dpx") == 0 || strcmp(file_format, "jpeg2000") == 0)));
return srgb ? u_colorspace_srgb : u_colorspace_raw;
}
else {
return u_colorspace_srgb;
}
}
else if (colorspace == u_colorspace_srgb || colorspace == u_colorspace_raw) {
/* Builtin colorspaces. */
return colorspace;
}
else {
/* Use OpenColorIO. */
#ifdef WITH_OCIO
{
thread_scoped_lock cache_lock(cache_colorspaces_mutex);
/* Cached lookup. */
if (cached_colorspaces.find(colorspace) != cached_colorspaces.end()) {
return cached_colorspaces[colorspace];
}
}
/* Detect if it matches a simple builtin colorspace. */
bool is_scene_linear, is_srgb;
is_builtin_colorspace(colorspace, is_scene_linear, is_srgb);
thread_scoped_lock cache_lock(cache_colorspaces_mutex);
if (is_scene_linear) {
VLOG(1) << "Colorspace " << colorspace.string() << " is no-op";
cached_colorspaces[colorspace] = u_colorspace_raw;
return u_colorspace_raw;
}
else if (is_srgb) {
VLOG(1) << "Colorspace " << colorspace.string() << " is sRGB";
cached_colorspaces[colorspace] = u_colorspace_srgb;
return u_colorspace_srgb;
}
/* Verify if we can convert from the requested color space. */
if (!get_processor(colorspace)) {
OCIO::ConstConfigRcPtr config = OCIO::GetCurrentConfig();
if (!config || !config->getColorSpace(colorspace.c_str())) {
VLOG(1) << "Colorspace " << colorspace.c_str() << " not found, using raw instead";
}
else {
VLOG(1) << "Colorspace " << colorspace.c_str()
<< " can't be converted to scene_linear, using raw instead";
}
cached_colorspaces[colorspace] = u_colorspace_raw;
return u_colorspace_raw;
}
/* Convert to/from colorspace with OpenColorIO. */
VLOG(1) << "Colorspace " << colorspace.string() << " handled through OpenColorIO";
cached_colorspaces[colorspace] = colorspace;
return colorspace;
#else
VLOG(1) << "Colorspace " << colorspace.c_str() << " not available, built without OpenColorIO";
return u_colorspace_raw;
#endif
}
}
示例6: texture
bool OSLRenderServices::texture(ustring filename, TextureOpt &options,
OSL::ShaderGlobals *sg,
float s, float t, float dsdx, float dtdx,
float dsdy, float dtdy, float *result)
{
OSL::TextureSystem *ts = osl_ts;
ShaderData *sd = (ShaderData *)(sg->renderstate);
KernelGlobals *kg = sd->osl_globals;
#ifdef WITH_PTEX
/* todo: this is just a quick hack, only works with particular files and options */
if(string_endswith(filename.string(), ".ptx")) {
float2 uv;
int faceid;
if(!primitive_ptex(kg, sd, &uv, &faceid))
return false;
float u = uv.x;
float v = uv.y;
float dudx = 0.0f;
float dvdx = 0.0f;
float dudy = 0.0f;
float dvdy = 0.0f;
Ptex::String error;
PtexPtr<PtexTexture> r(ptex_cache->get(filename.c_str(), error));
if(!r) {
//std::cerr << error.c_str() << std::endl;
return false;
}
bool mipmaplerp = false;
float sharpness = 1.0f;
PtexFilter::Options opts(PtexFilter::f_bicubic, mipmaplerp, sharpness);
PtexPtr<PtexFilter> f(PtexFilter::getFilter(r, opts));
f->eval(result, options.firstchannel, options.nchannels, faceid, u, v, dudx, dvdx, dudy, dvdy);
for(int c = r->numChannels(); c < options.nchannels; c++)
result[c] = result[0];
return true;
}
#endif
OSLThreadData *tdata = kg->osl_tdata;
OIIO::TextureSystem::Perthread *thread_info = tdata->oiio_thread_info;
OIIO::TextureSystem::TextureHandle *th = ts->get_texture_handle(filename, thread_info);
bool status = ts->texture(th, thread_info,
options, s, t, dsdx, dtdx, dsdy, dtdy, result);
if(!status) {
if(options.nchannels == 3 || options.nchannels == 4) {
result[0] = 1.0f;
result[1] = 0.0f;
result[2] = 1.0f;
if(options.nchannels == 4)
result[3] = 1.0f;
}
}
return status;
}